avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] String in flash


From: E . Weddington
Subject: Re: [avr-gcc-list] String in flash
Date: Tue, 14 Oct 2003 16:38:41 GMT

> Russell Shaw wrote:
> > E.Weddington wrote:
> > 
> >>> I've read all the manual and header files. I've tried:
> ....
> >> This is the way you would declare it outside a 
function:
> >>
> >> #include <avr/pgmspace.h>
> >> #include <inttypes.h>
> >>
> >> static uint8_t hex[] PROGMEM = "0123456789abcdef";
> >>
> >> Use the pgm_read_byte() macro to read a data value 
that is placed in 
> >> flash such as:
> >>
> >> val = pgm_read_byte(&(hex[3]));   // val == '3'
> >>
> >> Sorry if the docs are confusing about this.
> > 
> > 
> > Hi,
> > I tried PROGMEM and found these both give the same 
result:
> > 
> > static uint8_t hex[] PROGMEM = "0123456789abcdef";
> > static uint8_t PROGMEM hex[] = "0123456789abcdef";
> 
> Please disregard the last message (i got thoughroughly 
confused;)
> 

Additional note:

PROGMEM is defined in pgmspace.h to be a GCC function 
attribute. You can look up attributes in the GCC user 
manual for more information.

Generally the preferred form is:
static uint8_t hex[] PROGMEM = "0123456789abcdef";
where the attribute comes after the declaration of the 
variable and before the initializer. There seems to be less 
problems this way.

Eric





reply via email to

[Prev in Thread] Current Thread [Next in Thread]