锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

DS18b20温度值换算

时间:2023-11-29 04:37:02 ds18b20温度传感器参数

DS18B20 处理正负温度值。

寄存器格式

例子

//计算温度值 //参数 高字节,低字节 double CaculateTemp(uint8_t tmh, uint8_t tml) {     uint8_t th;  uint8_t tl;  double temp = 0;   tl = tml & 0x0F;//取低字节后四位   th = (tmh << 4)   (tml >> 4)//取高字节后三位和低字节前四位    temp = (int)th;///整数部分   if (tmh > 0x08)  {   th = ~th   1;//取反加一   temp = -th;//负数  }   temp  = tl * 0.0625;//小部分   printf(" Ds18b20ReadData temp=%3.3f \n", temp);   return temp; }
CaculateTemp(0xFE,0x6F);///用表中的例子测试

结果

temp=-25.062 与表中的例子一致

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章