1、.#include #define uint unsigned int#define uchar unsigned charsbit io=P10;/DHT11数据端sbit wela=P27;/数码管位选sbit dula=P26;/数码管段选uchar data_byte;uchar RH,RL,TH,TL;uchar table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98; uchar wei=0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80; void delay(uchar z)uchar x,y;
2、for(x=z;x0;x-)for(y=110;y0;y-);void delay1()/ 延时 10usuchar i;i-;i-;i-;i-;i-;i-;void start()/开始信号io=1;.delay1();io=0;delay(20);/18msio=1;delay1();/20-40usdelay1();delay1();delay1();delay1();uchar receive_byte()uchar i,temp,count;for(i=0;i8;i+)count=2;while(!io)&count+)/等待 50us 低电平结束temp=0;delay1();de
3、lay1();delay1();delay1();if(io=1)temp=1;count=2;while(io)&count+);if(count=1)break;data_byte=1;data_byte|=temp;return data_byte;void receive().uchar T_H,T_L,R_H,R_L,check,num_check;uchar count;start();/开始信号io=1;if(!io)/ 读取 DHT11 响应信号count=2;while(!io)&count+);/DHT11高电平 80us 是否结束count=2;while(io)&cou
4、nt+);R_H=receive_byte();R_L=receive_byte();T_H=receive_byte();T_L=receive_byte();check=receive_byte();io=0;/ 拉低延时 50usdelay1();delay1();delay1();delay1();delay1();io=1;num_check=R_H+R_L+T_H+T_L;if(num_check=check)RH=R_H;RL=R_L;TH=T_H;TL=T_L;check=num_check;.void display(uchar i,uchar j)/数码管显示P0=weii;wela=1;wela=0;P0=0xff;P0=tablej/10;dula=1;dula=0;delay(1);P0=0xff;P0=weii+1;wela=1;wela=0;P0=0xff;P0=tablej%10;dula=1;dula=0;delay(1);void main()while(1)receive();display(0,RH);delay(1);display(2,TH);delay(1);./ display(4,TH);/ delay(1);/ display(6,TL);/ delay(1);.