新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > AT89C52控制温度传感器DS18B20并在LM016L_LCD上显示

AT89C52控制温度传感器DS18B20并在LM016L_LCD上显示

作者:时间:2018-07-24来源:网络收藏

{
tempt=0;
i++;//延时
tempt=1;
i=8;//延时
while(i>0)i--;
}
else
{
tempt=0;
i=8;//延时
while(i>0)i--;
tempt=1;
i++;//延时
i++;
}
}
}

本文引用地址:http://www.eepw.com.cn/article/201807/383597.htm


//----------------------------------------
//函 数 名:convert_tempt()
//函数类型:void
//入口参数:None
//出口参数:None
//说明:开始获取温度,并进行转换
//----------------------------------------
void convert_tempt()
{
reset_tempt();//初始化
delay(1);
write_byte(0xcc);//跳过序列号读取
write_byte(0x44);//温度转换
}

//----------------------------------------
//函 数 名:get_tempt
//函数类型:uint
//入口参数:None
//出口参数:u_temp
//说明:获取寄存器中的温度数据
//----------------------------------------
uint get_tempt()
{
uchar a,b;//低位和高位
reset_tempt();
delay(1);
write_byte(0xcc);
write_byte(0xbe);//写入
//读数据命令

a=read_tempt();
b=read_tempt();//读取值暂存
u_temp=b;
u_temp=8;
u_temp|=a;//数据处理问题
//u_temp=u_temp/a;
f_temp=u_temp*0.0625;//精度为12位,所以分辨率为0.0625
u_temp=f_temp*10;//乘以10,将实际温度扩大10倍

return u_temp;//返回的u_temp是整型数据
}


//----------------------------------------
//函 数 名:display()
//函数类型:void
//入口参数:None
//出口参数:None
//说明:显示控制函数
//----------------------------------------
void display()
{
uchar i,j;
write_com(0x80+3);
for(i=0;i10;i++)
{
write_data(disp2[i]);
}
write_com(0x80+0x40+10);
for(j=0;j2;j++)
{
write_data(disp3[j]);//单位显示控制
}
}



评论


相关推荐

技术专区

关闭