资源描述:
《基于单片机的温度监测与控制系统程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.//------------------------------------------------------------------------//名称:用1602LCD与DS18B20设计的温敏报警器(含读ROMCODE,温度上下限显示)//------------------------------------------------------------------------//说明:本例将报警温度为高:70℃,低:-20℃当DS18B20感知温度达此临界//值时对应的LED闪烁,且发出警报
2、声。//本例还可以显示DS18B20的ROMCODE及报警温度上下限。//------------------------------------------------------------------------#include#include#defineucharunsignedchar#defineuintunsignedint#definedelayNOP(){_nop_();_nop_();_nop_();nop_()}sbitHI_LED=P2^3;
3、//高温,低温报警闪烁LEDsbitLO_LED=P2^6;sbitDQ=P3^3;//DS18B20数据线sbitBEEP=P3^7;//报警器sbitRS=P2^0;sbitRW=P2^1;sbitE=P2^2;sbitK1=P1^7;//正常显示温度,越界时报警sbitK2=P1^4;//显示报警温度sbitK3=P1^1;//查看ROMCODEucharcodeRomCodeStr[]={"--ROMCODE--"};ucharRomCode[8]={0x00,0x00,0x00,0x00,0x00
4、,0x00,0x00,0x00};//64位ROMCODEucharcodeTemp_Disp_Title[]={"CurrentTemp:"};ucharCurrent_Temp_Display_Buffer[]={"TEMP:"};ucharcodeTemperature_Char[8]={0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00};//温度字符ucharcodeAlarm_Temp[]={"ALARMTempHILO"};ucharAlarm_HI_LO_STR[
5、]={"HI:LO:"};uchartemp_date[2]={0x00,0x00};uchartemp_alarm[2]={0x00,0x00};uchardisplay[5]={0x00,0x00,0x00,0x00};uchardisplay1[3]={0x00,0x00,0x00};ucharcodedf_Table[]={0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9};charAlarm_Temp_HL[2]={70,-20};ucharCurrentT=0;//读取当前的温度整
6、数部分ucharTemp_Value[]={0x00,0x00};//从DS18B20读取的温度值ucharDisplay_Digit[]={0,0,0,0};bitHI_Alarm=0,LO_Alarm=0;bitDS18B20_IS_OK=1;uintTime0_Count=0;//-------------------------------------------------------...//延时//------------------------------------------------
7、-------voidDelayXus(intx){uchari;while(x--)for(i=0;i<200;i++);}bitLCD_Busy_check(){bitresult;RS=0;RW=1;E=1;DelayXus(4);result=(bit)(P0&0x80);E=0;returnresult;}//-------------------------------------------------------//向LCD发送命令//----------------------------
8、---------------------------voidWrite_LCD_Command(ucharc){while(LCD_Busy_check());//判断LCD是否忙碌RS=0;RW=0;E=0;_nop_();_nop_();P0=c;DelayXus(4);E=1;DelayXus(4);E=0;}//----------------------------------------------