tarts
Member level 2
Ok here is typical entry and exit from Interrupt routine in 16f microcontrollers:
Entry
exit:
But recently I used up all general purpose registers in page 0(starts at 0x20h), then I started to use registers in bank 1 (starts at 0xA0h)
Now when I'm in bank 1 and I enter the Interrupt routine then before I clear STATUS in entry I save W into W_TEMP, but actually it won't be saved in W_TEMP because this register is in bank0 and I'm still in bank 1, so it will be saved in some GPR in bank 1.
Has anyone encountered this problem?
I havent seen anyone mentioning it in tutorial website etc.
Entry
Code:
movwf W_TEMP ; Copy W to TEMP register
swapf STATUS,W ; Swap status to be saved into W
clrf STATUS
movwf STATUS_TEMP ; Swaps are used because they do not affect the status bits
; Save status to bank zero STATUS_TEMP register
movfw PCLATH ; save PCLATH regisers
movwf PCLATH_TEMP
clrf PCLATH
movf FSR,w
movwf FSR_TEMP
Code:
exit
movf FSR_TEMP,w
movwf FSR
movfw PCLATH_TEMP ; restore PC
movwf PCLATH ; (sets bank to original state)
swapf STATUS_TEMP,W ; Swap STATUS_TEMP register into W
movwf STATUS ; Move W into STATUS register
swapf W_TEMP,F ; Swap W_TEMP
swapf W_TEMP,W
retfie
But recently I used up all general purpose registers in page 0(starts at 0x20h), then I started to use registers in bank 1 (starts at 0xA0h)
Now when I'm in bank 1 and I enter the Interrupt routine then before I clear STATUS in entry I save W into W_TEMP, but actually it won't be saved in W_TEMP because this register is in bank0 and I'm still in bank 1, so it will be saved in some GPR in bank 1.
Has anyone encountered this problem?
I havent seen anyone mentioning it in tutorial website etc.