#region DS18b20计算温度
public float checktemp(int temp)
{
float a = 0;
try
{
if (temp < 0xfff)
{
a = temp * (float)0.0625;
}
else
{
temp = temp + 1;
a = temp * (float)(-0.0625);
}
}
catch
{
a = 0;
}
return a;
}
#endregion
温度有正负,所以上来先判断是否小于0xfff(10进制为4095),小于该值为正数温度,大于该值为负数温度。