Code:
clrf PORTB ; start with zero
loop:
btfsc PORTB, 4 ; switch closed, (gives 0)?
goto loop ; not yet
; switch has been detected closed
incf PORTB, f ; add 1 to port B
; wait a while to make sure switch has
; settled (debounce closure)
movlw D'10' ; wait about 10 msec
call nmsec
; now wait for release
btfss PORTB, 4 ; will be high (1) when released
goto $ -1 ; still low
; now must wait a make sure bouncing stopped
movlw D'10' ; 10 milliseconds
call nmsec
; and check again
btfss PORTB, 4 ; if set, still released
goto $ -5 ; still low start release wait all over
goto loop ; loop forever
Instead of using the goto $-2 and goto $-5 , i used labels instead, so just want to know if the -2 is to step back in number of cycles? like -2 means go back 2 lines?? anyway i tried it in another approach, just wanna know if they are doing the same thing still.thanks
Code:
clrf PORTB ; start with zero
loop:
btfsc PORTB, 4 ; switch closed, (gives 0)?
goto loop ; not yet
; switch has been detected closed
incf PORTB, f ; add 1 to port B
; wait a while to make sure switch has
; settled (debounce closure)
movlw D'10' ; wait about 10 msec
call nmsec
; now wait for release
chk btfss PORTB, 4 ; will be high (1) when released
goto chk ; still low
; now must wait a make sure bouncing stopped
movlw D'10' ; 10 milliseconds
call nmsec
; and check again
btfss PORTB, 4 ; if set, still released
goto chk ; still low start release wait all over
goto loop ; loop forever
if my code is wrong, what shd i do to make the 2 codes the same.Thanks..