仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg52.h>
- #include<dht11.h>
- #include<1602.h>
- #include<uart.h>
- #include<adc0809.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit led1=P2^3;
- sbit led2=P2^4;
- void main()
- {
-
- adc_interrupt();
- LCD_Init(); //lcd1602初始化
- UART_Init();
- led1=1;
- led2=1;
- LCD_DrawString(0,0,"RH/T");
- while(1)
- {
- //电压值采集处理
- uchar i;
- for(i=0;i<8;i++)
- {
- ADC();//调用模数转换程序
- UART_SendString("volt");
- UART_SendNum1(1,i);
- UART_SendString(":");
- UART_SendNum1(5,volt[i]);
- UART_SendString("\r\n");
-
- }
- display();//调用显示程序
-
- if(volt[0]<35000)
- {
- led2=0;
- UART_SendString("led2:open");
- UART_SendString("\r\n");
- }else{led2=1;UART_SendString("led2:close");UART_SendString("\r\n");}
- if(volt[1]<6000)
- {
- led1=0;
- UART_SendString("led1:open");
- UART_SendString("\r\n");
- }else{led1=1;led1=1;UART_SendString("led1:close");UART_SendString("\r\n");}
-
- //温湿度处理
- DHT11_receive();
- //湿度
- LCD_SetDisplayAddress(4,0);
- LCD_DrawNum1(2,rec_dat[0]);
- LCD_DrawString(6,0,".");
- LCD_SetDisplayAddress(7,0);
- LCD_DrawNum1(2,rec_dat[1]);
- LCD_DrawString(9,0,"% ");
-
- //温度
- LCD_SetDisplayAddress(11,0);
- LCD_DrawNum1(2,rec_dat[2]);
- LCD_DrawString(13,0,".");
- LCD_SetDisplayAddress(14,0);
- LCD_DrawNum1(1,rec_dat[3]);
- LCD_DrawString(15,0,"C");
-
- UART_SendString("wendu");
- UART_SendNum1(2,rec_dat[0]);
- UART_SendString(".");
- UART_SendNum1(2,rec_dat[1]);
- UART_SendString("\r\n");
- UART_SendString("shidu");
- UART_SendNum1(2,rec_dat[2]);
- UART_SendString(".");
- UART_SendNum1(2,rec_dat[3]);
- UART_SendString("\r\n");
-
-
-
- }
- }
复制代码
所有资料51hei提供下载:
DHT11温湿度检测 8路ADC0809电压采集 串口发送采集数据 高低电压报警.zip
(198.69 KB, 下载次数: 148)
|