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

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

Re: [avr-gcc-list] array of floats in program memory


From: Ernst den Broeder
Subject: Re: [avr-gcc-list] array of floats in program memory
Date: Tue, 8 Apr 2003 09:07:02 -0400 (EDT)

Joerg,

Adding 'static' to my variable declaration fixed my original code.  
Thanks for the code examples.  

Ernst


On Tue, 8 Apr 2003, Joerg Wunsch wrote:

> Ernst den Broeder <address@hidden> wrote:
> 
> > This piece of code does not compile (winavr-20030312).  I get a 
> > __progmem__ attribute ignored warning message, ...
> 
> Strange.  It works here:
> 
> #include <avr/pgmspace.h>
> 
> float getv(int i)
> {
>   static float PROGMEM afr_vs_voltage[62]=
>     {
>         1.40, 10.08,
>         1.45, 10.23, 
>         2.85, 19.66,
>         2.90, 20.66
>     };
>   float f;
> 
>   memcpy_P(&f, afr_vs_voltage + i, sizeof(float));
>   return f;
> }
> 
> The following yields slightly more efficient code:
> 
> #include <avr/pgmspace.h>
> 
> float getv(int i)
> {
>   static float PROGMEM afr_vs_voltage[62]=
>     {
>         1.40, 10.08,
>         1.45, 10.23, 
>         2.85, 19.66,
>         2.90, 20.66
>     };
>   union
>     {
>       unsigned char b[4];
>       float f;
>     }
>   u;
>   unsigned char *p;
> 
>   p = (unsigned char *)(afr_vs_voltage + i);
> 
>   u.b[0] = PRG_RDB(p++);
>   u.b[1] = PRG_RDB(p++);
>   u.b[2] = PRG_RDB(p++);
>   u.b[3] = PRG_RDB(p);
> 
>   return u.f;
> }
> 
> 



reply via email to

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