edx607 发表于 2013-2-5 14:18:57

51+ds18b20,读数格式怎样处理

uint ReadTemperature(void)
{
        uchar a=0;
        uint b=0;
        uint t=0;
        Init_DS18B20();
        WriteOneChar(0xCC); // 跳过读序号列号的操作
        WriteOneChar(0x44); // 启动温度转换
        delay_50us(4);
        Init_DS18B20();
        WriteOneChar(0xCC); //跳过读序号列号的操作
        WriteOneChar(0xBE); //读取温度寄存器等,前两个就是温度
        a=ReadOneChar(); //低位
        b=ReadOneChar(); //高位
        b<<=8;
        t=a+b;
        return(t);
}

temp=ReadTemperature();
DisplayTemp(temp);




以上是代码。。
怎样处理结果啊,些微十进制的?

lsy5110 发表于 2013-2-5 15:20:07

本帖最后由 lsy5110 于 2013-2-5 15:33 编辑


b<<=8;
      t=a+b;
      return(t);
、、、、、、、、、、、、、、、、、、、、、、、、、、
uchar b;就行

t=b;
t=(t<<8)|a;ort=256*b+a;

lsy5110 发表于 2013-2-5 15:23:32

t>>4就是结果,两位小数。
剩下就是除法取商取余的事了。

墨非 发表于 2013-2-5 16:49:48

LZ想要的是吧读到的数据转换成温度数据吗?

float temp = t*0.0625;
页: [1]
查看完整版本: 51+ds18b20,读数格式怎样处理