out1 equ 0
in1 equ 1
in2 equ 2
in3 equ 3
state equ 0x10
setup:
bsf STATUS, RP0 ; Bank 1
call 3FFh ; Get the cal value
movwf OSCCAL ; Calibrate
movlw 0xFE ; GP0 is the output; all others are input
movwf TRISIO
bcf STATUS, RP0 ; Bank 0
movlw 0xFF
movwf state
loop1:
movfw GPIO
andlw (1<<in1)|(1<<in2)
xorlw (1<<in1)|(1<<in2)
btfsc STATUS,Z
goto doSinglePulse
bcf state,0
loop2:
movfw GPIO
andlw (1<<in1)|(1<<in3)
xorlw (1<<in1)|(1<<in3)
btfsc STATUS,Z
goto doDoublePulse
bcf state,1
goto loop1
doSinglePulse:
btfsc state,0
goto loop1
bsf state,0
bsf GPIO,out1
delayms 2000
bcf GPIO,out1
goto loop1
doDoublePulse:
btfsc state,1
goto loop2
bsf state,1
bsf GPIO,out1
delayms 1000
bcf GPIO,out1
delayms 500
bsf GPIO,out1
delayms 1000
bcf GPIO,out1
goto loop2