;
; poll the Rotary Encoder A and B switches
;
ISR_Encoder
movf PORTB,W ; get switch data |B0
andlw b'00000011' ; mask encoder B and A switches |B0
xorwf ENCOLD,W ; same as last reading? |B0
bz ISR_Next ; yes, branch (no change), else |B0
xorwf ENCOLD,W ; restore encoder bits in W |B0
rrf ENCOLD,f ; prep for B-old ^ A-new |B0
xorwf ENCOLD,f ; ENCOLD bit 0 = direction |B0
rrf ENCOLD,f ; now Carry bit = direction |B0
movwf ENCOLD ; update ENCOLD (new BA bits) |B0
;
; encoder position has changed but we only act on a change
; that occurs when the encoder falls into one of the detent
; positions (we ignore the changes between detents)
;
xorlw b'00000011' ; detent position (BA = 11)? |B0
bnz ISR_Next ; no, branch, else |B0
;
; increment or decrement position variable based on direction
; in the Carry bit