Using interrupts on the PIC

If you want to save the status register (recommended), you will need to make use of the swapf f,w instruction which doesn't affect the z flag like movf f,w. Here is a typical start and end to an interrupt service routine. Only two source responses are shown for clarity.

service movwf   save_w
        swapf   status,w
        movwf   save_s		;save the important registers, status and w


	btfsc   TIMER0_FLAG     ;check if interrupt is timer0
	goto    timer

	btfsc   EEPROM_FLAG	;check if interrupt is eeprom write finish
	goto    eeprom

	goto    out             ;not recognised interrupt: exit

eeprom	bcf     EEPROM_FLAG     ;clear service flag

;eeprom interrupt service code here

	goto    out


timer	bcf     TIMER0_FLAG     ; clear service flag

;rtcc interrupt service code here

	goto    out

out	swapf   save_s,w
        movwf   status
        swapf   save_w,f
        swapf   save_w,w	;restore registers
        retfie			;return from interrupt
This will work on the 61, 71, and 84, but not on parts with bank-switched registers.

This is an equivalent circuit for the interrupt flag logic.