看一下这个51单片机的DHT11温湿度传感器1602显示的程序哪里不对?
#include"reg52.h"//#include"intrins.h"#defineucharunsignedchar#defineuintunsignedints...
#include"reg52.h"
//#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit P2_0=P3^3;
sbit lcden=P0^7;
sbit lcdrs=P0^5;
sbit dula=P0^4;
sbit wela=P0^6;
uchar a[]="wendu:";
uchar b[]="shidu:";
uchar c[]="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)
{
lcdrs=0;
P2=com;
delay_1ms(5);
lcden=1;
delay_1ms(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P2=date;
delay_1ms(5);
lcden=1;
delay_1ms(5);
lcden=0;
}
void write_dht11(U8 date)
{ U8 shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+7);
write_data(c[0x30+shi]);
write_com(0x80+0x40+7);
write_data(c[0x30+ge]);
}
void com()
{
U8 i;
for(i=0;i<8;i++)
{
U8flag=2;
while((!P2_0)&&U8flag++);
delay_10us();delay_10us();delay_10us();
U8temp=0;
if(P2_0)U8temp=1;
U8flag=2;
while((P2_0)&&U8flag++);
if(U8flag==1)break;
U8comdata<<=1;
U8comdata|=U8temp;
}
}
void RH()
{
P2_0=0; delay_1ms(180); P2_0=1;
delay_10us();delay_10us();delay_10us();delay_10us();
P2_0=1;
if(!P2_0)
{
U8flag=2;
while((!P2_0)&&U8flag++);
U8flag=2;
while((P2_0)&&U8flag++);
com();
U8SDH_temp=U8comdata;
com();
U8SDL_temp=U8comdata;
com();
U8WDH_temp=U8comdata;
com();
U8WDL_temp=U8comdata;
com();
U8checkdata_temp=U8comdata;
P2_0=1;
U8temp=(U8WDH_temp+U8WDL_temp+U8SDH_temp+U8SDL_temp);
if(U8temp==U8checkdata_temp)
{
U8SD_H=U8SDH_temp;
U8SD_L=U8SDL_temp;
U8WD_H=U8WDH_temp;
U8WD_L=U8WDL_temp;
U8checkdata=U8checkdata_temp;
}
}
}
void init()
{
uchar num;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<6;num++)
{
write_data(a[num]);
delay_1ms(5);
}
write_com(0x80+0x40);
for(num=0;num<6;num++)
{
write_data(b[num]);
delay_1ms(5);
}
}
void main()
{
P2_0=1;
delay_1ms(40);
dula=0;
wela=0;
while(1)
{
RH();
write_dht11(U8WD_H);
write_dht11(U8WD_L);
write_dht11(U8SD_H);
write_dht11(U8SD_L);
}
} 展开
//#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit P2_0=P3^3;
sbit lcden=P0^7;
sbit lcdrs=P0^5;
sbit dula=P0^4;
sbit wela=P0^6;
uchar a[]="wendu:";
uchar b[]="shidu:";
uchar c[]="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)
{
lcdrs=0;
P2=com;
delay_1ms(5);
lcden=1;
delay_1ms(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P2=date;
delay_1ms(5);
lcden=1;
delay_1ms(5);
lcden=0;
}
void write_dht11(U8 date)
{ U8 shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+7);
write_data(c[0x30+shi]);
write_com(0x80+0x40+7);
write_data(c[0x30+ge]);
}
void com()
{
U8 i;
for(i=0;i<8;i++)
{
U8flag=2;
while((!P2_0)&&U8flag++);
delay_10us();delay_10us();delay_10us();
U8temp=0;
if(P2_0)U8temp=1;
U8flag=2;
while((P2_0)&&U8flag++);
if(U8flag==1)break;
U8comdata<<=1;
U8comdata|=U8temp;
}
}
void RH()
{
P2_0=0; delay_1ms(180); P2_0=1;
delay_10us();delay_10us();delay_10us();delay_10us();
P2_0=1;
if(!P2_0)
{
U8flag=2;
while((!P2_0)&&U8flag++);
U8flag=2;
while((P2_0)&&U8flag++);
com();
U8SDH_temp=U8comdata;
com();
U8SDL_temp=U8comdata;
com();
U8WDH_temp=U8comdata;
com();
U8WDL_temp=U8comdata;
com();
U8checkdata_temp=U8comdata;
P2_0=1;
U8temp=(U8WDH_temp+U8WDL_temp+U8SDH_temp+U8SDL_temp);
if(U8temp==U8checkdata_temp)
{
U8SD_H=U8SDH_temp;
U8SD_L=U8SDL_temp;
U8WD_H=U8WDH_temp;
U8WD_L=U8WDL_temp;
U8checkdata=U8checkdata_temp;
}
}
}
void init()
{
uchar num;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<6;num++)
{
write_data(a[num]);
delay_1ms(5);
}
write_com(0x80+0x40);
for(num=0;num<6;num++)
{
write_data(b[num]);
delay_1ms(5);
}
}
void main()
{
P2_0=1;
delay_1ms(40);
dula=0;
wela=0;
while(1)
{
RH();
write_dht11(U8WD_H);
write_dht11(U8WD_L);
write_dht11(U8SD_H);
write_dht11(U8SD_L);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询