DPRG
DPRG List  



[DPRG] Pointers to values in Program Space in WINAVR

Subject: [DPRG] Pointers to values in Program Space in WINAVR
From: Kipton Moravec kip at kdream.com
Date: Thu Sep 9 14:31:47 CDT 2004

Well the last question was answered well.  Showing my ignorance. Lets try 
this one:

Problem #1

const char outstates[9] PROGMEM = {0,40,121,120,124,44,40,122,0};
// array of values in program memory (flash)


temp = outstates[1];  // works

i = 1;
temp = outstates[i]; // does not work.

====================================
The FAQ in the avr-lib documentation says the way to do arrays of constant 
strings is the following:


const char cPOWER_UP[]     PROGMEM = "POWER_UP    ";
const char cSTART_PUSHED[] PROGMEM = "START_PUSHED";
const char cRUN_POSITION[] PROGMEM = "RUN_POSITION";
const char cLIFT_DOWN[]    PROGMEM = "LIFT_DOWN   ";
const char cLIFT_UP[]      PROGMEM = "LIFT_UP     ";
const char cDROP_DIE[]     PROGMEM = "DROP_DIE    ";
const char cLOWER_LIFT[]   PROGMEM = "LOWER_LIFT  ";
const char cLEAVE_DIE[]    PROGMEM = "LEAVE_DIE   ";
const char cFINISH[]       PROGMEM = "FINISH      ";

PGM_P outstate_name[9] PROGMEM = {  cPOWER_UP,
                                     cSTART_PUSHED,
                                     cRUN_POSITION,
                                     cLIFT_DOWN,
                                     cLIFT_UP,
                                     cDROP_DIE,
                                     cLOWER_LIFT,
                                     cLEAVE_DIE,
                                     cFINISH};

How do I access it?

fputs_P(outstate_name[i],usart); // does not work.

Kip


More information about the DPRG mailing list