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 support@ccsinfo.com

Access to program memory

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



Joined: 18 Aug 2006
Posts: 6

View user's profile Send private message

Access to program memory
PostPosted: Fri Aug 18, 2006 5:08 am     Reply with quote

Hi,

I'm trying CCS compiler and wished to access a char array stored in program memory. To do it, I first tought I could use a pointer but CCS doesn't allow pointers to constant datas.

So I tried to retrieve the address of my first element in the char array to use the function read_program_memory but it didn't work either, so is there a way to access it without using an index to the array ?

Thank you,

Here is the idea I tought could work :

const char msg[] = "Hello World!";
int16 addr;
char *data;

//Retrieve the address in program memory of the first element
addr = &msg[0];

//Read program memory and store it in RAM
do
{
read_program_memory(addr, data, 1);
addr++;
}while(data != NULL);
rwyoung



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

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

PostPosted: Fri Aug 18, 2006 7:15 am     Reply with quote

Warning: untested, uncompiled! Use at your own risk.

Code:

const char msg[] = "my message";
int8 i;

i = 0;
while(msg[i])
{
   // do something with msg[i]
   i++;
}

If you are going to be using the value of msg[i] then you might want to consider assigning it to a temporary variable rather than allowing the code for the table jump more than once. Execution speed would generally be a bit higher.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Aug 18, 2006 11:14 am     Reply with quote

Look at the asm code generated when accessing a const array. You will see why the read program memory doesn't work.
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