Context saving help in assembly - 16f690


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Default Context saving help in assembly - 16f690

    Hi, I am trying to write an ISR in assembly, but when simulating, I am having some errors in proteus. Can someone please have a look into this context saving part of my code and advise me if it is OK? I originally have it for 16f676, but trying to adapt it to 16F690. Thanks
    Code:
    ' RAM Variables are declared here 
    wsave       var byte    $70     SYSTEM          ' safe for W in all banks
    ssave       var byte    BANK0   SYSTEM          ' save STATUS
    psave       var byte    BANK0   SYSTEM          ' save PCLATH
    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
            movwf   fsave          ; save FSR
            movf    PCLATH, W       ; Save PCLATH
            movwf   psave
    
    
            ; get ready to jump within the ISR page
            movlw   ((INTHAND) >> 8) ; Set PCLATH for jump
            movwf   PCLATH
     . 
    .
    .
    .
    isr routine
    .
    .
    .
    EndInt  ; restore the machine state and return from interrupts
            movf    fsave,w
            movwf   FSR             ; restore FSR
            movf    psave,w
            movwf   PCLATH          ; restore PCH
            swapf   ssave,w
            movwf   STATUS          ; restore Status
            swapf   wsave,f
            swapf   wsave,w         ; restore WREG
            retfie
    endasm

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Context saving help in assembly - 16f690

    You should only save context on chips with 2K or less program space.
    The 16F690 has 4K.

    When there's more than 2K, PBP has to do the context saving before jumping to the ISR.
    At that point, the registers have been changed. So if you try to save context again, you're saving the changed values.

    You always have to restore context, no matter how much program space there is.
    DT

  3. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Context saving help in assembly - 16f690

    Hello Darrel, if I do not have to save it, what variables I will use to restore it or how it is restored. Currently I have the following restoration code-
    Code:
    EndInt  ; restore the machine state and return from interrupts
            movf    fsave,w
            movwf   FSR             ; restore FSR
            movf    psave,w
            movwf   PCLATH          ; restore PCH
            swapf   ssave,w
            movwf   STATUS          ; restore Status
            swapf   wsave,f
            swapf   wsave,w         ; restore WREG
            retfie
    2) If PBP saves the context then, can I start straightaway by execution of my code assuming I will be in BANK0?
    Thanks

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Context saving help in assembly - 16f690

    You restore it the same way when PBP saves it.
    PBP uses the wsave, ssave and psave variables that you create.
    PBP does not save the FSR register, and you don't need to save FSR unless your ISR uses it.

    Yes, it will be in BANK0.
    DT

  5. #5
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Context saving help in assembly - 16f690

    Thanks Darrel. It works.

Similar Threads

  1. Context saving in assembly - 16F72 giving problem
    By financecatalyst in forum Off Topic
    Replies: 6
    Last Post: - 3rd August 2012, 20:30
  2. PIC with Automatic Context Saving
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 29th August 2011, 16:16
  3. IDE help context ID location
    By Normnet in forum General
    Replies: 2
    Last Post: - 25th July 2010, 18:14
  4. 16F to 18F context saving differences
    By brittons in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st April 2007, 03:40
  5. I think my interrupt is not saving context properly?
    By royly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th December 2004, 17:21

Members who have read this thread : 1

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