数字温度计程序.doc

数字温度计程序.doc

ID:61488619

大小:21.00 KB

页数:6页

时间:2021-02-05

数字温度计程序.doc_第1页
数字温度计程序.doc_第2页
数字温度计程序.doc_第3页
数字温度计程序.doc_第4页
数字温度计程序.doc_第5页
资源描述:

《数字温度计程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、#include#defineucharunsignedchar#defineuintunsignedintsbitd1=P2^0;sbitd2=P2^1;sbitd3=P2^2;sbitd4=P2^3;sbitkey1=P3^0;sbitkey2=P3^1;sbitkey3=P3^2;sbitbeep=P3^4;sbitDS=P1^2;sbitACC_7=ACC^7;uintcount=1000,alarm=300;ucharshu;ucharshi,fen,ri,yue,nian,xq,miao,ss;uinttemp;//温度变量ucharflag;ucharcode

2、tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};ucharcodetab1[]=//小数点点亮{0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=120;y>0;y--);}voiddsreset()//发复位{uinti;DS=0;i=103;while(i>0)i--;DS=1;i=4;while(i>0)i--;}uchartmpread()//读取一字节{ucharj,k,

3、dat;uinti;for(j=1;j<=8;j++){DS=0;i++;//延时DS=1;i++;i++;k=DS;i=8;while(i>0)i--;dat=(k<<7)

4、(dat>>1);//读出的数据最低位在最前面存一个字节在DAT里}return(dat);}voidtmpwritebyte(uchardat)//写一个字节{uinti;ucharj;bittestb;for(j=1;j<=8;j++){testb=dat&0x01;dat=dat>>1;if(testb)//写1{DS=0;i++;i++;DS=1;i=8;while(i>0)i--;}else{DS=0;//写

5、0i=8;while(i>0)i--;DS=1;i++;i++;}}}voidtmpchange()//DS18B20温度变换{dsreset();delay(1);tmpwritebyte(0xcc);//跳过读取内存romtmpwritebyte(0x44);//开始转换}uinttmp()//读取温度{floattt;uchara,b;dsreset();delay(1);tmpwritebyte(0xcc);tmpwritebyte(0xbe);a=tmpread();//a为低字节8位b=tmpread();//b为高字节8位temp=b;//temp为温度值UINT16bitte

6、mp<<=8;//两个字节组合到一起temp=temp

7、a;if(b>127){flag=1;ss=flag;temp=~temp+1;}tt=temp*0.0625;//temp/16则是温度的真实值tt.7位整数,4位小数temp=tt*10+0.5;//扩大十倍取出了第一位小数return(temp);}voiddisplayTemp(uinttemp)//显示温度程序{ucharge,shi,bai,qian,ser;d1=0;d1=0;d3=0;d4=0;dsreset();ser=temp/10;//分离出三位要显示的数字SBUF=ser;qian=temp/1000;bai=t

8、emp/100%10;//百位数字shi=temp/10%10;//十位数字ge=temp%10;//个位数字if(flag==1){flag=0;P0=0xbf;d1=1;delay(2);d1=0;}if(qian!=0){P0=tab[qian];d1=1;delay(2);d1=0;}else{P0=0xff;d1=1;delay(2);d1=0;}if(temp>99){P0=tab[bai];d2=1;delay(2);d2=0;}P0=tab1[shi];d3=1;delay(2);d3=0;P0=tab[ge];d4=1;delay(2);d4=0;}uintkeyscan(

9、){if(key1==0){delay(5);if(key1==0){while(!key1);shu++;}}if(key2==0){delay(5);if(key2==0){while(!key2);count=count+10;if(shu==2){alarm+=10;}}}if(key3==0){delay(5);if(key3==0){while(!key3);count=count-10;if(s

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。