;
; swnew ___---___---___---___ sample active lo switches
; swold ____---___---___---__ switch state latch
; swnew ___-__-__-__-__-__-__ changes, press or release
; swnew ___-_____-_____-_____ filter out 'release' bits
;
mainLoop
DelayCy(20*msecs) ; 20-msec debounce interval
comf GPIO,W ; sample active lo switches
andlw b'00000010' ; on the GP1 pin
xorwf swold,W ; changes, press or release
xorwf swold,F ; update switch state latch
andwf swold,W ; filter out 'release' bits
skpnz ; new press? yes, skip, else
goto mainLoop ; loop (wait for press)
;
; on "new press", send 104 bits at a 50-KHz (20-usec) rate
;
task
clrf bitctr ;
tx8bits(b'00000000') ; movlw xx & call send8bits
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
tx8bits(b'00000001') ;
tx8bits(b'00000000') ;
goto mainLoop ;
send8bits
movwf work ; save byte value
bsf bitctr,3 ; bitctr = 8
sendloop
movlw b'00000001' ; assume a '1'
btfss work,0 ; is it '1'? yes, skip,else
movlw b'00000000' ; reset to '0'
movwf GPIO ; send bit out on GP0 pin
DelayCy(20*usecs-14) ; 20-usecs minus 13 cycles
rrf work,F ; shift 'work' variable
decf bitctr,F ; decrement bit counter
skpnz ; done? no, skip, else
return ; exit
goto $+1 ; burn off 2 cycles
goto $+1 ; burn off 2 cycles
goto sendloop ; loop (send another bit)
;