b=DQ18B20_ReadByte(); //读高8位
temp=b;
temp<<=8; //两个字节组合为1个字
temp=temp|a;
f_temp=temp*0.0625; //温度在寄存器中为12位,分辨率为0.0625
temp=f_temp*10+0.5; //乘以10表示小数点后面只取1位,加0.5是四舍五入
f_temp=f_temp+0.05;
return temp; //temp是整型
}
void distemp(uint t,uchar addr) //温度显示函数
{
uchar shi,ge,fu;
shi = t/100;
ge = (t%100)/10;
fu = ((t%100)%10);
write_com(0x80+addr);
write_dat(shi+0x30);
write_dat(ge+0x30);
write_dat('.');
write_dat(fu+0x30);
}
void main()
{// char a,b,c,d,e,f,g,h;
init_lcd();
DQ18B20_Reset();
delay(1);
DQ18B20_WriteByte(0xcc);
DQ18B20_WriteByte(0x44);
delay(200);
while(1)
{
DQ18B20_Reset();
delay(1);
DQ18B20_WriteByte(0x55); //7E00 0002 1CC1 8028
delay(1);
DQ18B20_WriteByte(0x28);
DQ18B20_WriteByte(0x80);
DQ18B20_WriteByte(0xc1);
DQ18B20_WriteByte(0x1c);
DQ18B20_WriteByte(0x02);
DQ18B20_WriteByte(0x00);
DQ18B20_WriteByte(0x00);
DQ18B20_WriteByte(0x7e);
distemp(get_temp(),0);
DQ18B20_Reset();
delay(1);
DQ18B20_WriteByte(0x55); //DB00 0001 19BB 1828
delay(1);
DQ18B20_WriteByte(0x28);
DQ18B20_WriteByte(0x18);
DQ18B20_WriteByte(0xBB);
DQ18B20_WriteByte(0x19);
DQ18B20_WriteByte(0x01);
DQ18B20_WriteByte(0x00);
DQ18B20_WriteByte(0x00);
DQ18B20_WriteByte(0xDB);
distemp(get_temp(),8);
DQ18B20_Reset();
delay(1);
DQ18B20_WriteByte(0xcc);
DQ18B20_WriteByte(0x44);
delay(200);
}
}
上一页 [1] [2] [3]
本文关键字:程序设计 电脑-单片机-自动控制,电子学习 - 基础知识 - 电脑-单片机-自动控制