DS18B20温度读取及显示讲解学习

上传人:go****e 文档编号:137378890 上传时间:2020-07-07 格式:DOC 页数:6 大小:44KB
返回 下载 相关 举报
DS18B20温度读取及显示讲解学习_第1页
第1页 / 共6页
DS18B20温度读取及显示讲解学习_第2页
第2页 / 共6页
DS18B20温度读取及显示讲解学习_第3页
第3页 / 共6页
DS18B20温度读取及显示讲解学习_第4页
第4页 / 共6页
DS18B20温度读取及显示讲解学习_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《DS18B20温度读取及显示讲解学习》由会员分享,可在线阅读,更多相关《DS18B20温度读取及显示讲解学习(6页珍藏版)》请在金锄头文库上搜索。

1、DS18B20温度读取及显示精品文档DS18B20温度读取及显示#include#define uchar unsigned char #define uint unsigned int#define wela P2#define dula P0uchar code table=0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07,0x7f,0x6f;sbit DS=P37;void delay6us(uchar z)while(z-);void delayms(uchar z)uchar i,j;for(i=0;iz;i+)for(j=0;j160;j+); vo

2、id init()uchar presence=1;while(presence) DS=0;delay6us(80);/延时480us以上DS=1;delay6us(15);if(DS=0)presence=0;while(DS=0);else presence=1;uchar ds_read()uchar byt,bi;uchar i;for(i=0;i1)|(bi7);delay6us(11);return byt;void ds_write(uchar ch)uchar i;for(i=0;i=1;void DSchange()DS=1;init();ds_write(0xcc);ds

3、_write(0x44);void DSreadtempcom()DS=1;init();ds_write(0xcc);ds_write(0xbe);uint DSreadtemp()int temp=0;uchar tmh,tml;DSchange();delayms(1);DSreadtempcom();tml=ds_read();tmh=ds_read();DS=1;temp=tmh;temp=8;temp|=tml;return temp;void display(uint wendu)uchar bai,shi,ge,sfen,bfen,qfen;uchar s,tp,th,tl;u

4、int xs,flag;flag=wendu&0x8000;if(flag!=0)wendu=(wendu-1);th=wendu/256;tl=wendu%256;s=tl&0x0f;xs=0.0625*s*1000;th=4;tp=th|tl;bai=tp/100;shi=(tp%100)/10;ge=tp%10;sfen=xs/100;bfen=(xs%100)/10;qfen=xs%10; /显示的百位十位个位以及小数点后三位wela=0;if(flag!=0)dula=0x40;/显示负号elsedula=0x00;delayms(10);wela=1;if(bai!=0)dula=tablebai;elsedula=0x00;delayms(10);wela=2;dula=tableshi;delayms(10);wela=3;dula=tablege|0x80; /加小数点delayms(10);wela=4;dula=tablesfen;delayms(10);wela=5;dula=tablebfen;delayms(10);wela=6;dula=tableqfen;delayms(10);void main()uint temp;while(1)temp=DSreadtemp();display(temp);收集于网络,如有侵权请联系管理员删除

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

当前位置:首页 > 幼儿/小学教育 > 其它小学文档

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