请考虑以下代码:
unsigned int beta;
unsigned int theta;
unsigned int m = 4;
unsigned int c = 986;
unsigned int Rpre = 49900;
unsigned int getUAnalog(unsigned char channel) // to get the PT1000 Signal
{
unsigned int result;
unsigned int f_temp;
//select channel and initiate conversion
ADCSC1 |= (channel & 0b11111);
//wait until conversion is complete
while(!ADCSC1_COCO);
f_temp = ADCRH;
f_temp <<= 8;
f_temp += ADCRL;
beta = (((f_temp) / (4096*28))*1000); // warning: possible loss of data.
theta = ((((beta)*(Rpre))/(1-beta))*1000);
result = (theta-c)/(m);
return result;
}
我在 CodeWarrior 版本 5.9.0 上使用 MC9S08DZ60 ( http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08DZ60.pdf ) 和 PT1000-温度传感器。此函数用于计算温度并返回“结果”。但“beta”和“theta”值保持为 0。没有变化。
我也收到 C2705 警告:可能丢失数据。“结果”的价值是不对的。请帮助,因为我不知道出了什么问题!
提前致谢!