定义一个联合体:
typedef union FACTORY_TEST
{
uint16_t All[4];
struct
{
uint16_t IQ_FullScale_Hz;
uint16_t IQ_FullScale_V;
uint16_t ADC_FullScale_V1; //1V为单位
uint16_t ADC_FullScale_V2; //1V为单位
}code;
}FACTORYT;
FACTORYT FactoryTest
FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;
_iq Value_Mb = (_iq)(FactoryTest.code.IQ_FullScale_V);
_iq Value_Ma = (_iq)(FactoryTest.code.ADC_FullScale_V1);
float_t V_a = (float_t)(Value_Ma);
float_t V_b = (float_t)(Value_Mb);
float_t Value = V_a/V_b;
运行后显示:Value = 160.0;
显然结果不是期望的·Value = 1.0
不用联合,直接用结构:
typedef struct FACTORY_TEST
{
uint16_t IQ_FullScale_Hz;
uint16_t IQ_FullScale_V;
uint16_t ADC_FullScale_V1; //1V为单位
uint16_t ADC_FullScale_V2; //1V为单位
}FACTORYT;
FACTORYT FactoryTest
FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;
_iq Value_Mb = (_iq)(FactoryTest.IQ_FullScale_V);
_iq Value_Ma = (_iq)(FactoryTest.ADC_FullScale_V1);
float_t V_a = (float_t)(Value_Ma);
float_t V_b = (float_t)(Value_Mb);
float_t Value = V_a/V_b;
运行后显示:Value = 1..0;
是期望的结果。
CCS 为6.2,编译器为c2000_15.12.3.LTS
dsp为 F28069M
出现这一问题的原因是什么?是否是CCS自身编译器的问题? |