uchar a[]="温湿度传感器";
uchar b[]="温度:";
uchar c[]="湿度:";
uchar d[]="0123456789";
typedef unsigned char U8;
typedef unsigned int U16;
U8 U8flag,k;
U8 U8temp;
U8 U8WD_H,U8WD_L,U8SD_H,U8SD_L,U8checkdata;
U8 U8WDH_temp,U8WDL_temp,U8SDH_temp,U8SDL_temp,U8checkdata_temp;
U8 U8comdata;
void delay_1ms(uint n)
{
uint i,j;
for(i=0;i<=n;i++)
for(j=0;j<110;j++);
}
void delay_10us()
{
U8 i;
i--;i--;i--;i--;i--;i--;
}
void write_com(uchar com)
{
rs=0;
rw=0;
en=0;
P2=com;
delay_1ms(1);
en=1;
delay_1ms(1);
en=0;
}
void write_data(uchar date)
{
rs=1;
rw=0;
en=0;
P2=date;
delay_1ms(1);
en=1;
delay_1ms(1);
en=0;
}
void pos(uchar x,uchar y)
{
uchar pos;
if(x==0)
x=0x80;
else if(x==1)
x=0x90;
else if(x==2)
x=0x88;
else if(x==3)
x=0x98;
pos=x+y;
write_com(pos);
}
void display(U8WD_H,U8WD_L,U8SD_H,U8SD_L)
{
U8 yi,er,san,si;
yi=U8WD_H/10;
er=U8WD_H;
san=U8SD_H/10;
si=U8SD_H;
pos(1,4);
write_data(d[yi]);
pos(1,5);
write_data(d[er]);
pos(2,4);
write_data(d[san]);
pos(2,5);
write_data(d[si]);
}
void com()
{
U8 i;
for(i=0;i<8;i++)
{
U8flag=2;
while((!SJK)&&U8flag++);
delay_10us();delay_10us();delay_10us();
U8temp=0;
if(SJK)U8temp=1;
U8flag=2;
while((SJK)&&U8flag++);
if(U8flag==1)break;
U8comdata<<=1;
U8comdata|=U8temp;
}
}
2019-12-21 19:46:20
26KB
DHT11
1