27,508
社区成员




int Read_tem()
{
uint t;
uchar a,b;
DS18B20();
delay(1);
Write(0xcc); //跳过
Write(0x44); //温度转换
DS18B20();
delay(1);
Write(0xcc); //跳过
Write(0xbe); //读温度寄存器
a=Read(); //低八位
b=Read(); //高八位
t=b;
t<<=8; //左移
t=t|a;
return t;
}
uint tem_change()
{
float tp;
tem=Read_tem();
if(tem<0)
{
tem=tem-1;
tem=~tem;
tp=tem*0.0625;
tem=tp*10+0.5;
return 1;
}
else
{
tp=tem*0.0625;
tem=tp*10+0.5;
return 0;
}
}
void display_tempt(uint x)
{
uchar i,j,k;
i=tem/100;
j=tem%100/10;
k=tem%100%10;
if(x) //x=1温度为负
{
write_com(0xc0+5);
write_data('-');
}
else
{
write_com(0xc0+6);
}
write_data(disp[i]);
write_data(disp[j]);
write_data('.');
write_data(disp[k]);
if(tem<100)
{
BUZ=1;
}
if(tem>=100)
{
BUZ=0;
}
}