Implementing Table Read and Write in PIC18F4550

Hi,
Anyone knows here how to implement Table Read and Write in PIC18F4550 using MPLAB-X or MPLAB IDE as the environment and C18 Compiler.

Kurenai_ryu

Advanced Member level 2

Joined Jun 10, 2006 Messages 694 Helped 164 Reputation 326 Reaction score 112 Trophy points 1,323 Location Bolivia Activity points 6,157

you need to use the 'rom' attribute while defining your pointer and #pragma romdata if it's a table.

for example a table in flash memory (two examples, one table at 0x5000 and other at 0x5200):

#pragma romdata PRODS=0x5000 rom int Productos[]= ; #pragma romdata PRODS2=0x5200 rom char Prods[][2]=< , , , , , , , , , , , , , , , , , >; //to finnish pragma code! #pragma code

and use it like a normal table

. sb1 = Prods[3][0]; sb2 = Prods[3][1]; .. //you know, right?


if you need you can define the pointer externally as:

extern rom int Productos[]; extern rom char Prods[][2];

if you want a char pointer to any part of the flash memory,
define a pointer
rom char* maPointer;

and use it as you need

. maPointer = 0x5000; //points to some part of the memory bv = (*maPointer); //read address 0x5000 . maPointer++; //now points to 0x5001; //etc . //and also . (*maPointer) = someValue; //prefills page byte, read the datasheet for actual write in memory. 

it also works with the table version!

Prods[10][0]=newValue; //prefills page byte, again please read the datasheet for actual write. even it's more complicated with a table. do it with a known pointer