PIC16C71X
8.6 Context Saving During Interrupts
During an interrupt, only the return PC value is saved
on the stack. Typically, users may wish to save key reg-
isters during an interrupt i.e., W register and STATUS
register. This will have to be implemented in software.
Example 8-1 stores and restores the STATUS and W
registers. The user register, STATUS_TEMP, must be
defined in bank 0.
The example:
a) Stores the W register.
b) Stores the STATUS register in bank 0.
c) Executes the ISR code.
d) Restores the STATUS register (and bank select
bit).
e) Restores the W register.
EXAMPLE 8-1: SAVING STATUS AND W REGISTERS IN RAM
MOVWF W_TEMP
;Copy W to TEMP register, could be bank one or zero
SWAPF STATUS,W
;Swap status to be saved into W
MOVWF STATUS_TEMP
;Save status to bank zero STATUS_TEMP register
:
:(ISR)
:
SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W
;(sets bank to original state)
MOVWF STATUS
;Move W into STATUS register
SWAPF W_TEMP,F
;Swap W_TEMP
SWAPF W_TEMP,W
;Swap W_TEMP into W
DS30272A-page 64
© 1997 Microchip Technology Inc.