View previous topic :: View next topic |
Author |
Message |
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
how store constant data tables in ROM memory |
Posted: Tue Feb 01, 2005 3:19 am |
|
|
Hello,
I'am using a PIC 16F877A, i have problem memory space in RAM , and i want to know if its possible to store constant tables of data in ROM, knowing that i need to use this data during the program.
for example :
int8 API_PP_ACCESS_RIGHT_REQ[7]={0x66,0x85,0x01,0xFF,0xFF,0x12,0x34};
-> how store this Table in ROM?
Thanks |
|
|
Ttelmah Guest
|
Re: how store constant data tables in ROM memory |
Posted: Tue Feb 01, 2005 6:45 am |
|
|
global wrote: | Hello,
I'am using a PIC 16F877A, i have problem memory space in RAM , and i want to know if its possible to store constant tables of data in ROM, knowing that i need to use this data during the program.
for example :
int8 API_PP_ACCESS_RIGHT_REQ[7]={0x66,0x85,0x01,0xFF,0xFF,0x12,0x34};
-> how store this Table in ROM?
Thanks |
Add the word 'const' in front of the declaration.
Best Wishes |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
Re: how store constant data tables in ROM memory |
Posted: Tue Feb 01, 2005 10:35 am |
|
|
Thanks for your answerd but i don't use datas of the table one by one, i send all the table in parameter of a function and when i use this kind of definition i can't send all the table in parameter.
for example:
int8 BUS_SELECT_REQ[]={0x2E,0x2F,0x01};
.
.
.
.
send_info(3,BUS_SELECT_REQ); // function who use the table
the function send info use all the constant of the table. With the "const" definition it doesn't works.
Sorry for my english |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue Feb 01, 2005 1:54 pm |
|
|
Since the data tables are "global" in scope and you know in advance what their names are, make the 2nd parameter of your function call a code word. Then inside the function if you receive the code word 1, use data table #1, if you get 2, use datatable #2, etc. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 01, 2005 3:33 pm |
|
|
Alternatively, make the multiple tables into a single 2 dimensional array (this also means there is only one 'decoder' overhead for the constant declaration), and just send the second dimension value to the function.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: how store constant data tables in ROM memory |
Posted: Tue Feb 01, 2005 3:47 pm |
|
|
global wrote: | Thanks for your answerd but i don't use datas of the table one by one, i send all the table in parameter of a function and when i use this kind of definition i can't send all the table in parameter.
for example:
int8 BUS_SELECT_REQ[]={0x2E,0x2F,0x01};
.
.
.
.
send_info(3,BUS_SELECT_REQ); // function who use the table
the function send info use all the constant of the table. With the "const" definition it doesn't works.
Sorry for my english |
The problem is the compilers lack of pointers to constant data. rwyoung suggested that you pass a number as a parameter. You could then use a switch statement to determine which const data to load. Another option is to have the same data type in declared not using const. Then copy the const data to the ram (memcpy) and pass a pointer. I have used this approach for doing strings in the past. |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
Re: how store constant data tables in ROM memory |
Posted: Fri Feb 04, 2005 7:43 am |
|
|
Thanks for your help, I use your tips and i also found a function to include on my header
#device *=16
Now i've got more space in RAM. |
|
|
|