18b20温度测量

18b20温度测量

ID:40659307

大小:135.50 KB

页数:5页

时间:2019-08-05

18b20温度测量_第1页
18b20温度测量_第2页
18b20温度测量_第3页
18b20温度测量_第4页
18b20温度测量_第5页
资源描述:

《18b20温度测量》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#defineucharunsignedchar#defineuintunsignedintsbitDQ=P3^6;sbitBEEP=P3^7;sbitHI_LED=P1^4;sbitLO_LED=P1^5;ucharcodeDSY_CODE[]={0x3f,0x06,0x5b,0X4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};ucharcodedf_Table[]={0,1,1,2,3,3,

2、4,4,5,6,6,7,8,8,9,9};charAlarm_Temp_HL[2]={70,-20};ucharCurrentT=0;ucharTemp_Value[]={0x00,0x00};ucharDisplay_Digit[]={0,0,0,0};bitHI_Alarm=0,LO_Alarm=0;bitDS18B20_IS_OK=1;uintTime0_Count=0;voiddelay(uintx){while(--x);}ucharInit_DS18B20(){ucharstatus

3、;DQ=1;delay(8);DQ=0;delay(90);DQ=1;delay(8);status=DQ;delay(100);DQ=1;returnstatus;}ucharReadonebyte(){uchari,dat=0;DQ=1;_nop_();for(i=0;i<8;i++){DQ=0;dat>>=1;DQ=1;_nop_();_nop_();if(DQ)dat

4、=0x80;delay(30);DQ=1;}returndat;}voidwriteonebyte(uchardat){

5、uchari;for(i=0;i<8;i++){DQ=0;DQ=dat&0x01;delay(5);DQ=1;dat>>=1;}}voidRead_Temperature(){if(Init_DS18B20()==1)DS18B20_IS_OK=0;else{writeonebyte(0xcc);writeonebyte(0x44);Init_DS18B20();writeonebyte(0xcc);writeonebyte(0xbe);Temp_Value[0]=Readonebyte();T

6、emp_Value[1]=Readonebyte();Alarm_Temp_HL[0]=Readonebyte();Alarm_Temp_HL[1]=Readonebyte();DS18B20_IS_OK=1;}}voidSet_Alarm_Temp_Value(){Init_DS18B20();writeonebyte(0xcc);writeonebyte(0x4e);writeonebyte(Alarm_Temp_HL[0]);writeonebyte(Alarm_Temp_HL[1]);w

7、riteonebyte(0x7f);Init_DS18B20();writeonebyte(0xcc);writeonebyte(0x48);}voidDisplay_Temperature(){uchari;uchart=150;ucharng=0,np=0;charSigned_Current_Temp;if((Temp_Value[1]&0xf8)==0xf8){Temp_Value[1]=~Temp_Value[1];Temp_Value[0]=~Temp_Value[0]+1;if(T

8、emp_Value[0]==0x00)Temp_Value[1]++;ng=1;np=0xfd;}Display_Digit[0]=df_Table[Temp_Value[0]&0x0f];CurrentT=((Temp_Value[0]&0xf0)>>4)

9、((Temp_Value[1]&0x07)<<4);Signed_Current_Temp=ng?-CurrentT:CurrentT;HI_Alarm=Signed_Current_Temp>=Alarm_Temp_HL[0]?1:0;L

10、O_Alarm=Signed_Current_Temp<=Alarm_Temp_HL[1]?1:0;Display_Digit[3]=CurrentT/100;Display_Digit[2]=CurrentT%100/10;Display_Digit[1]=CurrentT%10;if(Display_Digit[3]==0){Display_Digit[3]=10;np=0xfb;if(Display_Digit[2]==0){Display_Digit[2]=10;np=0xf7;}}fo

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

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

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