debounce
movlw 32 ; debounce/beep delay
movwf mstmr ; msctr = 32 msecs
movlw b'00010000' ; mask for GP4 spkr pin
btfsc beep,0 ; beep? no, skip, else
xorwf GPIO,F ; toggle spkr pin
inDlyCy(1000*usecs-6) ; 1-msec minus 6 cycles
decfsz mstmr,F ; done? yes, skip, else
goto debounce+2 ; loop
movf beep,W ; beep task running?
bz newsample ; no, branch, else
decfsz beep,F ; beep task done?
goto debounce ; no, branch (loop), else
newsample
comf GPIO,W ; sample active lo switches
movwf swnew ; save sample
newpress
btfsc swnew,3 ; swnew.3 == 1 and
btfsc swold,3 ; swold.3 == 0 (new press)?
goto newrelease ; no, branch, else
bsf swold,3 ; update swold.3 state latch
bsf beep,0 ; task a single beep and
movlw 1000/32 ; start 1 second timer
movwf swtmr ;
newrelease
btfss swnew,3 ; swnew.3 == 0 and
btfss swold,3 ; swold.3 == 1 (new release)?
goto timeout ; no, branch, else
bcf swold,3 ; update swold.3 state latch
movf swtmr,W ; timed out "long" press?
bz long ; yes, branch, else
short
clrf swtmr ; turn off switch timer
movlw b'00000001' ; use GP0 pin mask to
xorwf GPIO,F ; toggle GP0 'motor' on/off output
goto debounce ;
long
movlw b'00000110' ; use GP2 & GP1 pin mask to
xorwf GPIO,F ; toggle 'direction' output and LED
goto debounce ;
timeout
movf swtmr,F ; switch timer running?
bz debounce ; no, branch, else
decfsz swtmr,F ; is it timed out?
goto debounce ; no, branch, else
movlw 3 ;
movwf beep ; task a double beep
goto debounce ;
;