CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how store constant data tables in ROM memory

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

how store constant data tables in ROM memory
PostPosted: Tue Feb 01, 2005 3:19 am     Reply with quote

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
PostPosted: Tue Feb 01, 2005 6:45 am     Reply with quote

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

View user's profile Send private message

Re: how store constant data tables in ROM memory
PostPosted: Tue Feb 01, 2005 10:35 am     Reply with quote

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 Wink
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 01, 2005 1:54 pm     Reply with quote

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







PostPosted: Tue Feb 01, 2005 3:33 pm     Reply with quote

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

View user's profile Send private message Send e-mail

Re: how store constant data tables in ROM memory
PostPosted: Tue Feb 01, 2005 3:47 pm     Reply with quote

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 Wink


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

View user's profile Send private message

Re: how store constant data tables in ROM memory
PostPosted: Fri Feb 04, 2005 7:43 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group