Adrian Kennard wrote: > Seeing as I have spent half a day chasing this bug, I thought I > would share it with you all. > > If you write an interrupt handler on a 16C84, then you need to > manually store the W register and STATUS register to ensure they > main program doesn't go wrong. .... I forgot that re-loading W would > of course change the Z flag !!! So you must restore STATUS, then > restore W, and then set or clear Z depending on the stored value of > STATUS. What a mess... Adrian: Sorry you wasted half a day on this. An easier way is the following, which is on mmy web page and has been in the Microchip data books for a couple of years now: INTW EQU [any page-0 register] INTS EQU [any page-0 register] .... ; INTERRUPT SERVICE ROUTINE: PUSH MOVWF INTW ;SAVE THE W-REGISTER. SWAPF STATUS,W ;SAVE THE STATUS MOVWF INTS ;REGISTER. BCF STATUS,RP0 ;MAKE SURE WE'RE ON ;REGISTER PAGE 0 ;[optional]. .... POP SWAPF INTS,W ;RESTORE THE STATUS MOVWF STATUS ;REGISTER SWAPF INTW ;RESTORE THE SWAPF INTW,W ;W-REGISTER. RETFIE ;RETURN AND RE-ENABLE ;INTERRUPTS. Note that the STATUS register doesn't HAVE to be SWAPFed into and out of INTS; doing so just keeps the Z flag from being disturbed on ENTRY to the interrupt handler. I've never needed this feature, but it doesn't take any more code or time than using MOVFs, so there's no reason not to do it. -Andy Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California http://www.geocities.com/SiliconValley/2499