HCS08运行不稳定,极易出错?

2019-03-26 08:07发布

1 临时变量或非直接页内存的全局变量经常不起作用,赋值赋不进,换成zero_ram区的全局变量就OK了; 2 临时变量或非直接页内存的全局变量容易引起程序出错,换成zero_ram区的全局变量就OK了; 3 有浮点运算时出错率大增; 4 有中断函数时出错率增加;   如: 程序写法一:(会出错,Table_test算出的常是完全不对的值;或者每次算出的值不一样,会有微小跳动) void Cal_Test(float *Table_test)                                                                    
{                                                                                       
        unsigned char i=0;          for(i=0;i<100;i++)         {                  Table_test+=0.0045*i+123.456;         }                                                                      
}                                                                               
程序写法二:(会出错,Table_test算出的常是完全不对的值;或者每次算出的值不一样,会有微小跳动) #pragma DATA_SEG DEFAULT volatile unsigned char i=0;  void Cal_Test(float *Table_test)                                                                    
{                                                                                       
        for(i=0;i<100;i++)         {                  Table_test+=0.0045*i+123.456;         }                                                                      
}  程序写法三:(能得到正确结果) #pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE     //开始 0 页数据定义
volatile unsigned char i=0;  void Cal_Test(float *Table_test)                                                                    
{                                                                                       
        for(i=0;i<100;i++)         {                  Table_test+=0.0045*i+123.456;         }                                                                      
}                                                                                
单片机:mc9s08qe4/8 编译环境:freescale codewarrior v6.2 试用版(破解版) 不知各位有没出现类似情况,这是MCU就这水平,还是编译器设置问题,还是编译器有问题? 1 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。