51单片机测并温显示_第1页
51单片机测并温显示_第2页
51单片机测并温显示_第3页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、要求:测当前温度,并在数码管上显示晶振 :11.0592MH程序如下:#include <reg52.h> #define uchar unsigned char #define uint unsigned intsbit DS=P2A2;uint temp; uchar flag1;sbit dula=P2A6; sbit wela=P2A7;/define interface/ variable of temperature/ sign of the result positive or negativeunsigned char code table=0x3f,0x06,0x

2、5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;unsigned char code table1=0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef;void delay(uint count)/delayuint i;while(count) i=200;while(i>0)i-; count-;/send reset and initialization commandvoid dsreset(void)uint i;DS=0;i=103;whil

3、e(i>0)i-;DS=1;i=4; while(i>0)i-;bit tmpreadbit(void)/read a bituint i;bit dat;DS=0;i+;/i+ for delayDS=1;i+;i+;dat=DS;i=8;while(i>0)i-;return (dat);uchar tmpread(void) /read a byte dateuchar i,j,dat;dat=0;for(i=1;i<=8;i+)DAT里 j=tmpreadbit(); dat=(j<<7)|(dat>>1); / 读出的数据最低位在最前面

4、,这样刚好一个字节在return(dat);void tmpwritebyte(uchar dat)/write a byte to ds18b20uint i;uchar j;bit testb;for(j=1;j<=8;j+) testb=dat&0x01; dat=dat>>1; if(testb)/write 1DS=0;i+;i+;DS=1;i=8;while(i>0)i-;elseDS=0; /write 0 i=8;while(i>0)i-;DS=1;i+;i+;void tmpchange(void) /DS18B20 begin chan

5、ge dsreset();delay(1);tmpwritebyte(0xcc); / address all drivers on bustmpwritebyte(0x44); / initiates a single temperature conversion uint tmp()float tt;uchar a,b;dsreset();delay(1);tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); b=tmpread();temp=b;temp<<=8; temp=temp|a; tt=temp*0.0625; t

6、emp=tt*10+0.5; return temp;void display(uint temp)uchar A1,A2,A2t,A3;A1=temp/100; A2t=temp%100;A2=A2t/10;A3=A2t%10;/get the temperature/two byte compose a int variable/ 显示程序dula=0;P0=tableA1; / 显示百位dula=1;dula=0;wela=0;P0=0x7e; wela=1;wela=0;delay(1);/ 显示十位/ 显示个位dula=0;P0=table1A2;dula=1;dula=0;wela=0;P0=0x7d;wela=1;wela=0;delay(1);P0=tableA3;dula=1;dula=0;P0=0x7b;wel

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论