avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] Problem accessing bytes in program space


From: Rich Teer
Subject: [avr-libc-dev] Problem accessing bytes in program space
Date: Mon, 28 Jan 2008 12:16:01 -0800 (PST)

Hi all,

I have some strings that I'm storing in program space like this:

const char PROGMEM sms_keys_0[] = "abcABC0  ";
const char PROGMEM sms_keys_1[] = "-_1      ";
const char PROGMEM sms_keys_2[] = "abcABC2  ";
const char PROGMEM sms_keys_3[] = "defDEF3  ";
const char PROGMEM sms_keys_4[] = "ghiGHI4  ";
const char PROGMEM sms_keys_5[] = "jklJKL5  ";
const char PROGMEM sms_keys_6[] = "mnoMNO6  ";
const char PROGMEM sms_keys_7[] = "pqrsPQRS7";
const char PROGMEM sms_keys_8[] = "tuvTUV8  ";
const char PROGMEM sms_keys_9[] = "wxyzWXYZ9";

PGM_P sms_keys[] PROGMEM = {
    sms_keys_0,
    sms_keys_1,
    sms_keys_2,
    sms_keys_3,
    sms_keys_4,
    sms_keys_5,
    sms_keys_6,
    sms_keys_7,
    sms_keys_8,
    sms_keys_9
};


I want to access characters of each string one at a time.  Something like

    uart_puts (strcpy_P (buf, (PGM_P)pgm_read_word (&sms_keys[num])))

will correctly print the numth string, but trying to print the string starting
from elsewhere leads to data being read from God knows where:

    uart_puts (strcpy_P (buf, (PGM_P)pgm_read_word (&sms_keys[num][2])))

I'd expect this to print the numth string starting at the 3 character
(it works as expected in non-embedded normal C).  Am I doing something
cluelessly wrong, or am I tickling a bug in the compiler?  I'm using
avr-libc-1.4.6 with avr-gcc 3.4.3 (using a newer version of gcc is a
bit problematic at the moment...).

TIA,

-- 
Rich Teer, SCSA, SCNA, SCSECA, OGB member

CEO,
My Online Home Inventory

URLs: http://www.rite-group.com/rich
      http://www.linkedin.com/in/richteer
      http://www.myonlinehomeinventory.com




reply via email to

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