找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1536|回复: 2
打印 上一主题 下一主题
收起左侧

89c51单片机控制,DHT11在1602上显示 为什么数据传不到1602上

[复制链接]
跳转到指定楼层
楼主
ID:489425 发表于 2019-3-19 14:57 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define DATA P0
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P2^5;
uchar str1[]={"  "},str2[]={"  "};
uchar shduh_s,shdul_s,wenduh_s,wendul_s,jiaoyan_s;
uchar shduh,shdul,wenduh,wendul,jiaoyan;
uchar RH_data,RL_data,TH_data,TL_data,CK_data;
uchar FLAG,k,count,temp,comdata;
sbit wshbzh=P1^7;
void delay(xms)
{
        uint i,j;
        for(i=xms;i>0;i--)
        for(j=50;j>0;j--);
}
void Delay_10us(void)
{
        uchar i;
        i--;
        i--;
        i--;
        i--;
        i--;
        i--;
}
void minling(uchar comd)
{
        rs=0;
        rw=0;
        DATA=comd;
        delay(5);
        en=1;
        delay(5);
        en=0;
}
void writedata(uchar write)
{
        rs=1;
        rw=0;
        DATA=write;
        delay(5);
        en=1;
        delay(5);
        en=0;
}
void writechar(uchar x,y,Data)
{     
        if (x==0)
        {     
              minling(0x80+y-1);     
        }   
        else
        {     
                minling(0xC0+y-1);     
         }        
        writedata(Data);  
}
void lcdinit()
{
  minling(0x02);
        minling(0x06);
        minling(0x0c);
        minling(0x38);
        minling(0x01);
}
void writestring(uchar x,uchar y,uchar *s)
{
         if (x == 1)
         {     
         minling(0x80 + y-1);   
         }
else
         {      
minling(0xC0 + y-1);      
         }        
while (*s)
         {     
writedata( *s);     
s ++;     
         }        
}
void COM()
{
        uchar i;
        for(i=0;i<8;i++)           
        {               
                FLAG=2;        
                while((!wshbzh)&&FLAG++);
                Delay_10us();
                Delay_10us();
                Delay_10us();
                temp=0;
                if(wshbzh) temp=1;
                FLAG=2;
                while((wshbzh)&&FLAG++);                 
                if(FLAG==1)
                        break;
                comdata<<=1;
                comdata|=temp;        //0
        }           
}
void RH()
{
        wshbzh=0;
        delay(200);        
        wshbzh=1;
        Delay_10us();
        Delay_10us();
        Delay_10us();
        Delay_10us();
     
        wshbzh=1;
        
        if(!wshbzh)  //T !         
        {
                FLAG=2;      
                while((!wshbzh)&&FLAG++);
                FLAG=2;
                while((wshbzh)&&FLAG++);               
                COM();
                shduh_s=comdata;
                COM();
                shdul_s=comdata;
                COM();
                wenduh_s=comdata;
                COM();
                wendul_s=comdata;
                COM();
                jiaoyan_s=comdata;
                wshbzh=1; //????         
                temp=(shduh_s+shdul_s+wenduh_s+wendul_s);
               if(temp==jiaoyan_s)
                {
                       shduh=shduh_s;
                        shdul=shdul_s;
                       wenduh=wenduh_s;
                       wendul=wendul_s;
                       jiaoyan=jiaoyan_s;
                }
        }      
}      
int main()
{
        rs=0;
        rw=0;
        en=0;
        lcdinit();
                               writestring(1,1,"shidu:");
                         writestring(2,1,"wendu:");        
                               writestring(1,10,"%");
                               writestring(2,10,"C");
        while(1)
        {
                RH();
                        RH_data=shduh;
                        RL_data=shdul;
                        TH_data=wenduh;
                        TL_data=wendul;  
                        CK_data=jiaoyan;                        
                        str1[0]=(char)(0x30+RH_data/10);
                        str1[1]=(char)(0x30+RH_data%10);                                
                        str2[0]=(char)(0x30+TH_data/10);
                        str2[1]=(char)(0x30+TH_data%10);      

                        writechar(1,8,str1[0]);
                                    writechar(1,9,str1[1]);
                        writechar(2,8,str2[0]);
                        writechar(2,9,str2[1]);                                                     
                 delay(2000);
        }
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

板凳
ID:10947 发表于 2019-3-19 18:10 | 只看该作者
writechar(2,9,str2[1]); ,这个语句不是把内容发到1602上显示吧?
回复

使用道具 举报

沙发
ID:94031 发表于 2019-3-19 17:25 | 只看该作者
先实现能正确读出DHT11的数据,再实现到1602显示。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表