首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[求助]#pragma的使用方法

[求助]#pragma的使用方法

以下是我的代码,为什么不能将const byte speed=0x5a;存放到固定的FLASH中呢?
我用的单片机是 MC9S08AW16

在main.c文件中
#pragma CONST_SEG ARRAY_BUFFER
const byte speed=0x5a;
#pragma CONST_SEG DEFAULT
void main(void) {
EnableInterrupts;
for(;;) {
__RESET_WATCHDOG();
}
}
project.prm文件中
/* This is a linker parameter file for the mc9s08aw16 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
Z_RAM = READ_WRITE 0x0070 TO 0x00FF;
RAM = READ_WRITE 0x0100 TO 0x01FF;
MYRAM = READ_WRITE 0X0200 TO 0X046F;
ROM = READ_ONLY 0xC000 TO 0xDFFF;
MYROM = READ_ONLY 0XE000 TO 0XFFAF;
ROM1 = READ_ONLY 0xFFC0 TO 0xFFCB;

//FUNCTIONROM = READ_ONLY 0XFFCC TO 0XFFFB;
/* INTVECTS = READ_ONLY 0xFFCC TO 0xFFFF; Reserved for Interrupt Vectors */
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */

ARRAY_BUFFER INTO MYROM;
CODE_BUFFER INTO ROM1;
DATA_BUFFER INTO MYRAM ;
DEFAULT_RAM /* non-zero page variables */
INTO RAM;

_PRESTART, /* startup code */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
DEFAULT_ROM,

COPY /* copy down information: how to initialize variables */
INTO ROM; /* ,ROM1: To use "ROM1" as well, pass the option -OnB=b to the compiler */

_DATA_ZEROPAGE, /* zero page variables */
MY_ZEROPAGE INTO Z_RAM;
END


STACKSIZE 0x50

VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */






在程序中有没有用到这个常量?如果没有,它可能被优化掉了。也可以加一个volatile声明避免优化。
海纳百川  有容乃大
返回列表