标题:
LCD1602显示的单总线4路ds18B20温度监测系统
[打印本页]
作者:
dzdiy
时间:
2015-4-11 21:23
标题:
LCD1602显示的单总线4路ds18B20温度监测系统
本帖最后由 dzdiy 于 2015-4-11 21:42 编辑
LCD1602显示的单总线4路ds18B20温度监测系统,温度测量范围-55~125度,单片机使用的是AT89C51,测试测量结果由LCD1602进行显示,温度精确到小数点后一位。LCD1602显示的单总线4路ds18B20温度监测系统程序资料包中含有C语言源程序,仿真文件。LCD1602显示的单总线4路ds18B20温度监测系统是一个不错的多路温度监测系统。需要源程序的就自己下载LCD1602显示的单总线4路ds18B20温度监测系统程序资料,资料附后。
下载:
单总线挂接4路ds18B20温度监测系统.zip
(271.41 KB, 下载次数: 260)
2015-4-11 21:20 上传
点击文件名下载附件
下载积分: 黑币 -5
相关程序:
http://www.51hei.com/bbs/dpj-33277-1.html
部分程序源码预览(完整版本请下载本帖附件):
/*******************************************************************
**函数功能:ds18b20的驱动函数 **
**创建人:xingyuegu **
**创建日期:2006-7-12 **
**版本:1.0 **
**修改日期:2006-10-30 **
**版本:2.0 **
*******************************************************************/
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
void serial_set(void);
void process(unsigned char,unsigned char);
char volatile xiaoshu_temp[5],zhen_temp[4]; //
bit flag;
bit dot_dis=1;
sbit DQ=P1^0;
//sbit DQ=P2^3;
extern unsigned char temp[5];
/*************************************************************
**功能:延时600us **
**参数:无 **
*************************************************************/
void delay600us(void)
{
uchar i;
for(i=0;i<255;i++);
}
/*************************************************************
**功能:延时60us **
**参数:无 **
*************************************************************/
void delay60us(void)
{
uchar i;
for(i=0;i<20;i++);
}
/*************************************************************
**功能:延时18us **
**参数:无 **
*************************************************************/
/*void delay15us(void)
{
uchar i;
for(i=0;i<2;i++);
}*/
/*************************************************************
**功能:复位脉冲 **
**参数:bool **
*************************************************************/
bit resetpulse(void)
{
DQ=0;
delay600us(); //延时500us
DQ=1;
delay60us(); // 延时60us
return(DQ); //读取P1.0的状态
}
/*************************************************************
**功能:ds18b20的初始化 **
**参数:无 **
*************************************************************/
void ds18b20_init(void)
{
while(1)
{
if(!resetpulse()) //收到ds18b20的应答信号
{
//printf("reset successful!");
//delay240us(); //延时240us
DQ=1;
delay600us(); //延时240us
break;
}
else
resetpulse(); //否则再发复位信号
}
}
/*************************************************************
**功能:向ds18b20写命令 **
**参数:无 **
*************************************************************/
void ds18b20_writecommand(uchar command)
{
uchar i;
for(i=0;i<8;i++)
{
if((command & 0x01)==0)
{
DQ=0; //写0
delay60us(); //延时60us
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
DQ=1;
_nop_();
_nop_();
}
else //写1
{
DQ=0;
_nop_();
_nop_(); //延时2us
DQ=1;
delay60us(); //延时60us
_nop_();
_nop_();
_nop_();
_nop_();
}
command=_cror_(command,1); // 右移1位
}
}
/*************************************************************
**功能:读ds18b20数据 **
**参数:返回读到的数据 **
*************************************************************/
uchar ds18b20_readdata(void)
{
uchar readdata;
uchar i;
for(i=0;i<8;i++)
{
DQ=0;
_nop_();
_nop_();
_nop_();
DQ=1; //释放总线
//delay15us(); 注意不需要
if(DQ==0) //如果读到的是0
{
readdata=readdata&0x7f;
delay60us();
}
else //读到的是1
{
readdata=readdata|0x80;
delay60us();
}
if(i<7)
readdata=_cror_(readdata,1);
}
return readdata;
}
/*************************************************************
**功能:温度处理函数 **
**参数:无返回 **
*************************************************************/
void temperature_process(uchar low,uchar high)
{
uint temp1,temp2,temp3;
if(high&0x80)//判断正负
{
flag=1;
temp3=temp3|high;
temp3=temp3&0x00ff;
temp3=temp3<<8;
temp1=temp3;
temp1=temp1|low;
temp1=(temp1^0xffff);
temp1=temp1+1; //取反加1
low=temp1&0x000f;
high=temp1>>4;
process(high,low);
}
else
{
flag=0; //zhen
temp1=high;
temp2=low;
temp1=temp1<<4;
temp2=temp2>>4;
temp3=temp1|temp2;
high=temp3;
low=low&0x0f;
process(high,low);
}
}
/*************************************************************
**功能:数值处理函数 **
**参数:无返回 **
*************************************************************/
void process(unsigned char high,unsigned char low)
{
uint temp1;
uchar i;
temp1=low*625;
xiaoshu_temp[0]=temp1/1000+'0';
//xiaoshu_temp[1]=temp1/100%10+'0';
//xiaoshu_temp[2]=temp1%100/10+'0';
//xiaoshu_temp[3]=temp1%10+'0';
xiaoshu_temp[1]='\0';
dot_dis=1;
//if(xiaoshu_temp[3]=='0')
//{
// xiaoshu_temp[3]='\0';
// if(xiaoshu_temp[2]=='0')
// {
// xiaoshu_temp[2]='\0';
// if(xiaoshu_temp[1]=='0')
// {
// xiaoshu_temp[1]='\0';
if(xiaoshu_temp[0]=='0')
{
xiaoshu_temp[0]='\0';
dot_dis=0;
}
else
dot_dis=1;
// }
// }
// }
zhen_temp[0]=high/100+'0';
zhen_temp[1]=high%100/10+'0';
zhen_temp[2]=high%10+'0';
zhen_temp[3]='\0';
for(i=0;i<2;i++)
if(zhen_temp[0]=='0')
{
zhen_temp[0]=zhen_temp[1];
zhen_temp[1]=zhen_temp[2];
zhen_temp[2]='\0';
}
else
break;
}
/****************************************/
//serial_set func
void serial_set(void)
{
SCON=0x50;
TMOD=TMOD&0x0f;
TMOD=TMOD|0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
TI=1; //用PRINTF时,TI要置1
}
/*************************************************************
**功能:序列号匹配子程序 **
**参数:无返回 **
*************************************************************/
bit match_rom(uchar *rom)
{
uchar i;
ds18b20_init();
ds18b20_writecommand(0x55);
for(i=8;i>0;i--)
{
ds18b20_writecommand(*(rom+i-1));
// rom++;
}
return 1;
}
复制代码
作者:
suda
时间:
2015-7-19 12:09
怎么按照你给的电路图制作怎么检测不了啊,现在能显示 1:-0 2:-0 3:-0 4:-0 就是不能检测温度 请问你知道是什么情况吗?
作者:
爱生活,爱折腾
时间:
2015-10-26 22:27
下一个看看
作者:
爱生活,爱折腾
时间:
2015-10-26 22:37
下载的程序不对啊,没有c文件
作者:
whengfu
时间:
2015-11-8 20:54
想学习一下18B20多点测温,很少有实例,不知道有否参考价值
作者:
swim
时间:
2016-5-17 21:15
哇哇
作者:
xzs
时间:
2016-5-17 21:34
好东西啊
作者:
a1298703610
时间:
2016-5-18 15:49
谢谢分享
作者:
weichen
时间:
2017-4-5 15:20
谢谢分享
作者:
李晓冬
时间:
2017-4-10 15:22
感谢分享
作者:
琪亚娜时间到了
时间:
2018-7-10 10:11
感谢分享
作者:
xsj1877578806
时间:
2018-7-29 10:05
感谢分享,点赞
作者:
971958171
时间:
2018-12-29 13:57
程序可以运行,但是没有读取rom序列号的功能,我找了好久,加了自动搜索这个功能
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1