DS18B20与数码管温度显示C程序

上传人:大米 文档编号:497922843 上传时间:2022-08-25 格式:DOC 页数:6 大小:18KB
返回 下载 相关 举报
DS18B20与数码管温度显示C程序_第1页
第1页 / 共6页
DS18B20与数码管温度显示C程序_第2页
第2页 / 共6页
DS18B20与数码管温度显示C程序_第3页
第3页 / 共6页
DS18B20与数码管温度显示C程序_第4页
第4页 / 共6页
DS18B20与数码管温度显示C程序_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《DS18B20与数码管温度显示C程序》由会员分享,可在线阅读,更多相关《DS18B20与数码管温度显示C程序(6页珍藏版)》请在金锄头文库上搜索。

1、#icldereg52h#define uch nsig cadefie int usigned intsbi DQ=1;/d180与单片机连接口unsigned hr cde str=0x3f,0x06,x5b,0x4f,0x6,0x,0x7d,x,xf,f,0x3;/共阴数码管字码表unsinedcharcoe r10x0bf,08,0db,xcf,0xe6,x0,00,0x87,0f,x0ef,0x39;/个位带小数点字码表unigd cod wi00f,x0d,0x0b,0xf7;ucrdata disdata5;uinttvaue;/温度值uchar tfag;/温度正负标志/*ds

2、12程序*void deay8B20(unsiged int i)/延时1微秒 while(i-);od s180()/*s1820复位/ usid h x=0;DQ ; /D复位dea_18B0(4); /延时D =0; /拉低dey_B20(100); /精确延时不小于80usDQ = ; /拉高elay_820(40); cha ds820rd()/读数据*unsignedcr i0;usignd chrdat = ;for (i=8;i;) D = 0; /给脉冲信号 d1; DQ=1; /给脉冲信号 if(D) da|=0x0; delay_18B0(10); return(dat)

3、;vi s1820r(uchr wdata)/*写数据*unsignechri0; for (i=8;i; -) DQ =; Q = dat&0x01; elay_18B20(); DQ = 1; wdata=1; read_temp()/读取温度值并转换*/uchar ,b;ds1rst();d180wr(0cc);/*跳过读序列号*/s820wr(0x4);/*启动温度转换*/s18rt();s10wr(0xc);/*跳过读序列号*/ds1820r(xbe);/*读取温度/=ds180rd();b=s180d();valu=b;tvaue=8;tval=tvalue|a; if(tvalu

4、e00f) tflag=; else tvalu=tlue+;tflag=1; tale=tvalue*(0.62);/温度值扩大1倍,精确到位小数rtun(tvale);/*/ odds820ip()/温度值显示 uchar flagt; uchar i; didata0=taue/1000;/百位数 isata1=tvalue%1000/00;十位数 disdata2=tvlue%1001;/个位数 isdata3=tva%;/小数位 i(tfla0) fagd00;/正温度不显示符号 lse flagdat=02d;/负温度显示负号: i(disdata0=0x3) disdta0=020;/如果百位为,不显示 if(idata1=00) disdata1=020;/如果百位为0,十位为也不显示 for(i=0;150;i+) P2ei; 0=stdisda3; delay_1B20(20); 2ei; =st1isdat2; elay_18B20(0);=wei2; P0=strdsaa1; dela18B20(20); P2=ei3; P0=strdsdat; dlay_B20(20); /*主程序*oidmai() ds1820rs;初始化显示 wil(1)ra_emp();/读取温度 s1disp();/显示

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号