登录|立即注册|使用QQ帐号登录
论坛 > 24小时必答区
发帖|
看2031|回2|收藏
楼主 ID:435640 只看他
2019-4-19 21:43
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);
        }
}

沙发 ID:516781 只看他
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;
}
板凳 ID:213173 只看他
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 上传)


51黑电子论坛

Powered by Discuz! X3.1

首页|标准版|触屏版|电脑版