Fernando Soares <spam_OUTFernando.Manuel.Ramos.SoaresTakeThisOuT
UNINOVA.PT> wrote:
{Quote hidden}>To save W, STATUS and FSR you can use:
>
> movwf SavedW
> swapf STATUS,W
> movwf SavedSTATUS
> movf FSR,W
> movwf SavedFSR
> .....
>
>To restore W, STATUS and FSR you can use:
>
> .....
> movf SavedFSR,W
> movwf FSR
> swapf SavedSTATUS,W
> movwf STATUS
> swapf SavedW,F
> swapf SavedW,W
> retfie
This works on the 16C71/61 (if you don't care about saving/restoring
PCLATH), but it will not work on any 16Cxx parts whose general-purpose
registers aren't accessible from all pages (e.g., all the other 16Cxx
devices). For those, save registers with:
INTW EQU [any register on page 0]
INTW1 EQU SAVEW + 080H
INTS EQU [any register on page 0]
INTP EQU [any register on page 0]
INTF EQU [any register on page 0]
INT_SERVICE:
MOVWF INTW ;STORE W-REG IN CURRENT DATA-SEGMENT.
MOVF STATUS,W ;GRAB THE STATUS REGISTER.
BCF STATUS,RP0 ;SWITCH TO PAGE 0.
MOVWF INTS ;STORE THE STATUS REGISTER.
MOVF PCLATH,W ;STORE THE PCLATH REGISTER.
MOVWF INTP ;
MOVF FSR,W ;STORE THE FSR.
MOVWF INTF ;
At the end of your interrupt-handler, do this to restore the registers:
INT_EXIT:
MOVF INTF,W ;RESTORE THE FSR.
MOVWF FSR ;
MOVF INTP,W ;RESTORE THE PCLATH REGISTER.
MOVWF PCLATH ;
MOVF INTS,W ;RESTORE THE STATUS REGISTER,
MOVWF STATUS ;
SWAPF INTW ;RESTORE THE W-REGISTER.
SWAPF INTW,W ;
RETFIE ;RETURN AND RE-ENABLE INTERRUPTS.
-Andy
P.S. As far as I know, Klaus Borchers was the first to publicize this
pair of routines.
--
Andrew Warren - .....fastfwdKILLspam
@spam@ix.netcom.com
Fast Forward Engineering, Vista, California