Board logo

标题: [求助]#pragma的使用方法 [打印本页]

作者: 183514354    时间: 2008-4-1 16:48     标题: [求助]#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. */







作者: strongchen    时间: 2008-4-2 10:21

在程序中有没有用到这个常量?如果没有,它可能被优化掉了。也可以加一个volatile声明避免优化。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0