avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] pgmspace with arrays of structs with strings


From: neil
Subject: Re: [avr-chat] pgmspace with arrays of structs with strings
Date: Tue, 03 May 2011 08:40:20 +1200
User-agent: Mutt/1.5.18 (2008-05-17)

> typedef struct
> {
>    struct
>    {
>       uint8       x:4;
>       uint8       y:4;
>    } v;
>    char        name[4];
> } PIN;
> 
> PIN Pin[] PROGMEM =
> {
>    { { 1, 2 }, "PC6" },
>    { { 3, 4 }, "PD0" }
> };
> 
> int main(void)
> {
>    PIN local;
>    uint8 a;
> 
>    memcpy_P(&local, &Pin[0], sizeof(PIN));
>    a = local.v.x;
>    memcpy_P(&local, &Pin[1], sizeof(PIN));
>    a = local.v.y;

Many thanks for this suggestion.  I didn't know that memcpy_P existed but I do
now.  And I think initialising arrays will work for me as well since the names
are all 3 or 4 characters in length so the program memory wasted by declaring:

  char  name[5];

..will be more than compensated for by not storing 16-bit pointers to the
strings in program memory:

    flash: 88 bytes
    RAM:   0 bytes

- neil




reply via email to

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