代码如下: unsigned char CalTempFromADCResult(unsigned int TempADCResult) { unsigned char CalTemp; signed int tempvalue; signed int temp2;
tempvalue=(int)(((float)TempADCResult/100.0)*((float) SystemPara.TempS)); temp2=SystemPara.TemperOffset; tempvalue-=temp2; CalTemp=(unsigned char)tempvalue; return CalTemp; } 我把SystemPara.TemperOffset付给temp2,temp2的类型和SystemPara.TemperOffset一样。SystemPara.TemperOffset的值为307, 为什么赋值给temp2,而temp2的值为51或-205,51是305的高8位全变成0,-205高8位全为1。而低8位不变。用的是C8051F413。编译器为KEIL-C。搞了一整天也看不出哪儿有错!不会是编译器问题吧! 大伙帮我看看啊!
SystemPara的声明如下 typedef struct { unsigned char Mode1; //0 unsigned char Mode2; //1 unsigned int Modset;//2,3 unsigned int APCset;// 4,5 signed int TemperOffset;//6,7 unsigned char TempS; //8 unsigned char SupplyO; //9 unsigned char VcompS; //10 unsigned char KFactorSH; //11 unsigned char KFactorSL; //12 unsigned char K2Temp; //13 unsigned int TemperV; //14,15 ADC temperature result unsigned int SupplyV; //16,17 ADC supply result unsigned int IBiasV; //18,19 ADC bias current result unsigned int Imd1V; //20, 21 ADC monitor current result unsigned int RSSIV; //22,23 ADC RSSI result unsigned char CalTemp; //24 //unsigned int Biasset; // for test
} SysPara;
|