View previous topic :: View next topic |
Author |
Message |
Akutabi
Joined: 18 Aug 2006 Posts: 6
|
Access to program memory |
Posted: Fri Aug 18, 2006 5:08 am |
|
|
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
|
|
Posted: Fri Aug 18, 2006 7:15 am |
|
|
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
|
|
Posted: Fri Aug 18, 2006 11:14 am |
|
|
Look at the asm code generated when accessing a const array. You will see why the read program memory doesn't work. |
|
|
|