hi! i'm trying build a counter using a pic 16f877, the counter shoul only start when a switch connected to PORTA is pressed! and the counter must stop when the switch is released. so far i can make the pic count but the swicth is not working. can anybody tell me what wrong with my code? thanx.
;*****Configuration****************************************
LIST p=16F877
#include <P16F877.inc>
__config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF
;*****Equates**********************************************
status equ 03h
PortA equ 05h
PortD equ 08h
TRISA equ 85h
TRISD equ 88h
count0 equ 25h
count1 equ 26h
count2 equ 27h
;******Main Program****************************************
org 10h
bsf status,RP0
movlw B'11111111' ; set portA as input
movwf TRISA
movlw B'00000000' ; set PortD as outpout
movwf TRISD
bcf status,RP0
start
btfss PortA,0 ; test if portA bit 0 is set
goto start ; if bot 0 cleared goto start
incf PortD ; if bit 0 se inc portD
call delay
goto start ;do same thing
delay
movlw 05h ;SET DELAY FOR 1 SEC
Movwf count2
Loop
decfsz count0,1
Goto Loop
Decfsz count1,1
Goto Loop
Decfsz count2,1
Goto Loop
Return
end
;*****Configuration****************************************
LIST p=16F877
#include <P16F877.inc>
__config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF
;*****Equates**********************************************
status equ 03h
PortA equ 05h
PortD equ 08h
TRISA equ 85h
TRISD equ 88h
count0 equ 25h
count1 equ 26h
count2 equ 27h
;******Main Program****************************************
org 10h
bsf status,RP0
movlw B'11111111' ; set portA as input
movwf TRISA
movlw B'00000000' ; set PortD as outpout
movwf TRISD
bcf status,RP0
start
btfss PortA,0 ; test if portA bit 0 is set
goto start ; if bot 0 cleared goto start
incf PortD ; if bit 0 se inc portD
call delay
goto start ;do same thing
delay
movlw 05h ;SET DELAY FOR 1 SEC
Movwf count2
Loop
decfsz count0,1
Goto Loop
Decfsz count1,1
Goto Loop
Decfsz count2,1
Goto Loop
Return
end