;
; <> process up to eight switches in parallel
; <> eight independent 2-bit 30.0-msec "debounce" vertical counters
; <> momentary switch operation (test then clear a SWITCH bit
; in Main)
; <> toggle switch emulation (push to toggle a SWITCH bit from
; off-to-on or from on-to-off) perfect for lighted switches
;
; a switch is "debounced" or "filtered" after it's sampled four
; times at the same level spanning a 30-msec period.
;
; execute this code every 10.0-msec interrupt cycle
;
; 13 instructions/13 words
;
ISR_Debounce
;
; get new press, release, or bounce state "change" bits in W
;
comf PORTB,W ; read active low switches |B0
movwf SWKEYS ; save live switch press data |B0
xorwf SLATCH,W ; get delta 'live' and 'latch' |B0
;
; reset vertical counters for bouncing or inactive switches
;
andwf VCBIT0,f ; |B0
andwf VCBIT1,f ; |B0
;
; get timed-out counter bits in W
;
andwf VCBIT0,W ; |B0
andwf VCBIT1,W ; |B0
;
; update debounced switch state latch (each '1' represents
; a 30.0-msec debounced switch press)
;
xorwf SLATCH,f ; update debounced state latch |B0
;
andwf SWKEYS,W ; get "new" switch press bits |B0
;
; toggle SWITCH pressed flags for processing by MAIN program
;
; MAIN should test SWITCH flags for emulated "toggle" switches
; or test then clear SWITCH flags for "momentary" switches
;
xorwf SWITCH,f ; toggle SWITCH flags for MAIN |B0
;
; increment the 2-bit vertical counters (unconditionally)
;
movf VCBIT0,W ; |B0
xorwf VCBIT1,f ; b1 ^= b0 |B0
comf VCBIT0,f ; b0 = ~b0 |B0
;