Download avr-libc-user-manual..
Transcript
7.3
Frequently Asked Questions
Warning:
There was no such alignment before 2000-07-01, including the old patches for
gcc-2.95.2. Check your old assembler subroutines, and adjust them accordingly.
Back to FAQ Index.
7.3.15
How do I put an array of strings completely in ROM?
There are times when you may need an array of strings which will never be modified. In
this case, you don’t want to waste ram storing the constant strings. This most obvious
thing to do is this:
#include <avr/pgmspace.h>
PGM_P array[2] PROGMEM = {
"Foo",
"Bar"
};
int main (void)
{
char buf[32];
strcpy_P (buf, array[1]);
return 0;
}
The result is not want you want though. What you end up with is the array stored in
ROM, while the individual strings end up in RAM (in the .data section).
To work around this, you need to do something like this:
#include <avr/pgmspace.h>
const char foo[] PROGMEM = "Foo";
const char bar[] PROGMEM = "Bar";
PGM_P array[2] PROGMEM = {
foo,
bar
};
int main (void)
{
char buf[32];
strcpy_P (buf, array[1]);
return 0;
}
Looking at the disassembly of the resulting object file we see that array is in flash as
such:
Generated on Mon Dec 9 22:14:31 2002 for avr-libc by Doxygen
74