单片机源程序如下:
#include //////////////////////////////////////////////////////////////////////////// void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str); void ConfigTimer0(unsigned int ms); unsigned char IntToString(unsigned char *str, int dat); extern bit Start18B20(); extern bit Get18B20Temp(int *temp); extern void InitLcd1602(); bit DHT_Start(); void aj (void); bit DHT_ByteRead(unsigned char *dat); ///////////////////////////////////////////////////////////////////// sbit K1=P1^4; ///引脚声明 sbit K2=P1^5; sbit K3=P1^6; sbit K4=P1^7; sbit M1=P1^0; sbit M2=P1^1; sbit M3=P1^2; sbit M4=P1^3; sbit D1=P2^7; sbit D2=P2^6; sbit KD1=P2^3; sbit KD2=P2^4; ///////////////// ///////////////////////////// 数组命名 int SD,WD,x,xx,SDC,WDC,PWM1,PWM2; int KK1,KK2; int wdg=40,wdd=20,sdg=80,sdd=60; bit SZ,JB; bit flag1s = 0; //1s定时标志 unsigned char T0RH = 0; //T0重载值的高字节 unsigned char T0RL = 0; //T0重载值的低字节 ///////////////////////////////// 延时子程序 void delay () { x=99999; while(x--); } ///////////////////////////////// void main() ////////////////主程序 { bit tmp; unsigned char str[12]; unsigned char DHT[5]; ////初始化/////////////////////// EA = 1; //开总中断 ConfigTimer0(10); //T0定时10ms InitLcd1602(); //初始化液晶 M1=0; M1=0;M2=0;M3=0;D1=0;D2=0; //////////////////////////////////// DHT_Start(); delay(); delay(); delay(); delay(); while (1) { LcdShowStr(0, 0, "WD"); //显示到液晶屏上 LcdShowStr(0, 1, "SD"); //显示到液晶屏上 LcdShowStr(5, 0, "H"); //显示到液晶屏上 LcdShowStr(5, 1, "H"); //显示到液晶屏上 LcdShowStr(9, 0, "L"); //显示到液晶屏上 LcdShowStr(9, 1, "L"); //显示到液晶屏上 if (flag1s) //每秒更新一次温度 { str[0] = (wdg/10)%10 + '0'; //十位转为ASCII码 str[1] = (wdg%10) + '0'; //个位转为ASCII str[2] = '