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
SWAPF
MOVWF
:
W_TEMP
STATUS,W
STATUS_TEMP
;Copy W to TEMP register, could be bank one or zero
;Swap status to be saved into W
;Save status to bank zero STATUS_TEMP register
:(ISR)
:
SWAPF
STATUS_TEMP,W
;Swap STATUS_TEMP register into W
;(sets bank to original state)
;Move W into STATUS register
;Swap W_TEMP
MOVWF
SWAPF
SWAPF
STATUS
W_TEMP,F
W_TEMP,W
;Swap W_TEMP into W
DS30272A-page 64
1997 Microchip Technology Inc.