标题:
单片机ds18b20温度计算小数如何改动程序?
[打印本页]
作者:
zhai123
时间:
2019-4-19 21:43
标题:
单片机ds18b20温度计算小数如何改动程序?
ds18b20温度转换这段程序谁能详细说明一下怎么运行的,如果我想计算小数如何改动
void temp_convert(void)
{
negetiveflag=0;
negetiveflag=temp_h&0x80;
if(negetiveflag)
{
negetiveflag=1;
temp_h=~temp_h;
if(temp_l==0)
{
temp_h++;
}
temp_l=~temp_l+1;
}
temp_h<<=4;
temp_l>>=4;
temp_over=temp_h|temp_l;
tempalarm=temp_over;
if(negetiveflag==1)
{
tempalarm=tempalarm*(-1);
}
}
作者:
yangdk
时间:
2019-4-19 22:49
int getTmpValue()
{
unsigned int tmpvalue;
int value;
float t;
unsigned char low, high;
sendReadCmd();
low = readByte();
high = readByte();
tmpvalue = high;
tmpvalue <<= 8;
tmpvalue |= low;
value = tmpvalue;
\
t = value * 0.0625;
\
value = t * 100 + (value > 0 ? 0.5 : -0.5); //大于0加0.5, 小于0减0.5
return value;
}
作者:
wulin
时间:
2019-4-20 08:37
yangdk 发表于 2019-4-19 22:49
int getTmpValue()
{
unsigned int tmpvalue;
给你一个示例程序。
ds18b20温度数码管显示+仿真.zip
(123.22 KB, 下载次数: 21)
2019-4-20 08:36 上传
点击文件名下载附件
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1