|
发表于 2011-6-13 23:09:11
|
显示全部楼层
1。首先应该看CVAVR的HELP,里面什么都有,如果你不看,或者看不懂,那么说明你还不具备“高手”的特质和能力
2。通过这个例子,也可以证明,一般的人应该使用CVAVR,相对比ICC、GCC、IAR等使用方便些,容易掌握和使用。当然你要考虑移植性什么的,另做讨论。不过,对于面向硬件低层的东西,那个软件都谈不上移植性好。比如,数组定义在FLASH中,标准C中是没有的,但你会发现CVAVR用起来方便。
下面是CVAVR中的说明,应该对LZ有帮助的。
The flash or __flash keywords can be used to specify that a constant must be placed in FLASH memory, no matter what is the state of the Store Global Constants in FLASH Memory option:
flash <type definition> <identifier> = constant expression;
__flash <type definition> <identifier> = constant expression;
Example:
flash int integer_constant=1234+5;
flash char char_constant='a';
flash long long_int_constant1=99L;
flash long long_int_constant2=0x10000000;
flash int integer_array1[]={1,2,3};
flash char string_constant1[]="This is a string constant located in FLASH";
The constant literal char strings, enclosed in double quotation marks, that are passed as function arguments, are stored in the memory type pointed by the pointer used as function parameter.
Example:
/* This function displays a string located in RAM. */
void display_ram(char *s) {
/* ....... */
}
/* This function displays a string located in FLASH. */
void display_flash(flash char *s) {
/* ....... */
}
/* This function displays a string located in EEPROM. */
void display_eeprom(eeprom char *s) {
/* ....... */
}
void main(void) {
/* The literal string "Hello world" will be placed
by the compiler in FLASH memory and copied at program
startup to RAM, so it can be accessed by the pointer
to RAM used as function parameter.
The code efficiency is low, because both FLASH and
RAM memories are used for the string storage. */
display_ram("Hello world");
/* The literal string "Hello world" will be placed
by the compiler in FLASH memory only, good code
efficiency beeing achieved. */
display_flash("Hello world");
/* The literal string "Hello world" will be placed
by the compiler in EEPROM memory only.
The code efficiency is very good because no
FLASH memory will be allocated for the string. */
display_eeprom("Hello world");
while (1);
} |
|