|
以下是我读18b20的程序:
float get_temp()
{
uchar a,b,c;
uint temp;
Init18B20();
delay(1);
tempwritebyte(0xcc);//写跳过ROM指令
tempwritebyte(0xbe);//读暂存器指令
a=tempread();//低8位
b=tempread();//高8位
temp=b;
temp=(temp<<8)|a;//两字节合并为一字节
c=b>>4;
if(c&0x0f==0)
temp_f=temp*0.0625;//温度为正
else
temp=~temp+1; //温度为负
temp_f=temp*0.0625;
return temp_f;
}
我希望能够测零下的温度。液晶显示为0.1度,请高手指点!
|
|