Context saving in assembly - 16F72 giving problem


Results 1 to 7 of 7

Threaded View

  1. #1

    Question Context saving in assembly - 16F72 giving problem

    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
    Last edited by financecatalyst; - 3rd August 2012 at 13:56.
    ___________________
    WHY things get boring when they work just fine?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts