;***** INTERRUPT SERVICE ROUTINE *****
ISR ;************************
;*** ISR CONTEXT SAVE ***
;************************
bcf INTCON,GIE ; disable all interrupts
btfsc INTCON,GIE ; assure interrupts are disabled
goto ISR
movwf W_TEMP ; context save: W
swapf STATUS,W ; context save: STATUS
movwf STATUS_TEMP ; context save
clrf STATUS ; bank 0, regardless of current bank
movfw PCLATH ; context save: PCLATH
movwf PCLATH_TEMP ; context save
clrf PCLATH ; page zero, regardless of current page
bcf STATUS,IRP ; return to bank 0
movfw FSR ; context save: FSR
movwf FSR_TEMP ; context save
;*** context save done ***
;**************************
;*** ISR MAIN EXECUTION ***
;**************************
;*** check origin of interrupt ***
btfsc INTCON,INTF ; check for RB0/INT interrupt
goto _ISR_RS232 ; if set, there was a keypad stroke
; catch-all
goto ISRend ; unexpected IRQ, terminate execution of ISR
;******************************
;*** RS232 DATA ACQUISITION ***
;******************************
_ISR_RS232
; first, disable interrupt source
bcf INTCON,INTE ; disable RB0/INT interrupt
; second, acquire RS232 data
RECEIVE ; macro of RS232 software reception
bsf RSflag ; enable RS232 data reception flag
goto _ISR_RS232end ; terminate RS232 ISR properly
;***********************************
;*** CLEARING OF INTERRUPT FLAGS ***
;***********************************
; NOTE: Below, I only clear the interrupt flags! This does not
; necessarily mean, that the interrupts are already re-enabled.
; Basically, interrupt re-enabling is carried out at the end of
; the corresponding service routine in normal operation mode.
; The flag responsible for the current ISR call has to be cleared
; to prevent recursive ISR calls. Other interrupt flags, activated
; during execution of this ISR, will immediately be served upon
; termination of the current ISR run.
_ISR_RS232error
bsf INTCON,INTE ; after error, re-enable IRQ already here
_ISR_RS232end
bcf INTCON,INTF ; clear RB0/INT interrupt flag
;goto ISRend ; terminate execution of ISR
;*****************************************
;*** ISR TERMINATION (CONTEXT RESTORE) ***
;*****************************************
ISRend movfw FSR_TEMP ; context restore
movwf FSR ; context restore
movfw PCLATH_TEMP ; context restore
movwf PCLATH ; context restore
swapf STATUS_TEMP,W ; context restore
movwf STATUS ; context restore
swapf W_TEMP,F ; context restore
swapf W_TEMP,W ; context restore
RETFIE ; enable global interrupt (INTCON,GIE)
;***** END OF INTERRUPT SERVICE ROUTINE *****