
PIC16F8X
DS30430C-page 50
1998 Microchip Technology Inc.
8.10
Context Saving During Interrupts
During an interrupt, only the return PC value is saved
on the stack. Typically, users wish to save key register
values during an interrupt (e.g., W register and
STATUS register). This is implemented in software.
register’s values. The User defined registers, W_TEMP
and STATUS_TEMP are the
temporary
storage
locations for the W and STATUS registers values.
a)
Stores the W register.
b)
Stores the STATUS register in STATUS_TEMP.
c)
Executes the Interrupt Service Routine code.
d)
Restores the STATUS (and bank select bit)
register.
e)
Restores the W register.
EXAMPLE 8-1:
SAVING STATUS AND W REGISTERS IN RAM
PUSH
MOVWF
W_TEMP
; Copy W to TEMP register,
SWAPF
STATUS, W
; Swap status to be saved into W
MOVWF
STATUS_TEMP
; Save status to STATUS_TEMP register
ISR
:
; Interrupt Service Routine
:
;
should configure Bank as required
:
;
POP
SWAPF
STATUS_TEMP, W
; Swap nibbles in STATUS_TEMP register
; and place result into W
MOVWF
STATUS
; Move W into STATUS register
;
(sets bank to original state)
SWAPF
W_TEMP, F
; Swap nibbles in W_TEMP and place result in W_TEMP
SWAPF
W_TEMP, W
; Swap nibbles in W_TEMP and place result into W