ba_wang_mao 发表于 2007-3-26 16:52:25

ICCAVR中,如何将一个结构体数组定义到FLASH程序存储区中?

我是菜鸟,请问ICCAVR中:

 我想在FLASH程序存储区中定义一个结构体数组,存储参数的默认值、最小值、最大值、格式。

单片机上电初始化后,发现如果EEPROM中存储的数据有错误时,就将该结构体中值送到SRAM中定义

的数组set_buffer[]中,为什么编译通不过呢?



struct FORMAT_STRUCT

{

    unsigned char decimal;                //        格式

    int max;                        //        最大值

    int min;                        //        最小值

    init_num;                           //         初始值

};



//定义在FLASH

flash struct FORMAT_STRUCT Para1_Format={

           {0x80,9999,0,0},        //        A{格式,最大值,最小值}

           {0x80,9999,0,0},        //         B{格式,最大值,最小值}

           {0x80,9999,0,100},};//       C{格式,最大值,最小值}



// 定义在SRAM  

int set_buffer;   





void Init(void)

{

   struct FORMAT_STRUCT *PTR;

   int i;



   for (i=0;i<3;i++)

   {

      set_buffer = PTR->init_num;

      PTR++;

    }

joson 发表于 2007-3-26 17:20:13

关注中。

fsclub 发表于 2007-3-26 17:51:16

加CONST关键字.

ba_wang_mao 发表于 2007-3-27 11:15:55

不行呀!

(1)如果加上const ,即 struct FORMAT_STRUCT const Para1_Format;

则编译器出现如下错误

 operands of = have illegal types `pointer to struct FORMAT_STRUCT' and `pointer to const struct FORMAT_STRUCT'

(2)如果加关键字flash,即 flash struct FORMAT_STRUCT Para1_Format

则编译器出现如下错误

 operands of = have illegal types `pointer to struct FORMAT_STRUCT' and `pointer to const struct FORMAT_STRUCT'

(3)如果什么关键字都不加,即 struct FORMAT_STRUCT const Para1_Format

则编译器出现如下错误

 warning: COFF no struct tag 'FORMAT_STRUCT' found for symbol index 494

ddaitt999 发表于 2009-7-17 08:57:44

顶一下!!我也遇到同样的问题,期待高人指点

luy3728000 发表于 2010-4-16 17:29:16

IAR上可以 这样定义 struct FORMAT_STRUCT const Para1_Format;

shark 发表于 2010-4-16 17:44:00

你程序中的PTR是个wildpointer,以下ICC7.16A编译通过。
struct FORMAT_STRUCT
{
    unsigned char decimal; // 格式
    int max; // 最大值
    int min; // 最小值
    int init_num;                           //         初始值
};

//定义在FLASH
__flash struct FORMAT_STRUCT Para1_Format={
   {0x80,9999,0,0}, // A{格式,最大值,最小值}
   {0x80,9999,0,0}, //B{格式,最大值,最小值}
   {0x80,9999,0,100},};//       C{格式,最大值,最小值}

// 定义在SRAM  
int set_buffer;   


void Init(void)
{
   struct FORMAT_STRUCT __flash *PTR = Para1_Format;
   int i;

   for (i=0;i<3;i++)
   {
      set_buffer = PTR->init_num;
      PTR++;
   }
}
int main(){
    Init();
    for(;;);
    return 0;
}

z382570793 发表于 2011-3-1 15:05:05

在定义结构体是就将他定义到程序存储区
const struct FORMAT_STRUCT
{
    unsigned char decimal;       //        格式
    int max;       //        最大值
    int min;       //        最小值
    init_num;                           //         初始值
};

perfection 发表于 2011-4-24 23:54:46

mark

zhuhuanwu163 发表于 2013-7-18 10:11:55

用__flash 或者将complier 中的标签页打勾Treat 'const' as '__flash' (backword compatibility),意思是支持'const' 作为 '__flash'使用

sky@215574023 发表于 2014-2-18 15:32:31

数组要挨个元素赋值!
页: [1]
查看完整版本: ICCAVR中,如何将一个结构体数组定义到FLASH程序存储区中?