高手帮忙看一下,这段程序里面,温度转换正确,湿度转换的时候,变量a变成负数了(正数就对了)导致湿度转换错误,什么原因啊?谢谢!
void Tem_Hum_Get(void)
{
long a; //定义一下
SHT31_Read(SHT31_R_Data,6); //读取SHT31内部温湿度数据
a = (SHT31_R_Data[0]*256)+SHT31_R_Data[1];
a = a*175;
a = a/65535; //计算温度数值(℃)
temperature = a-45; //得到温度数值(℃)
a = (SHT31_R_Data[3]*256)+SHT31_R_Data[4];
a = a*100;
a = a/65535; //计算湿度数值(%)
humidity = a; //得到温度数值(%)
}
|
@xch :谢谢!
SHT31_R_Data[3]*256+SHT31_R_Data[4]; 改成(long) SHT31_R_Data[3]*256L+(long)SHT31_R_Data[4];