淮阴师范学院毕业论文
#include
BYTE code dis1[] = {\BYTE code dis2[] = {\
void DisplayInit() {
unsigned char i; lcd_pos(0); i=0;
while(dis1[i]!='\\0') {
lcd_wdat(dis1[i]); i++; }
lcd_pos(41); i=0;
while(dis2[i]!='\\0') {
lcd_wdat(dis2[i]); i++; } }
void main() {
unsigned int temp=0;
unsigned char DHT11_H,DHT11_T; Delay_ms(1000);
lcd_init(); // 初始化LCD Delay_ms(10); DisplayInit(); while(1) {
temp = Read_DHT11(); DHT11_H=temp/256;
if(DHT11_H<100)
{ lcd_pos(11); lcd_wdat(DHT11_H/10+'0');
16
淮阴师范学院毕业论文
lcd_wdat(DHT11_H+'0'); lcd_pos(0x0d); lcd_wdat('%'); lcd_pos(0x0e); lcd_wdat('R'); lcd_wdat('H'); }//if
DHT11_T=temp%6; if(DHT11_T<100) {
lcd_pos(0x4C); lcd_wdat(DHT11_T/10+'0'); lcd_pos(0x4D); lcd_wdat(DHT11_T+'0'); lcd_pos(0x4e);
lcd_wdat(0xdf); //显示℃ lcd_wdat('C'); }
Delay_ms(1000); } }
DHT11驱动程序 #include
unsigned char Read_DHT11_Byte() {
unsigned char temp,flag,Data=0,DataTemp; for(temp=0;temp<8;temp++) {
flag=2;
while((!DHT11)&&flag++);/ Delay_10us(); / Delay_10us(); Delay_10us(); DataTemp=0; if(DHT11)
DataTemp=1; flag=2;
while((DHT11)&&flag++); if(flag==1)break; Data<<=1; Data|=DataTemp;
17
淮阴师范学院毕业论文
}//for
return Data; }
unsigned int Read_DHT11() {
unsigned char flag;
unsigned char DHT11_H_H,DHT11_H_L,DHT11_T_H,DHT11_T_L,DHT11_Check;稟虛嬪赈维哜妝扩踴粜。 unsigned char DHT11_H_H_temp,DHT11_H_L_temp,DHT11_T_H_temp,DHT11_T_L_temp,DHT11_Check_temp;
陽簍埡鲑罷規呜旧岿錟。 unsigned int DHT11_H=0,DHT11_T=0,DHT11_temp=0; DHT11=0;
Delay_ms(18); DHT11=1;
Delay_10us(); Delay_10us(); Delay_10us(); Delay_10us(); DHT11=1; if(!DHT11) {
flag=2;
while((!DHT11)&&flag++); flag=2;
while((DHT11)&&flag++);
DHT11_H_H_temp=Read_DHT11_Byte(); DHT11_H_L_temp=Read_DHT11_Byte(); DHT11_T_H_temp=Read_DHT11_Byte(); DHT11_T_L_temp=Read_DHT11_Byte(); DHT11_Check_temp=Read_DHT11_Byte(); DHT11=1;
if(DHT11_Check_temp=(DHT11_H_H_temp+DHT11_H_L_temp+DHT11_T_H_temp+DHT11_T_L_temp))沩氣嘮戇苌鑿鑿槠谔應。 { DHT11_H_H=DHT11_H_H_temp; DHT11_H_L=DHT11_H_L_temp; DHT11_T_H=DHT11_T_H_temp; DHT11_T_L=DHT11_T_L_temp; DHT11_Check=DHT11_Check_temp; } }
DHT11_H=DHT11_H_H; DHT11_T=DHT11_T_H;
18
淮阴师范学院毕业论文
}
//DHT11_H=23; //DHT11_T=59;
DHT11_temp=(DHT11_H<<8)+DHT11_T; return DHT11_temp;
5 系统仿真与调试 5.1 仿真结果
进入Protues 后,根据原理图,首先找出元器件,然后将其连接好。 原理图如下图所示:
19