Hallo Joe,
das mit dem Progmem ist kinderleicht und bewahrt einen wirklich vor bösen Überraschungen. Ich hab hier mal ein kleines Beispiel, wie ich das implementiert habe um Statusmeldungen auszugeben.
Die flash_mem.c:Code:int main(void) { unsigned char actual_page = 0; char main_text[20]; ... get_str_from_flash(6, main_text);//"Menue 4" tp_write_statusbar(&tp, main_text); ...
und in der flash_mem.h steht nur:Code:#include <stdint.h> #include <avr/pgmspace.h> #include <string.h> #include "main.h" #include "flash_mem.h" const char str1[] PROGMEM = "INFO allgemein"; const char str2[] PROGMEM = " ";//14 Leerzeichen const char str3[] PROGMEM = "Menue 1"; const char str4[] PROGMEM = "Menue 2"; const char str5[] PROGMEM = "Menue 3"; const char str6[] PROGMEM = "Menue 4"; const char str7[] PROGMEM = "Menue 5"; ... const char *strarray1[] PROGMEM = { str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, ... }; void get_str_from_flash(uint16_t strnum, char* str) { if(strnum>0)strcpy_P(str, (const char*)(pgm_read_word(&(strarray1[strnum-1])))); else strcpy(str, "Invalid number!"); }
Code:#ifndef _MEM_FLASH_H_ #define _MEM_FLASH_H_ extern void get_str_from_flash(uint16_t strnum, char* str); #endif /* _MEM_FLASH_H_ */







Zitieren

Lesezeichen