Searching \ for '[PIC] C18 table stuff' 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/microchip/memory.htm?key=table
Search entire site for: 'C18 table stuff'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] C18 table stuff'
2012\01\16@162815 by PICdude

flavicon
face
On the subject of tables in C18, as I've been tinkering with C  (instead of asm) for PICs, I'm going to get into tables soon.

Off the top of my head right now, I can see how I'd use TBLPTRU/H/L to  point to the correct data, but not sure yet how data is declared and  held in memory efficiently, and how these will be 256-byte boundary  aligned (though I would think that that's not necessary here).  These  will be pre-determined values.

Anyone care to share an example of how this is done with C18?  AFAIK,  the mchip app notes all show this in assembly.

Cheers,
-Neil.

2012\01\16@164716 by PICdude

flavicon
face
I should also point out that this is for an 18F PIC.



Quoting PICdude <spam_OUTpicdude3TakeThisOuTspamnarwani.org>:

{Quote hidden}

>

2012\01\17@002837 by PICdude

flavicon
face
Put a bit of time into this tonight, and partially answering my own  question, I found that I can do it this way (simplified)...

// Define data...
unsigned char rom LookupTable[10] = { 1,2,3,5,7,9,11,13,17,19 };
// Access/retrieve data...
a = LookupTable[5];

But still wondering, is there a more space-efficient way to do this if  I directly manipulate TBLPTRU/H/L etc ?

Cheers,
-Neil.




Quoting PICdude <.....picdude3KILLspamspam@spam@narwani.org>:

{Quote hidden}

>> -

2012\01\17@023005 by Tamas Rudnai

face picon face
Hi Neil,

I guess you can use these operations (hope someone has better algorithm for
you):


Initialize table pointer (traditional way):
   movlw   upper ( table )
   movwf   TBLPTRU
   movlw   high ( table )
   movwf   TBLPTRH
   movlw   low ( table )
   movwf   TBLPTRL

Initialize table pointer (cheat way, when you are absolutely sure that the
table is in the page 0...):
   clrf    TBLPTRU
   clrf    TBLPTRH
   movlw   low ( table )
   movwf   TBLPTRL

Initialize table pointer (cheat way, when you use a separate section in the
linker script for the table):
   clrf    TBLPTRU          ; assume that the table is on below that range
   movlw   high ( table )   ; load the section address only
   movwf   TBLPTRH
   clrf    TBLPTRL          ; table starts at the offset 0 on that section

incrementing by one (efficient way)
   TBLRD*+
   ; we do not use the value of TABLAT here so we only incremented the
pointer...

incrementing manually by one (math operations way, you do not need this...):
   INCF    TBLPTRL
   CLRF    WREG
   ADDWFC  TBLPTRH
   ADDWFC  TBLPTRU

incrementing by another number:
   MOVLW   0x10 ; or other incrementals
   ADDWF   TBLPTRL
   CLRF    WREG
   ADDWFC  TBLPTRH
   ADDWFC  TBLPTRU ; you can leave out this if you absolutely sure it will
never overflow

incrementing by another number (silly thing, slightly smaller prog mem
footprint but much slower):
   MOVLW   0x10 ; or other incrementals
   TBLRD*+
   DECFSZ  WREG,F
   BRA     $-4

Tamas



On 17 January 2012 05:28, PICdude <.....picdude3KILLspamspam.....narwani.org> wrote:

{Quote hidden}

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