piclist 1996\05\02\154919a >
Thread: Interrupts on 16C84
www.piclist.com/techref/microchip/ints.htm?key=interrupt
face
flavicon
face BY : Andrew Warren email (remove spam text)



Adrian Kennard <spamadrianspamrhanna.demon.co.uk> 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 - TakeThisOuTfastfwdTakeThisOuTspamspam_OUTix.netcom.com
Fast Forward Engineering, Vista, California
http://www.geocities.com/SiliconValley/2499
<199605021954.MAA15296@dfw-ix5.ix.netcom.com>

See also: www.piclist.com/techref/microchip/ints.htm?key=interrupt
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Interrupts on 16C84

month overview.

new search...