> I don't see anyone mentioning PCLATH context saving here! Essential if > you venture into page 1 of program memory.. > > To do it, you would add.. > >> swapf STATUS, w ;Swap status to be saved into W > >> bcf STATUS, RP0 ;Change to bank zero, regardless of current bank > >> movwf STATUS_TEMP ;Save status to bank zero STATUS_TEMP register > movf PCLATH,w > movwf temp_lath > bcf PCLATH,3 ;this line is crucial, otherwise your first > ;GOTO or CALL in the ISR could jump into the > ;other program page with terminal results.. > ;(this is assuming your ISR resides in page 0) A couple of points to consider, though: [1] If your ISR has no program-control instructions, there is no need to save/restore PCLATH at all. While the concept of an ISR without any program-control instructions may seem ridiculous, such a thing is not at all out of the question given the btfss/btfsc,incfsz/decfsz opcodes. In addition, for an ISR which will 'usually' execute very quickly and then leave, it may be useful to do something like: ISR: movwf WSAVE swapf STATUS,w bcf STATUS,5 movwf STSAVE ... do the common stuff here swapf STSAVE,w movwf STATUS swapf WSAVE,f swapf WSAVE,w decfsz Counter retfie bcf STATUS,5 movf PCLATH movwf PCSAVE clrf PCLATH ... do the rare stuff here movf PCSAVE,w movwf PCLATH swapf STSAVE,w movwf STATUS swapf WSAVE,w retfie This will waste three cycles in the "rare" case but will save four in the common case. Another independent--though sometimes useful--technique, is to split the common and rare cases this way: movwf WSAVE swapf STATUS,w bcf STATUS,5 movwf STSAVE .. do the common stuff here swapf STSAVE,w movwf STATUS swapf WSAVE,f swapf WSAVE,w decfsz Counter retfie bsf INTCON,7 ;Global interrupt enable movwf WSAVE2 swapf STATUS,w bcf STATUS,5 movwf STSAVE2 movf PCLATH,w ; If needed movwf PCSAVE .. do the rare stuff here movf PCSAVE,w ; If needed movwf PCLATH swapf STSAVE2,w movwf STATUS swapf WSAVE2,f swapf WSAVE,f retfie ; Or return--doesn't really matter Note that this latter formulation allows the rare part of the ISR to take longer than one interrupt-time to complete. Of course, if it takes too long it may impact the performance of the main program and if it takes much too long it may recurse and trash its saved registers. [2] If the ONLY reason you are saving PCLATH is so you can clear bit 3, and if you know that the main program never uses it for computed gotos in the second half of either page, you may simplify the code a little bit thus: movwf WSAVE swapf STATUS,w movwf STSAVE rlf PCLATH ; Old bit 3 is now in bit 4, which is ; ignored. Old bit 2, which we know to ; be zero, is in bit 3. .. ISR goes here rrf PCLATH ; All is as it was, except that bit 4 ; (which the '74 ignores) is trashed. swapf STSAVE,w movwf STATUS swapf WSAVE,f swapf WSAVE,w retfie