;note W_TEMP and STATUS_TEMP need to be in the common area (above 0x70)
ISR MOVWF W_TEMP ; SAVE OFF CURRENT W REGISTER CONTENTS
MOVF STATUS,W ; MOVE STATUS REGISTER INTO W REGISTER
MOVWF STATUS_TEMP ; SAVE OFF CONTENTS OF STATUS REGISTER
BCF STATUS,RP0
BCF PIR1,TMR2IF
RLF previous,F
RLF previous,W
ANDLW 0X0C ;KEEP ONLY BITS 2 & 3
BTFSS PORTA,0 ;MOVE ENCODER BITS
IORLW 1 ;TO BITS 0 & 1
BTFSS PORTA,1
IORLW 2
MOVWF previous ;KEEP FOR NEXT TIME
CALL ENC_TABLE
ADDWF clicks,F
MOVLW 4
XORWF clicks,W
BTFSS STATUS,Z
GOTO CHECK_DOWN
CLRF clicks ;added this line
MOVLW high 10800 ;test if frequency has reached 108MHz
XORWF freqHigh,W
BTFSS STATUS,Z
GOTO DOINC ;high bytes don't match so do increment
MOVLW low 10800
XORWF freqLow,W
BTFSC STATUS,Z ;low bytes don't match so do increment
GOTO EXIT ;if it has, exit
DOINC INCF freqHigh,F ;if not then increment it
INCFSZ freqLow,F
DECF freqHigh,F
GOTO EXIT
CHECK_DOWN
MOVLW 0XFC ;-4
XORWF clicks,W
BTFSC STATUS,Z
GOTO EXIT
CLRF clicks ;added this line
MOVLW high 8700
XORWF freqHigh,W
BTFSS STATUS,Z
GOTO DODEC
MOVLW low 8700
XORWF freqLow,W
BTFSC STATUS,Z
GOTO EXIT
DODEC MOVF freqLow,F
SKPNZ
DECF freqHigh,F
DECF freqLow,F
GOTO EXIT
; RESTORE CONTEXT BEFORE RETURNING FROM INTERRUPT
EXIT MOVF STATUS_TEMP,W ; RETRIEVE COPY OF STATUS REGISTER
MOVWF STATUS ; RESTORE PRE-ISR STATUS REGISTER CONTENTS
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; RESTORE PRE-ISR W REGISTER CONTENTS
RETFIE ; RETURN FROM INTERRUPT