问题描述:当使用avr/pgmspace.h库中的PROGMEM宏时,编译器报错。
解决方法:
#include
const char myString[] PROGMEM = "Hello, World!";
char buffer[20];
strcpy_P(buffer, (char*)pgm_read_word(&myString));
int myInt PROGMEM = 42;
int value = pgm_read_word(&myInt);
char myChar PROGMEM = 'A';
pgm_write_byte(&myChar, 'B');
注意:要使用PROGMEM,你的代码必须在编译时使用-A参数来告诉编译器将常量数据存储到程序存储器中。
avr-gcc -mmcu=atmega328p -Os -o output.elf input.c -Wl,--section-start=.data=0x800000,--section-start=.text=0x800000 -Wl,--relax -Wl,--gc-sections -Wl,--print-gc-sections -Wl,-Map=output.map -Wl,-u,vfprintf -lprintf_flt -lm -Wl,-u,vfscanf -lscanf_flt -lm -Wl,--wrap=main -Wl,--wrap=_malloc_r -Wl,--wrap=_free_r -Wl,--wrap=_realloc_r -Wl,--wrap=_calloc_r -Wl,--wrap=exit -Wl,--wrap=atexit -lm
以上是解决Arduino中使用avr/pgmspace.h的PROGMEM遇到问题的解决方法。