#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DT=P1^0;
int cod[5];
uchar duan[]={0xfe,0xfd,0xfb,0xf7,0xdf,0xbf};
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar DHT11_send();
void DHT11_Delay_10us()
{
unsigned char i;
i--;
i--;
i--;
i--;
i--;
i--;
}
void delay(int d)
{
int x,y;
for(y=d;y>=0;y--)
for(x=110;x>0;x--);
}
int DHT11readzhi()
{
int m,a,b;
EA=0;
DT=0;
delay(20);
DT=1;
DHT11_Delay_10us();
DHT11_Delay_10us();
DHT11_Delay_10us();
DHT11_Delay_10us();
while(DT==0);
DT=1;
while(DT==1);
for(m=0;m<5;m++)
{
cod[m]=DHT11_send();//8湿度+8小数+8温度+8小数+8校验
}
a=cod[0];
return a;
}
uchar DHT11_send()
{
int i;
uchar zhi;
for(i=8;i>0;i--)
{
zhi<<=1;
while(DT==0);
DHT11_Delay_10us();
DHT11_Delay_10us();
DHT11_Delay_10us();
if(DT==1)
{
zhi++;
while(DT==1);
DT=1;
}
}
return zhi;
}
void display(int a)
{ uint i;
int shi,ge,ca,ba;
shi=a/10;
ge=a%10;
for(i=0;i<=100;i++)
{
P0=duan[0];
P2=table[shi];
delay(2);
P0=duan[5];
P2=table[ge];
delay(2);
}
/* P0=duan[4];
P2=table[ca];
delay(2);
P0=duan[5];
P2=table[ba];
delay(2); */
}
void main()
{
//P0=0x00;
while(1)
{
display(DHT11readzhi());
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>