1、uchar i;i-;void Delay2(uchar ms) / 延时子程序 uchar i ; while(ms-) for(i = 0 ; i0;delay-) for(i=123;ii-); void delay(uint z)for(x=z;xx-) for(y=110;yy-);void write_com(uchar com)lcdrs=0;lcdrw=0;P0=com;delay(5);lcden=1;lcden=0;void init()write_com(0x38); write_com(0x0c); write_com(0x06);write_com(0x01); wr
2、ite_com(0x80); void write_data(uchar dat)lcdrs=1;P0=dat;void start(void)/开始信号DHT11_IO=1;Delay1();DHT11_IO=0;Delay2(20);/18ms/20-40usuchar receive_byte(void)/接收一个字节uchar i,temp,count,data_byte;for(i=0;i8;i+)while(!DHT11_IO);/等待50us低电平结束temp=0;Delay1();Delay1();if(DHT11_IO=1)temp=1;while(DHT11_IO);dat
3、a_byte=1;data_byte|=temp;return data_byte;void receive()/接收数据uchar check,num_check,HZ,HX,WZ,WX;start();/开始信号if(!DHT11_IO)/读取DHT11响应信号/DHT11高电平80us是否结束HZ = receive_byte();HX = receive_byte();WZ = receive_byte();WX = receive_byte();check = receive_byte();DHT11_IO=0;/拉低延时50usDHT11_IO=1;num_check = HZ +
4、 HX + WZ + WX;if(num_check = check)check = num_check;write_data(tableHZ/10);write_data(tableHZ%10);write_data(.);write_data(tableHX/10);write_data(tableHX%10); write_data(RH%/write_com(0x80+0x40);/write_data(tableWZ/10);/write_data(tableWZ%10);/write_data(/write_data(tableWX/10);/write_data(tableWX%10);/ write_data(Tvoid main() init();while(1) receive();