Go Down

Topic: Work with PROGMEM ? (Read 201 times) previous topic - next topic

Brkic

Oct 20, 2019, 09:31 pm Last Edit: Oct 20, 2019, 09:44 pm by Brkic
Hi, can somebody help me with my code to put them in mem with PROGMEM

my constants char is...
Code: [Select]

#define maxItemSize 17
byte itemSelected, subMenuSelected;

char menu[][maxItemSize] ={"!! START !!","Ampere 2","Battery WET","Equalize OFF","MaintenanceOFF","Time","Voltage","Temperature","V / A reg.","Help","Reboot/Reset","BACK"," "};
char subMenu0[][maxItemSize] = {"WET Lead-Acid", "AGM", "GEL"}; //Baterry
char subMenu1[][maxItemSize] = {"Absorption", "Equalize","Maintenance", "RESET", "BACK"}; //Time of charge
char subMenu2[][maxItemSize] = {"0.5", "1", "2", "3", "4"}; // Ampere of charge
char subMenu3[][maxItemSize] = {"Float", "Absorption", "Equalize", "Maintenance", "RESET", "BACK"}; // Voltage of charge

//this is code to use char from menu and subMenu

itemSelected = displayMenu(menu, sizeof(menu)/maxItemSize);
subMenuSelected = displayMenu(subMenu0, sizeof(subMenu0)/maxItemSize);
subMenuSelected = displayMenu(subMenu1, sizeof(subMenu1)/maxItemSize);
...
...
...

how I can use PROGMEM with my code, how I can convert my code to use PROGMEM ?

somebady can help me ?

TheMemberFormerlyKnownAsAWOL

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Hutkikz


mcs51mc

This is how I do it
Code: [Select]
// Strings used in project stored in program memory
//
const PROGMEM char Msg_00[]= "!! START !!";
const PROGMEM char Msg_01[]= "Ampere 2";
const PROGMEM char Msg_02[]= "Battery wet";
const PROGMEM char Msg_03[]= "Equalize off";


All messages at top of sketch, easy to track them


To print a message centered on an LCD
Code: [Select]
lcd.printP (LCDLine_1, (int)(LCDCharsPerLine - strlen(Msg_07)) / 2, Msg_07, strlen(Msg_07));

To print a message on given line / column
Code: [Select]
lcd.printP (LCDLine_4, 1, Msg_80, strlen(Msg_80));


Finally the routine in my LCD lib
Code: [Select]
void LCD_ASI::printP (int Line, int Col, const char* Message, int Chars) {
// Sub to write a message from Flash to LCD at given location
//
 char _strDummy[Chars + 1];
 
 setCursor(Line, Col);
 strcpy_P(_strDummy,Message);
 print(_strDummy);
}



I hope this works for you too... ...

Whandall

Code: [Select]
strlen(Msg_07)
does not work on PROGMEM strings, use

Code: [Select]
strlen_P(Msg_07)
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

mcs51mc

Are you sure about that dear Whandall?
Because I copied the above from a working project!

I just changed the text to match the ones from the OP.

Whandall

Probably it's the compiler that evaluates the strlen at compile time before there is a difference in addressing,
it seems to work on PROGMEM strings, but I would still use the strlen_P.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Go Up