22277 发表于 2005-4-22 10:11:31

马老师,关于您的《M128上册》书上的329页

定义在EEPROM中的全局变量

#program data:eeprom

......

......

#program data:eeprom

//这种定义方式在编译器(ICCAVR)不能通过



使用下面的

#pragma data:eeprom

......

......

#pragma data:data

//这样就可以了



不知道怎么回事???

22277 发表于 2005-4-22 10:32:53

#pragma data:eeprom

......

......

#pragma data:data



好像也不行,不懂定义到哪里去了

machao 发表于 2005-4-22 13:23:00

谢谢!这是一个笔误。



下面是ICC的HELP中的解释。



Initializing EEPROM



EEPROM can be initialized in your program source file by allocation global variable to a special area called "eeprom." In C source, this can be done using pragmas. See Program Areas for discussion on different program areas. The resulting file is <output file>.eep. For example,



#pragma data:eeprom



int foo = 0x1234;



char table[] = { 0, 1, 2, 3, 4, 5 };



#pragma data:data



...



int i;



EEPROM_READ((int)&foo, i);        // i now has 0x1234



The second pragma is necessary to reset data area name back to the default "data."



Note that to work around the hardware bug in AVR, location 0 is not used for initialized EEPROM data.



Note that when using in an external declaration (e.g. accessing foo in another file), you do not use the pragma. For example, in another file:



extern int foo;



int i;



EEPROM_READ((int)&foo, i);



正确的定义方法是:



#pragma data:eeprom

......

......

#pragma data:data



然后生成一个.eep文件。该文件在下载程序执行代码后,再下载到EEPROM中。具体讲就是:

1。下载HEX文件,将HEX写入AVR的FLASH中

2。下载EEP文件,将EEP写入AVR的EEPROM中



在下载EEP文件时,可以在PC的下载软件中查看EEP文件的内容,它就是你定义的数据,同时也能知道写入EEPROM中的地址。如果第二部不做的话,EEPROM中不会有你初始定义的数据。

22277 发表于 2005-4-26 14:17:23

谢谢马老师!
页: [1]
查看完整版本: 马老师,关于您的《M128上册》书上的329页