Datasheet

2003 Microchip Technology Inc. DS30235J-page 57
PIC16C62X
TABLE 9-6: SUMMARY OF INTERRUPT REGISTERS
9.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
registers during an interrupt (e.g., W register and
STATUS register). This will have to be implemented in
software.
Example 9-3 stores and restores the STATUS and W
registers. The user register, W_TEMP, must be defined
in both banks and must be defined at the same offset
from the bank base address (i.e., W_TEMP is defined
at 0x20 in Bank 0 and it must also be defined at 0xA0
in Bank 1). The user register, STATUS_TEMP, must be
defined in Bank 0. The Example 9-3:
Stores the W register
Stores the STATUS register in Bank 0
Executes the ISR code
Restores the STATUS (and bank select bit
register)
Restores the W register
EXAMPLE 9-3: SAVING THE STATUS
AND W REGISTERS IN
RAM
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Value on POR
Reset
Value on all
other
RESETS
(1)
0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF
0000 000x 0000 000u
0Ch PIR1
—CMIF
-0-- ---- -0-- ----
8Ch PIE1
—CMIE
-0-- ---- -0-- ----
Note 1: Other (non Power-up) Resets include MCLR Reset, Brown-out Reset and Watchdog Timer Reset during normal
operation.
MOVWF W_TEMP ;copy W to temp register,
;could be in either bank
SWAPF STATUS,W ;swap status to be saved
into W
BCF STATUS,RP0 ;change to bank 0 regardless
;of current bank
MOVWF STATUS_TEMP ;save status to bank 0
;register
:
: (ISR)
:
SWAPF STATUS_TEMP,
W
;swap STATUS_TEMP register
;into W, sets bank to origi-
nal
;state
MOVWF STATUS ;move W into STATUS register
SWAPF W_TEMP,F ;swap W_TEMP
SWAPF W_TEMP,W ;swap W_TEMP into W