English
Language : 

PIC16C6X_13 Datasheet, PDF (139/334 Pages) Microchip Technology – null8-Bit CMOS Microcontrollers
PIC16C6X
13.6 Context Saving During Interrupts
Applicable Devices
61 62 62A R62 63 R63 64 64A R64 65 65A R65 66 67
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 13-1 stores and restores the STATUS and W
registers. Example 13-2 stores and restores the
STATUS, W, and PCLATH registers (Devices with
paged program memory). For all PIC16C6X devices
with greater than 1K of program memory (all devices
except PIC16C61), the register, W_TEMP, must be
defined in all banks and must be defined at the same
offset from the bank base address (i.e., if W_TEMP is
defined at 0x20 in bank 0, it must also be defined at
0xA0 in bank 1, 0x120 in bank 2, and 0x1A0 in bank 3).
The examples:
a) Stores the W register
b) Stores the STATUS register in bank 0
c) Stores PCLATH
d) Executes ISR code
e) Restores PCLATH
f) Restores STATUS register (and bank select bit)
g) Restores W register
EXAMPLE 13-1: SAVING STATUS AND W REGISTERS IN RAM (PIC16C61)
MOVWF
SWAPF
MOVWF
:
:(ISR)
:
SWAPF
W_TEMP
STATUS,W
STATUS_TEMP
STATUS_TEMP,W
MOVWF
SWAPF
SWAPF
STATUS
W_TEMP,F
W_TEMP,W
;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
;Swap STATUS_TEMP register into W
;(sets bank to original state)
;Move W into STATUS register
;Swap W_TEMP
;Swap W_TEMP into W
EXAMPLE 13-2: SAVING STATUS, W, AND PCLATH REGISTERS IN RAM
(ALL OTHER PIC16C6X DEVICES)
MOVWF
SWAPF
CLRF
MOVWF
MOVF
MOVWF
CLRF
BCF
MOVF
MOVWF
:(ISR)
:
MOVF
MOVWF
SWAPF
MOVWF
SWAPF
SWAPF
W_TEMP
STATUS,W
STATUS
STATUS_TEMP
PCLATH, W
PCLATH_TEMP
PCLATH
STATUS, IRP
FSR, W
FSR_TEMP
PCLATH_TEMP, W
PCLATH
STATUS_TEMP,W
STATUS
W_TEMP,F
W_TEMP,W
;Copy W to TEMP register, could be bank one or zero
;Swap status to be saved into W
;bank 0, regardless of current bank, Clears IRP,RP1,RP0
;Save status to bank zero STATUS_TEMP register
;Only required if using pages 1, 2 and/or 3
;Save PCLATH into W
;Page zero, regardless of current page
;Return to Bank 0
;Copy FSR to W
;Copy FSR from W to FSR_TEMP
;Restore PCLATH
;Move W into PCLATH
;Swap STATUS_TEMP register into W
;(sets bank to original state)
;Move W into STATUS register
;Swap W_TEMP
;Swap W_TEMP into W
 1997-2013 Microchip Technology Inc.
DS30234E-page 139