[Top][All Lists]

[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 15:08:47 GMT

> I've read all the manual and header files. I've tried:
>    static const char* hex="0123456789abcdef";
>    static PGM_P hex="0123456789abcdef";
>    static PGM_P hex=(prog_int8_t*)"0123456789abcdef";
> but the "0123456789abcdef" string seems to go in the .data
> section:
> These give an error:
>    static PGM_P hex =  PSTR("0123456789abcdef");
> gives:
>    error: braced-group within expression allowed only 
inside a function

Yes, unfortunately the PSTR() macro can only be used within 
a function.

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.


reply via email to

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