At 04:36 PM 3/9/03 -0800, 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: 2 problems: >...saving context... > > movwf ISRHighW ; Save off W > movf STATUS, W ; Put status in W clrf STATUS ;ensure on RAM pg 0 > movwf ISRHighStatus ; Store the status > >...restoring context... > > movf ISRHighStatus, W ; Save off working register > movwf STATUS ; Put back in status register swapf ISRHighW, F ; Restore W! swapf ISRHighW, W > retfie The 1st addition I made simply ensures that Status, FSR, PCLATH, etc get stored in the 1st RAM page. Note that you have to reserve space for ISRHighW on *all* RAM pages. The problem that was nailing you, though, was the way you restored W at the end of the context restore. The problem is that if you simply load W with the saved value, the Status register changes to reflect the value you are loading into W. You don't want that. The SWAPF instruction does not affect the Status register. The 1st swap simply swaps the upper and lower nibble while leaving it in the register. The 2nd swap puts the nibbles back the way they are supposed to be and leaves the result in W. Thanks Andrew Warren for that little snippet - he is the 1st person I am aware of to solve that problem way back in the early days. His method of using swaps to restore W is now standard. dwayne -- Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax Celebrating 19 years of Engineering Innovation (1984 - 2003) .-. .-. .-. .-. .-. .-. .-. .-. .-. .- `-' `-' `-' `-' `-' `-' `-' `-' `-' Do NOT send unsolicited commercial email to this email address. This message neither grants consent to receive unsolicited commercial email nor is intended to solicit commercial email. -- 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