xiaobendan 发表于 2006-4-10 20:39:43

请教PROGMEM的使用问题

同样的代码:

const uchar table1[] = {0x7d,0x30,0x5b,0x3b,0x36,0x2f,0x6f,0x38,0x7f,0x3f,0x02};//0--9,-

正常,但是:

const uchar table1[] PROGMEM = {0x7d,0x30,0x5b,0x3b,0x36,0x2f,0x6f,0x38,0x7f,0x3f,0x02};//0--9,-

就不正常了,为什么?

zhoud 发表于 2007-12-4 10:42:36

const uchar table1[] = .....还是定义在RAM中,
const uchar table1[] PROGMEM = ..... 是定义在FLASH里.

ATmega32 发表于 2007-12-4 10:50:33

const uchar table1[] PROGMEM = {0x7d,0x30,0x5b,0x3b,0x36,0x2f,0x6f,0x38,0x7f,0x3f,0x02};//

读取数组元素不能直接用table1,应该用pgm8(table1)
#define pgm8(A)\
((typeof(A))pgm_read_byte(&(A)))

mljda 发表于 2007-12-4 13:00:42

1,2 楼正解
补充
1 const限制符。不可修改
2 所有初始化的ram变量都会占用flash空间,其实在上电时C自动初始化复制到制定的ram空间中去。建议长数据表都定义为PROGMEM

sunjihe 发表于 2011-4-28 11:40:48

请问如果把这句话移植到51单片机应该怎么用C写

zsp06312222 发表于 2017-4-12 09:05:53

PROGMEM学习了{:lol:}
页: [1]
查看完整版本: 请教PROGMEM的使用问题