Interrupts on 16C84
Andrew Warren email (remove spam text)
Adrian Kennard <rhanna.demon.co.uk> wrote: adrian
> 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...
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
POP SWAPF INTS,W ;RESTORE THE STATUS
MOVWF STATUS ;REGISTER
SWAPF INTW ;RESTORE THE
SWAPF INTW,W ;W-REGISTER.
RETFIE ;RETURN AND RE-ENABLE
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.
Andrew Warren - ix.netcom.comfastfwd
Fast Forward Engineering, Vista, California
See also: www.piclist.com/techref/microchip/ints.htm?key=interrupt
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the