; Check for an input change of state
movf gpio,w ; read inputs
xorwf LastEnc,w ; compare to previously saved encoder status
andlw 030h ; mask off all except bits 4 and 5
btfsc status,z ; zero flag is clear if encoder status has changed
goto EncEnd ; Skip around next section if no status change
;
; Encoder inputs have changed, so determine direction and update Counter
bcf STATUS,RP0 ; Sel Bank 0
rrf LastEnc,w ; get previous bit 5 value as bit 4
xorwf gpio,w ; and xor it with current bit 4
andlw 010h ; clear all but bit 4
btfss status,z ; increment (+1)
movlw 0feh ; decrement (-1)
addlw 1
addwf counter,f ; add to counter
movf gpio,w ; get current encoder status again
movwf LastEnc ; and save value for next time
EncEnd
; End of Encoder service section