51单片机测并温显示_第1页
51单片机测并温显示_第2页
51单片机测并温显示_第3页
51单片机测并温显示_第4页
51单片机测并温显示_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、要求:测当前温度,并在数码管上显示晶振 :11.0592MH程序如下:#include #define uchar unsigned char#define uint unsigned intsbit DS=P2A2;uint temp;uchar flag1;sbit dula=卩2人6;sbit wela=卩2人7;unsigned char code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;unsigned char code table1=0xbf,0x8

2、6,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef;/define interface/ variable of temperature/ sign of the result positive or negativevoid delay(uint count)uint i;while(count)/delayi=200; while(i0) i-;count-;void dsreset(void)uint i;DS=0;i=103;while(i0)i-;DS=1;i=4; while(i0)i-;/send reset and initialization

3、commandbit tmpreadbit(void)uint i;/read a bitbit dat;DS=0;i+;DS=1;i+;i+; dat=DS; i=8;while(i0)i-; return (dat);/i+ for delayuchar tmpread(void)uchar i,j,dat;dat=0;for(i=1;i=8;i+) j=tmpreadbit(); dat=(j1); / 读出的数据最低位在最前面,这样刚好一个字节在 return(dat);/read a byte dateDAT里void tmpwritebyte(uchar dat) /write a

4、 byte to ds18b20 uint i;uchar j;bit testb; for(j=1;j1;if(testb) /write 1DS=0; i+;i+;DS=1; i=8;while(i0)i-;elseDS=0;/write 0i=8;while(i0)i-; DS=1; i+;i+;/ address all drivers on bus /initiates a single temperature conversionvoid tmpchange(void)dsreset();delay(1);tmpwritebyte(0xcc); tmpwritebyte(0x44);/DS18B20 begin changeuint tmp()float tt; uchar a,b; dsreset(); delay(1);tmpwritebyte(0xcc); tmpwritebyte(0xbe);

温馨提示

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

评论

0/150

提交评论