counter is not functioning
Posted: Mon Jun 02, 2008 2:08 pm
hi friends , I am using the HP-488-00-3 board, in my following program, i want to have delayed outputs at port B when my portA,1 is set and some outputs when the portA,1 is high, all other functions are fine, but my counter is not decrementing and give the output, i have attached my code, can any one point my mistake please
list p=16F84
radix hex
;It is a 16f84 xt oscillator, watchdog timer off, power-up timer on.
;include <p16f84.inc>
;__config _XT_OSC & _WDT_OFF & _PWRTE_ON
;----------------------------------------------------------------------
; cpu equates (memory map)
Status equ 0x03
portA equ 0x05 ; define the potA address
portB equ 0x06 ; (p. 10 defines port address)
Output_Status equ 0x08 ;
count1 equ 0xA0
count2 equ 0xA1
counter_status equ 0xA2
count3 equ 0xA3
count4 equ 0xA4
count5 equ 0xA5
count6 equ 0xA6
;----------------------------------------------------------------------
org 0x000
Initialise movlw 0X00
tris portB
movlw 0xFF
tris portA
;-----initialise PortB and Output_Status-------------
movlw 0x00
movwf portB
movwf counter_status
;-----------------------------------------------------
Start
;=========================================================================
;----------test bit-A0 if pressed invert B0--------------------
Test_Bit0
BTFSC portA,1
goto set_counter
BTFSS portA,0
goto clear_all
clear_all
BTFSC portA,1
goto set_counter
bcf portB,0
bcf portB,1
bcf portB,4
goto wait_0
set_counter
bsf portB,1
bcf portB,0
bcf portB,4
BTFSC counter_status,0
goto wait_0
movlw 0x01 ;--- to enable counter
movwf counter_status
movlw 0xFF
movwf count3
movlw 0x0A
movwf count4
movlw 0x00
movwf count5
movlw 0x00
movwf count6
goto wait_0
wait_0
;BTFSS portA,0
;goto Test_Bit1
;BTFSS portA,1
;goto Test_Bit1
;goto wait_0
Test_Bit1
BTFSS portA,0
goto clear_all
BTFSS portA,3
goto set_2
bsf portB,0
bsf portB,4
bsf portB,3
bcf portB,1
goto wait_1
set_2 bsf portB,0
bsf portB,4
bcf portB,3
bcf portB,1
goto wait_1
wait_1
;-------------5m Sec Delay------------------------
movlw 0xFF
movwf count1
movlw 0x0A ;here also can change the value for delay
movwf count2
Small_Delay
decfsz count1
goto Small_Delay
decfsz count2
goto Small_Delay
;----------------End of Delay----------------------
;-------------5m Sec Delay------------------------
BTFSS counter_status,0
goto Start
decfsz count3
goto Start
bsf portB,3
decfsz count4
goto Start
bsf portB,5
decfsz count5
goto Start
bsf portB,6
decfsz count6
goto Start
goto Start
end
list p=16F84
radix hex
;It is a 16f84 xt oscillator, watchdog timer off, power-up timer on.
;include <p16f84.inc>
;__config _XT_OSC & _WDT_OFF & _PWRTE_ON
;----------------------------------------------------------------------
; cpu equates (memory map)
Status equ 0x03
portA equ 0x05 ; define the potA address
portB equ 0x06 ; (p. 10 defines port address)
Output_Status equ 0x08 ;
count1 equ 0xA0
count2 equ 0xA1
counter_status equ 0xA2
count3 equ 0xA3
count4 equ 0xA4
count5 equ 0xA5
count6 equ 0xA6
;----------------------------------------------------------------------
org 0x000
Initialise movlw 0X00
tris portB
movlw 0xFF
tris portA
;-----initialise PortB and Output_Status-------------
movlw 0x00
movwf portB
movwf counter_status
;-----------------------------------------------------
Start
;=========================================================================
;----------test bit-A0 if pressed invert B0--------------------
Test_Bit0
BTFSC portA,1
goto set_counter
BTFSS portA,0
goto clear_all
clear_all
BTFSC portA,1
goto set_counter
bcf portB,0
bcf portB,1
bcf portB,4
goto wait_0
set_counter
bsf portB,1
bcf portB,0
bcf portB,4
BTFSC counter_status,0
goto wait_0
movlw 0x01 ;--- to enable counter
movwf counter_status
movlw 0xFF
movwf count3
movlw 0x0A
movwf count4
movlw 0x00
movwf count5
movlw 0x00
movwf count6
goto wait_0
wait_0
;BTFSS portA,0
;goto Test_Bit1
;BTFSS portA,1
;goto Test_Bit1
;goto wait_0
Test_Bit1
BTFSS portA,0
goto clear_all
BTFSS portA,3
goto set_2
bsf portB,0
bsf portB,4
bsf portB,3
bcf portB,1
goto wait_1
set_2 bsf portB,0
bsf portB,4
bcf portB,3
bcf portB,1
goto wait_1
wait_1
;-------------5m Sec Delay------------------------
movlw 0xFF
movwf count1
movlw 0x0A ;here also can change the value for delay
movwf count2
Small_Delay
decfsz count1
goto Small_Delay
decfsz count2
goto Small_Delay
;----------------End of Delay----------------------
;-------------5m Sec Delay------------------------
BTFSS counter_status,0
goto Start
decfsz count3
goto Start
bsf portB,3
decfsz count4
goto Start
bsf portB,5
decfsz count5
goto Start
bsf portB,6
decfsz count6
goto Start
goto Start
end