Re: Context saving in assembly - 16F72 giving problem
Thanks Darrel, here is my complete code:
ISR:
asm
movwf wsave ; Save WREG
swapf STATUS, W
clrf STATUS ; Point to bank 0
movwf ssave ; Save STATUS
movf FSR,w
movf fsave ; save FSR
BTFSS INTCON,TMR0IF
GOTO EndInt
bcf INTCON, TMR0IF ; clear the interrupt
incf _i
movlw 3
bcf STATUS,Z
XORWF _i,w
BTFSS STATUS,Z
Goto EndInt
clrf _i
bcf STATUS,Z
MOVLW 0
addwf PORTA,w
BTFSS STATUS,Z
clrf PORTA
BCF STATUS,Z
MOVLW 0
addwf PORTC,w
BTFSS STATUS,Z
clrf PORTC
EndInt ; restore the machine state and return from interrupts
movf fsave,w
movwf FSR ; restore FSR
swapf ssave,w
movwf STATUS ; restore Status
swapf wsave,f
swapf wsave,w ; restore WREG
retfie
endasm
My PIC just hangs. The oscillator pins get weird constant voltage levels, one ground, one at 4.7/4.8 volts. The code is just clearing PORTA/C after certain interval.
I would also take this opportunity to ask you one question which I have heard before as well but never understood completely which is -> WHY should I save PCLATH? The datasheet says
During an interrupt, only the return PC value is saved on the stack. Typically, users may wish to save key registers during an interrupt (i.e, W, STATUS registers)...
and it also provides few lines about context saving.
___________________
WHY things get boring when they work just fine?
Bookmarks