Do you have a similar code paging macros for 4-page machine (16F877)? >From: Don Hyde >Reply-To: pic microcontroller discussion list >To: PICLIST@MITVMA.MIT.EDU >Subject: Re: [PIC]: Program Memory Paging >Date: Mon, 16 Apr 2001 14:25:34 -0500 > >I thought I would share a couple of macros I use to deal with code paging. >These are for a 2-page machine (16C63 in this case). For a 4-page machine, >it is a bit more complicated. > >To use: > > fcall Subroutine_in_other_page > >or: > > fgoto Label_in_other_page > >Potential trap: > >DON'T do > > btfsc STATUS,c > fcall Subroutine_call_you_meant_to_skip > >The fcall macro will create 3 lines of code, but the skip instruction will >only skip the first of these! > >Note: > The MESSG line tells you if there's an unnecessary fcall, but I >couldn't figure out how to get it to print the address in hex, so it's a >pain to figure out where it happened. MPLAB reports the error location as >being in the macro file, so that's totally useless. >The errorlevel 306 stuff suppresses the now-meaningless warnings about >references to the other code page. >Using the bsf and bcf leave the W register undisturbed, which means it can >still be used to pass and return arguments. This is especially important >if >you are using a call into the other page to do a lookup in a table or >something. > >fcall macro t > If((t & 0x800) == ($ & 0x800)) > MESSG fcall not actually needed at #v($). > EndIf > If (t & 0x800) > bsf PCLATH,3 > Else > bcf PCLATH,3 > EndIf > > errorlevel -306 > call t > errorlevel +306 > > If ($ & 0x800) > bsf PCLATH,3 > Else > bcf PCLATH,3 > EndIf > endm > >fgoto macro t > If((t & 0x800) == ($ & 0x800)) > MESSG fgoto not actually needed at #v($). > EndIf > If (t & 0x800) > bsf PCLATH,3 > Else > bcf PCLATH,3 > EndIf > > errorlevel -306 > goto t > errorlevel +306 > > endm > > > -----Original Message----- > > From: Olin Lathrop [mailto:olin_piclist@EMBEDINC.COM] > > Sent: Monday, April 16, 2001 1:28 PM > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: [PIC]: Program Memory Paging > > > > > > > And, unless I am wrong, when you return from the CALL, you > > need to set > > > the PCLATH bits back to the value of the "calling" page - > > although the > > > datasheets are a little fuzzy about this. > > > > You don't need to, but I find it convenient to keep PCLATH > > pointing to the > > current code page. PCLATH only matters when a GOTO or CALL > > are executed, or > > on an explicit modification of PCL. > > > > > > ******************************************************************** > > Olin Lathrop, embedded systems consultant in Littleton Massachusetts > > (978) 742-9014, olin@embedinc.com, http://www.embedinc.com > > > > -- > > http://www.piclist.com hint: To leave the PICList > > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > > > > >-- >http://www.piclist.com hint: To leave the PICList >mailto:piclist-unsubscribe-request@mitvma.mit.edu > > _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu