Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4787

Context saving in assembly - 16F72 giving problem

$
0
0
Hi, I am trying to learn about context saving in assembly language. I have 16F72 with me for which I am trying to write an ISR in assembly. I am having a little trouble in understanding the variable declaration part. What I have written upto now is this:
Code:

wsave      var byte    $40    SYSTEM        ' safe for W in all banks
ssave      var byte    BANK0  SYSTEM      ' save STATUS
fsave      var byte    BANK0  SYSTEM          ' save FSR

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

; my code here

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

The above is an unreliable code which is causing problem in operation of the PIC. The problem is that the the PIC hangs up after sometime.

It is running fine without interrupts so it is surely the interrupts causing the problem. I was reading the datasheet and it says W_Temp should be saved in BANK0 & 1. How do you save the same variable in two banks? I also thought that since $40 location can be addressed from all banks, it was ok to just save W-Temp in that location so it can be accessed by all banks, but surely I am wrong here.

So can someone please explain this concept to me so I can correct the above code as well. Thanks

Viewing all articles
Browse latest Browse all 4787

Trending Articles