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

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

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


From: Theodore A. Roth
Subject: Re: [avr-gcc-list] string array in program memory
Date: Thu, 1 Jul 2004 10:21:29 -0700 (PDT)

On Thu, 1 Jul 2004, Jan Spurny wrote:

> avr-gcc 3.0.3 - I am using this code:
>
> ----------------------------------------------------------------------------
> const char mzNone[] PROGMEM   = "[none]";
> const char mz50[] PROGMEM     = "[ 50 ]";
> const char mz100[] PROGMEM    = "[100 ]";
>
> PGM_P choices[3] PROGMEM = {mzZrusC, mz50, mz100};
> ----------------------------------------------------------------------------
>
> to make "menu" which is displayed on LCD display and changed by pressing one 
> button, but when I use this array:
>
> ----------------------------------------------------------------------------
> void disp_progmem_str(PGM_P str)
> {
>       char tmpBuf[64];
>       strcpy_P(tmpBuf, str);
>       display(tmpBuf, 0);
> }
>
> void press_button_1()
> {
>       ...
>       choice = choice + 1;
>       if (choice == 3)
>               choice = 0;
>       disp_progmem_str(choices[choice]);

You need to do a prog_mem read of choices here:

        disp_progmem_str (pgm_read_word (choices[choice]));

You might need a cast in there too though.

I do something similar for my menu system, but I have an array of menu
item structs in prog mem. I walk the array and copy the current
item into sram (with memcpy_P), then can get at the menu item string
from prog mem.


---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: address@hidden


reply via email to

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