I really need help on an collage assignment that I have to do, but there are a few things that are not working right, but I do not know what is wrong with it. Can somebody just look over my code and give any advice. Thanx in advance
sorry that there is no comments
sorry that there is no comments
Rich (BB code):
List p=PIC16F88
#INCLUDE <P16F88.INC>
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;------------------------------------------------------------------------------------------------------------------------------------------------------------
current_state equ 0x20
cap_current_state equ 0x25
charge_time equ 0x26
WORK_REG_PORTA equ 0x22
WORK_REG_PORTB equ 0x23
;------------------------------------------------------------------------------------------------------------------------------------------------------------
digit1_state equ 0
digit2_state equ 1
digit3_state equ 2
digit4_state equ 3
cap_wait_state equ 0
cap_reset_state equ 1
cap_test_state equ 2
cap_tested_state equ 3
;------------------------------------------------------------------------------------------------------------------------------------------------------------
W_TEMP equ 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP equ 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP equ 0x7F ; variable used for context saving
;------------------------------------------------------------------------------------------------------------------------------------------------------------
number_thousands equ 0x27
number_hundreds equ 0x28
number_tens equ 0x29
number_units equ 0x30
;------------------------------------------------------------------------------------------------------------------------------------------------------------
START
ORG 0x0000
goto initialize
;------------------------------------------------------------------------------------------------------------------------------------------------------------
ORG 0x0004
ISR:
;******************************
movwf W_TEMP ; save off current W register contents
movf STATUS,W ; move status register into W register
movwf STATUS_TEMP ; save off contents of STATUS register
movf PCLATH,W ; move pclath register into W register
movwf PCLATH_TEMP ; save off contents of PCLATH register
;******************************
bcf INTCON, TMR0IF
call STATE_CAP_TEST
call NUM2DIGIT
call STATE_DIGITS
;******************************
movf PCLATH_TEMP,W ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf STATUS_TEMP,W ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf W_TEMP,F ; restore pre-isr W register contents
swapf W_TEMP,W
;******************************
retfie
;------------------------------------------------------------------------------------------------------------------------------------------------------------
initialize:
banksel TRISB
movlw b'00000000'
movwf TRISB
movlw b'01000000'
movwf TRISA
movlw b'00000000'
movwf OSCCON
movlw b'00000111'
movwf OPTION_REG
banksel PORTA
clrf PORTA
clrf PORTB
clrf current_state
clrf cap_current_state
banksel INTCON
bcf INTCON,TMR0IF
bsf INTCON,TMR0IE
bsf INTCON,GIE
init_loop:
goto init_loop
;***********************************************************************************************************************
STATE_DIGITS:
clrz
movf digit1_state,w
xorwf current_state, w
btfsc STATUS, Z
goto digit1
clrz
movf digit2_state,w
xorwf current_state, w
btfsc STATUS, Z
goto digit2
clrz
movf digit3_state,w
xorwf current_state, w
btfsc STATUS, Z
goto digit3
goto digit4
;=========================================
digit1:
banksel PORTB
bcf PORTB, RB5
movlw high LED_DISP_LUT
movwf PCLATH
call NUM2DIGIT
movf number_thousands,w
call LED_DISP_LUT
call LED_OUTPUT
movf digit2_state,w
movwf current_state
bsf PORTB, RB2
goto state_end
digit2:
banksel PORTB
bcf PORTB, RB2
movlw high LED_DISP_LUT
movwf PCLATH
call NUM2DIGIT
movf number_hundreds,w
call LED_DISP_LUT
call LED_OUTPUT
movf digit3_state,w
movwf current_state
bsf PORTB, RB3
goto state_end
digit3:
banksel PORTB
bcf PORTB, RB3
movlw high LED_DISP_LUT
movwf PCLATH
call NUM2DIGIT
movf number_tens,w
call LED_DISP_LUT
call LED_OUTPUT
movf digit4_state,w
movwf current_state
bsf PORTB, RB4
goto state_end
digit4
banksel PORTB
bcf PORTB, RB4
movlw high LED_DISP_LUT
movwf PCLATH
call NUM2DIGIT
movf number_units,w
call LED_DISP_LUT
call LED_OUTPUT
movf digit1_state,w
movwf current_state
bsf PORTB, RB5
goto state_end
state_end:
return
;***********************************************************************************************************************
STATE_CAP_TEST:
clrz
movf cap_wait_state,w
xorwf cap_current_state, w
btfsc STATUS, Z
goto wait_cap_read
clrz
movf cap_reset_state,w
xorwf cap_current_state, w
btfsc STATUS, Z
goto cap_reset
clrz
movf cap_test_state,w
xorwf cap_current_state, w
btfsc STATUS, Z
goto cap_test
goto cap_tested
;=========================================
wait_cap_read:
banksel PORTA
bsf PORTA,RA7
nop
bcf PORTA,RA7
btfss PORTA, RA6
goto capstate_end
movf cap_reset_state,w
movwf cap_current_state
goto capstate_end
cap_reset:
banksel PORTA
bsf PORTA,RA7
movf cap_test_state,w
movwf cap_current_state
goto capstate_end
cap_test:
banksel T1CON
btfsc PORTA, RA6
goto capstate_end
bcf PORTA,RA7
bsf T1CON, TMR1ON
movf cap_tested_state,w
movwf cap_current_state
goto capstate_end
cap_tested:
banksel T1CON
btfss PORTA, RA6
goto capstate_end
bcf T1CON, TMR1ON
movf cap_wait_state,w
movwf cap_current_state
;clrf TMR1L
;clrf TMR1H
goto capstate_end
capstate_end
return
;***********************************************************************************************************************
; Bit Number 6 10 43210
; PORTB,6 => 0 00 00000 <=PORTA
; ^^^ < = PORTB
LED_OUTPUT
movwf WORK_REG_PORTA
movwf WORK_REG_PORTB
banksel PORTA
;=============================
; Bit Number 6 10 43210
; PORTB,6 => 0 00 00000 <=PORTA
; ^ < = PORTB
btfsc WORK_REG_PORTB, 7
bsf PORTB, RB6
movlw b'01100000'
andwf WORK_REG_PORTB,f
rrf WORK_REG_PORTB,f
rrf WORK_REG_PORTB,f
rrf WORK_REG_PORTB,f
rrf WORK_REG_PORTB,f
rrf WORK_REG_PORTB,f
movf WORK_REG_PORTB,w
movlw PORTB
;=============================
; Bit Number 6 10 43210
; PORTB,6 => 0 00 00000 <=PORTA
; ^ < = PORTB
movlw b'00011111'
andwf WORK_REG_PORTA,f
movf WORK_REG_PORTA,w
movlw PORTA
return
;***********************************************************************************************************************
NUM2DIGIT:
thousands_loop
clrc
banksel TMR1L
movlw 1000
subwf TMR1L,f
btfss STATUS,C
goto thousands_loop
addwf TMR1L
movlw .1
addwf number_thousands
hundreds_loop:
clrc
movlw .100
subwf TMR1L,f
btfss STATUS,C
goto hundreds_loop
addwf TMR1L
movlw .1
addwf number_hundreds
tens_loop:
clrc
movlw .10
subwf TMR1L,f
btfss STATUS,C
goto tens_loop
addwf TMR1L
movlw .1
addwf number_hundreds
units_loop:
clrc
movf TMR1L,w
movlw number_units
return
;***********************************************************************************************************************
LED_DISP_LUT:
; Bit Number 6 10 43210
; PORTB,6 => 0 00 00000 <=PORTA
; ^ < = PORTB
addwf PCL, f
retlw b'00111111' ;0
retlw b'00000110' ;1
retlw b'01011011' ;2
retlw b'01001111' ;3
retlw b'01100110' ;4
retlw b'01101101' ;5
retlw b'01111101' ;6
retlw b'00000111' ;7
retlw b'01111111' ;8
retlw b'01101111' ;9
retlw b'10000000' ; .
end_loop:
goto end_loop
end