On Sunday 09 March 2003 04:36 pm, Neil Bradley wrote: > Can anyone verify that my saving/restoring W and STATUS below are > correct? I'm getting VERY erratic behavior in my foreground code > with or without this snippet (even if I just change the status > register in the ISR), and I'm not entirely sure that it's really > saving off the status register properly. From what I understand, if > I'm doing a fast interrupt, I need to save/restore registers > myself: > > ...saving context... > > movwf ISRHighW ; Save off W > movf STATUS, W ; Put status in W > movwf ISRHighStatus ; Store the status > > ...restoring context... > > movf ISRHighStatus, W ; Save off working register > movwf STATUS ; Put back in status > register movf ISRHighW, W ; Restore W! > retfie > > I have the quintessential guide to the PIC, but it's a 16F in the > book which contains assembly syntax that won't work on the 18F. ;-| > I'm hoping my translation is correct - please advise me if it > isn't. Thanks! As I understand it from reading the data sheet, the W, BSR, and STATUS are automatically stored on interrupt. If you do a RETFIE FAST you get them back. However, if you're using both high and low priority interrupts, you can only use the fast RETFIE safely in the high priority interrupts (as the registers stored on entry to the low-priority interrupt handler will get trashed as soon as a high-priority interrupt comes along and preempts). So if you're using both, you *have* to store these registers in the low-priority interrupt handler (and restore them and do a regular retfie), while you can use the RETFIE FAST in the high-priority handler. -- Ned Konz http://bike-nomad.com GPG key ID: BEEA7EFE -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics