Searching \ for 'Table lookup and AN556' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=table
Search entire site for: 'Table lookup and AN556'.

Truncated match.
PICList Thread
'Table lookup and AN556'
1998\08\20@050919 by Ralph Landry

flavicon
face
I'm trying to decipher the AN556 that discusses table lookup
when the table crosses a page.  I'd like to figure it out rather
than add a few nop's as I'm right at the edge of say around
FAh and rolls over.  The AN556 says that example 5 is a
same of code that will allow the user to place and access
a table anywhere in memory.

I haven't been able to get it to work on a 16C65,  I've used
the sim and I see where PCL is rolling over and crash it goes.

Does anyone have a fix for example 5, or a better explanation?

-Ralph
spam_OUTrlandryTakeThisOuTspamhaywood.main.nc.us
"If they call it Tourist Season why can't we shoot 'em?"

1998\08\20@081528 by Chip Weller

flavicon
face
Ralph Landry wrote:


>I'm trying to decipher the AN556 that discusses table lookup
>when the table crosses a page.  I'd like to figure it out rather
>than add a few nop's as I'm right at the edge of say around
>FAh and rolls over.  The AN556 says that example 5 is a
>same of code that will allow the user to place and access
>a table anywhere in memory.
>
>I haven't been able to get it to work on a 16C65,  I've used
>the sim and I see where PCL is rolling over and crash it goes.
>
>Does anyone have a fix for example 5, or a better explanation?
>
>-Ralph

Here is a bit of code I have used with MPASM when compiling to absolute code
(not relocatable .obj):

   movlw high TableStart
   movwf PCLATH            ; set the latch value.
   movf SwitchVariable,w     ; get the switch variable.
   addlw -(TableEnd-TableStart)    ; carry if past end of table.
   skpnc
       goto TableDefault    ; default, or out of range value.
   ; use conditional compile to minimize code if table not on page boundry.
   if ((TableStart) & 0xFF00) == ((TableEnd-1) & 0xFF00)
       ; no need for PCLATH modifications, use short version.
       addlw TableEnd-TableStart+low TableStart
       ; carry is meaningless here, but PCLATH is correct, from range check
     else  ; full PCLATH modification code.
       ; if over our table size first correct offset and then add in table.
       addlw TableEnd-TableStart         ; restore, ignore carry.
       ; now add in the start of the table. If carry update high byte
       addlw low TableStart
       skpnc
           incf PCLATH,f   ; update high byte.
     endif
   movwf PCL           ; do the jump.

TableStart
   retlw 0        ; list of jumps, returns, or whatever is desired.
   retlw 1
TableDefault        ; label a default condition if out of range, or place
                   ; outside of the table if desired.
   retlw 2
   retlw 3
TableEnd            ; final label to tell size of table.
(TableEnd-TableStart)

(PS: I just here converted the code from a more complex "switch / case"
macro so you may want to double check the range tests.)

Chip Weller

1998\08\20@115123 by Mike Keitz

picon face
On Thu, 20 Aug 1998 04:57:40 -0700 Ralph Landry
<.....rlandryKILLspamspam@spam@HAYWOOD.MAIN.NC.US> writes:
>I'm trying to decipher the AN556 that discusses table lookup
>when the table crosses a page.  I'd like to figure it out rather
>than add a few nop's as I'm right at the edge of say around
>FAh and rolls over.  The AN556 says that example 5 is a
>same of code that will allow the user to place and access
>a table anywhere in memory.

The example should work, unless you're crossing the 2K pages.  Then
numerous additional complications will set in.  Also note that offset
should be 1 to access the first entry in the table.  Using offset of zero
will cause the movwf PCL instruction to go to itself, forming an infinite
loop.

A single movwf PCL instruction can be used to access all the tables in
the same 2K program page where it resides.  So usually I put one
somewhere other than at the head of the table, and label the first retlw
in the table as "table" instead.  Then an offset of zero will return the
first entry.

If you have tables in multiple 2K pages, including possibly some that
cross over, you'll need movwf PCL instructions exactly the same place in
all pages.  Otherwise the 'call table' instruction may go to the wrong
page, and not find a movwf PCL instruction there.



_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...