找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2193|回復: 2
打印 上一主題 下一主題
收起左側

89c51單片機控制,DHT11在1602上顯示 為什么數(shù)據(jù)傳不到1602上

[復制鏈接]
跳轉到指定樓層
樓主
ID:489425 發(fā)表于 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空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:94031 發(fā)表于 2019-3-19 17:25 | 只看該作者
先實現(xiàn)能正確讀出DHT11的數(shù)據(jù),再實現(xiàn)到1602顯示。
回復

使用道具 舉報

板凳
ID:10947 發(fā)表于 2019-3-19 18:10 | 只看該作者
writechar(2,9,str2[1]); ,這個語句不是把內(nèi)容發(fā)到1602上顯示吧?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表