基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)

上传人:马*** 文档编号:143951625 上传时间:2022-08-26 格式:DOCX 页数:17 大小:28.32KB
收藏 版权申诉 举报 下载
基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)_第1页
第1页 / 共17页
基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)_第2页
第2页 / 共17页
基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)_第3页
第3页 / 共17页
资源描述:

《基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)》由会员分享,可在线阅读,更多相关《基于单片机的数字温度计c程序(Microcontroller based digital thermometer C program)(17页珍藏版)》请在装配图网上搜索。

1、基于单片机的数字温度计c程序(MicrocontrollerbaseddigitalthermometerCprogram)#包括reg52。”#包括信息。”#定义unsignedchar函数#unsignedint定义单元#定义delaynop()_nop_();_nop_();_nop_();_nop_();公司DQP22;普通双=P26;/定义锁存器锁存端普通焊接=P27;普通RS=P35;/定义1602液晶RS端公司lcden=P34;/定义1602液晶lcden端P3了S1=0;/定义按键-功能键公司S2=P31;/定义按键-增加键P3了S3=2;/定义按键-减小键P3了S4=6;/

2、闹钟查看键P3了RD=7;普通哔=P23;/定义蜂鸣器端函数代码temp_disp_title=“当前温度:“;函数current_temp_display_buffer=“临时”;函数代码alarm_temp=“报警温度高低”;函数alarm_hi_lo_str=“嗨:Lo:“;函数temp_data2=0x00,0x00;函数temp_alarm2=0x00,0x00;函数显示5=0x00,0x00,0x00,0x00,0x00;函数显示3=0x00,0x00,0x00;函数代码df_table=0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9;函数,=0;/当前读取的温度整

3、数部分函数temp_value=0x00,0x00;/从DS18B20读取的温度值函数display_digit=0,0,0,0;/待显示的各温度数位点ds18b20_is_ok=1;/传感器正常标志/-延时/1/-无效的极限(个X)我的函数;当(x)为(i0;i200;i+);/-延时/2/-虚空Delay(个X)(x);/-/忙检查/-无效write_com(UCHARCOM)/液晶写命令函数RS0;lcden=0;P0=COM;极限(5);lcden=1;极限(5);lcden=0;write_lcd_data(void函数日期)/液晶写数据函数RS1;lcden=0;P0=日期;极限(

4、5);lcden=1;极限(5);lcden=0;/-/设置液晶显示位置/-无效set_disp_pos(ucharPos)write_com(POS|0x80);/-/液晶初始化/-无效initialize_lcd()函数数;RD=0;/软件将矩阵按键第4列一端置低用以分解出独立按键班杜拉=0;/关闭两锁存器锁存端,防止操作液晶时数码管会出乱码维拉=0;lcden=0;write_com(0X38);/初始化1602液晶write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);/设置显示初始坐标对于(num=0;数14;数

5、+)/显示年月日星期write_lcd_data(temp_disp_title民);极限(5);/-/函数功能:初始化DS18B20/出口参数:现状DS18B20是否复位成功的标志/-init_ds18b20()函数函数的状态;/储存DS18B20是否存在的标志,状态=0,表示存在;状态=1,表示不存在DQ1;Delay(8);/6微秒略微延时约先将数据线拉高DQ0;Delay(90);/再将数据线从高拉低,要求保持480960us600/略微延时约微秒以向DS18B20发出一持续480960us的低电平复位脉冲DQ1;Delay(8);/释放数据线(将数据线拉高)/延时约30us(释放总线

6、后需等待1560us让DS18B20输出存在脉冲)状态=DQ;Delay(100);Todetectwhethertheoutputofthemicrocontroller/presencepulse(DQ=0saidtherewasenoughlongtimedelay)/,waitingfortheexistenceofoutputpulse.DQ=1;/datalinespulledReturnstatus;/returntestsuccess/-/function:readabyteExportparameters:dat-/readdata/-Uchar,ReadOneByte()U

7、char,I,dat=0;DQ=1;(_nop_);/thefirstdatalineup/waitforamachinecycleFor(i=0;i=1;(_nop_);/waitforamachinecycleDQ=1;/datalineartificialpullup,readyforthedetectionofDS18B20MCUoutputlevel_nop_(_nop_);();/delayofabout6us,sothatthehostsamplingin15USIf(DQdat|=0x80);/ifthereaddatais1,willbe1inDAT,ifthe0willre

8、maintheoriginalvalueunchanged.Delay(30);/3usdelay,theremustbemorethan1USoftherecoveryperiodbetweentworeadtimingDQ=1;/datalinespulled,readyforthenextdatareadReturndat;/-/function:writeabyteEntranceparameters:dat-/datatobewritten/-VoidWriteOneByte(ucharDAT)Uchari;For(i=0;i=1;/datinthe1bitbinarydata./-

9、/function:readthetemperaturevalueEntranceparameters:/-Void,Read_Temperature()If(Init_DS18B20)(/DS18B20=1)faultDS18B20_IS_OK=0;ElseWriteOneByte(0xCC);/readserialnumbercolumnnumberoperationskipWriteOneByte(0x44);/converttemperature(Init_DS18B20);/initializeDS18B20WriteOneByte(0xCC);/readserialnumberco

10、lumnnumberoperationskipWriteOneByte(0xBE);/readthetemperatureregister,thefirsttwoarelowandhightemperatureTemp_Value0=ReadOneByte(8);/lowtemperatureTemp_Value1=ReadOneByte(hightemperature);/8DS18B20_IS_OK=1;/-/function:displaythecurrenttemperatureinLCD/entranceparameters:/-Void,Display_Temperature()U

11、chari;/delayvalueandnegativeidentificationUchar,t=150,ng=0;5all1/high(0xF8)isnegative,negativecounterplus1,andsetthenegativesignIf(Temp_Value1&0xF8)=0xF8)Temp_Value1=Temp_Value1;Temp_Value0=Temp_Value0+1;If(Temp_Value0=0x00Temp_Value1+);/plus1ifthelowbyteis00bitsthatcarry,thenaddedtothehighbyteNg=1;

12、/the1negativesignDisplay_Digit0=df_TableTemp_Value0&0x0F;/findthedecimalparttemperature/getthetemperature(highbyteintegerpartofthelower3andthelowbyteinthehigh4bitunsigned)CurrentT=(Temp_Value0&0xF0)(4)|(Temp_Value1&0x07)4);/integerpartisdecomposedinto3bitdigitaltodisplayDisplay_Digit3=CurrentT/100;/

13、100digitCurrentT/100;Display_Digit2=CurrentT%100/10;/tenDisplay_Digit1=CurrentT%10;/A/LCDdisplayrefreshbufferCurrent_Temp_Display_Buffer11=Display_Digit0+0;/thefirst0willbeconvertedintotheinteger48,thenaddthedigitalfront,GetstheASCIIcharacterofthecorrespondingnumberCurrent_Temp_Display_Buffer10=.;Cu

14、rrent_Temp_Display_Buffer9=Display_Digit1+0;/ACurrent_Temp_Display_Buffer8=Display_Digit2+0;/tenCurrent_Temp_Display_Buffer7=Display_Digit3+0;/100Nottodisplay0/highIf(Display_Digit3=0)Current_Temp_Display_Buffer7=;Forthe0timeandhigh/high0times,donotshowhighIf(Display_Digit2=0andDisplay_Digit3=0)Curr

15、ent_Temp_Display_Buffer8=;/negativesymbolsaredisplayedintherightpositionIf(NG)If(Current_Temp_Display_Buffer8=)Current_Temp_Display_Buffer8=-;Elseif(Current_Temp_Display_Buffer7=)Current_Temp_Display_Buffer7=-;ElseCurrent_Temp_Display_Buffer6=-;/inthefirstrowshowtitleSet_Disp_Pos(0x00);For(i=0;i16;i

16、+)Write_LCD_Data(Temp_Disp_Titlei);Set_Disp_Pos(0x40);/inthesecondlineshowsthecurrenttemperatureFor(i=0;i16;i+)Write_LCD_Data(Current_Temp_Display_Bufferi);/temperaturedisplaysymbols/Set_Disp_Pos(0x4D);Write_LCD_Data(0x00);Set_Disp_Pos(0x4D);Write_LCD_Data(0xdf);Set_Disp_Pos(0x4E);Write_LCD_Data(C);/-/function:themainfunction/entranceparameters:/-Void,main()Initialize_LCD();Read_Temperature();Delay(50000);Delay(50000);While(1)Read_Temperature();If(DS18B20_IS_OK)Display_Temperature();Delay1(100);

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!