;
; single switch example
;
; a switch is debounced for both "press" and "release" states by
; sampling it at the same state 24 times within a 23 msec period
;
suspend
movf GPIO,W ; clear any IOC mismatch condition
bcf INTCON,RBIF ; clear IOC interrupt flag bit
sleep ; sleep, wait for IOC interrupt
nop ;
dbounce
movlw d'24' ;
movwf dbctr ; set debounce counter to 24 msecs
dbdelay
DelayCy(1*msecs) ; sample at 1 msec intervals
comf GPIO,W ; get fresh active low switch data
andlw 1<<SW0 ; mask off unused bits
xorwf slatch,W ; changes (press or release)
bz dbounce ; branch if inactive or bouncing, else
decfsz dbctr,F ; debounced? yes, skip, else
goto dbdelay ; test it again
xorwf slatch,F ; update switch state latch
andwf slatch,W ; is it a "new press"?
bz suspend ; no, branch (a "new release"), else
;
; a "new press", your "on switch press" code goes here
;
nop ;
nop ;
;
; then debounce the release part of the switch cycle and sleep
;
goto dbounce ;