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

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

Re: [avr-gcc-list] pointer to program memory string


From: E. Weddington
Subject: Re: [avr-gcc-list] pointer to program memory string
Date: Wed, 24 Nov 2004 07:10:39 -0700

On 24 Nov 2004 at 15:39, Leo Hendrawan wrote:

> Hello all,
> 
> suppose i have a struct which is:
> 
>       struct a {
>               char*data;      // data to be sent
>               unsigned int datalen;
>               char*datasrc;   // data source
>       };
> 
> and i have some program memory strings:
> 
>       char b[] PROGMEM = {"........"};
>       char c[] PROGMEM = {"............."};
> 
> then could point the datasrc above to these program memory strings like
> this:
> 
>       a->data = &buffer[0];   // point to the data buffer to be sent
> 
>       a->datasrc = &b[0]; (or) a->datasrc = &c[0];
> 
>       a->datalen = strlen_P(datasrc);
> 
>       for(i=0 ; i<(a->datalen-1) ; i++)
>       {
>               a->data[i]=PRG_RDB(a->datasrc[i]);
>       }
> 
> i have tried this once but it doesn't work.
> any suggestion?
> 


for(i=0 ; i<(a->datalen-1) ; i++)
{
        a->data[i]=PRG_RDB(a->datasrc + i);
}

Using array notation on a->datasrc will cause the value to be gotten from RAM. 
a->datasrc is 
the beginning address of the string in Flash. It is not an array per se. You 
want to add an offset 
to the address to get the address of the next character in the string. 
Untested, of course.

HTH
Eric


reply via email to

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