This is on a 1 millisecond interrupt. Chip is 18F8722

Here is a portion of the code...


Asm
IntHandler

movwf wsave
swapf STATUS,W
clrf STATUS
movwf ssave
movf PCLATH,W
movwf psave
movf FSR0,W
movwf fsave

movlw 0xEC ; Reload TMR0 with 65535 - 5000
movwf TMR0H
movlw 0x77
movwf TMR0L

btfsc PIR1,5
goto KeyHit

bcf INTCON,2 ; Clear the interrupt flag

infsnz _MasterClock
incf _MasterClock + 1

movlw 0x03
cpfseq _MasterClock + 1
goto FanRoutine
movlw 0xE8
cpfseq _MasterClock
goto FanRoutine
clrf _MasterClock
clrf _MasterClock + 1


bsf _TPE
goto DoneForNow


FanRoutine

movf PORTB,0,0
movwf _Temp,0
xorwf _OldPortB,0,0
movwf _changedB,0
movff _Temp,_OldPortB


Fan1
btfss _changedB,0
goto DoneForNow
infsnz _Fan1Counter
incf _Fan1Counter+1



KeyHit
bsf _KeyHitFlag
bcf PIR1,5

DoneForNow

movf psave,W
movwf PCLATH
movf fsave,W
movwf FSR0
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
bsf INTCON,7 ; Turn Global interrupts on
bsf INTCON,6 ; Turn Peripheral Interrupts on
retfie ; Return from the interrupt

EndAsm