Again movfw GateState ;get state
movwf OldState ;keep copy
clrf GateState
btfsc PORTB,A ;A covered?
bsf GateState,0 ;yes, set bit
btfsc PORTB,B ;B covered?
bsf GateState,1
movfw GateState ;get new state
xorwf OldState,[COLOR="Red"]W[/COLOR] ;cmp old state [COLOR="red"]edited[/COLOR]
btfsc STATUS,Z ;same
goto Again ;yes, do nothing
; state has changed.
movfw OldState ;check the states and
xorlw b'10' ;inc/dec as appropriate
btfss STATUS,Z
goto NoIncrement
movfw GateState
xorlw b'11'
btfss STATUS,Z
goto NoIncrement
incf Count,F
goto Again
NoIncrement
movfw OldState
xorlw b'11'
btfss STATUS,Z
goto NoDecrement
movfw GateState
xorlw b'10'
btfss STATUS,Z
goto NoDecrement
decf Count,F
goto Again
NoDecrement
goto Again