找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机dht11 LCD1602显示湿度值总为0为什么啊?编译没有问题,一个警告

[复制链接]
跳转到指定楼层
楼主
ID:1068594 发表于 2023-3-27 19:09 来自手机 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>
#define uint unsigned int;
#define uchar unsigned char;
unsigned char rec[5]={'\o'};
unsigned char code array[]={"humi:"};
sbit ledl=pl^1;
sbit dht=Po^4;
sbit EN=P3^4;10
sbit rs=P3^5;
uint num;
void delayms (unsigned int xms) {
unsigned int i j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--); }
void delayus(unsigned char xus)
{
while(xus--);
}
void DHTll Start(void) {
dht=1;
delayus(2);
dht=0;
delayms(20);
dht=1;
delayus (40);
dht=1;
if(dht=-0)
{
while(!dht);
while(dht);}
unsigned char dhTll receive byte() {
unsigned char i;        
60        unsigned char flag=o;
for(i=0;i<8;i++)
while(!dht);
delayus(30);
flag<<=1;
if(dht==1)
flag+=1;
while(dht);
}
return flag; }
void DHTll receive()
{
unsigned char R h,R L,receive;
dht=1;
delayus(30);
dht=0;
delayms(20);
dht=1;
delayus(30);
dht=1;
if(dht==0)
{
while(!dht);
while(dht);
R H=DHTll receive byte;
R L=DHTll receive byte;
receive=DHTll receive byte;
dht=0;
delayus(55);
dht=1;        
if((R H+R L)==receive)
{
rec[0]=R H;        
         rec[1]=RL;
rec[2]=receive;        
} } }
void Lcd1602 write cmd(unsigned char cmd) { RS=0; P0=cmd;
delayms(5);
EN=1;
delayms (5) ;
EN=0; }
void Lcd1602 write data(unsigned char date)
RS=1;
P0=date;
delayms (5);
EN=1;
delayms (5) ;
EN=0;}
void Lcd1602 init() {
Lcd1602 write cmd(0x38);
Lcd1602 write cmd(0x0c);
Lcd1602 write cmd(0x06);
Lcd1602 write cmd(0x0l); }
void DHT display() {
Lcd1602 write cmd(0x85);
Lcd1602 write data(rec[0]/10+0x30);
Lcd1602 write cmd(0x86);
Lcd1602 write data(rec[0]810+0x30);
Lcd1602 write cmd(0x87);
Lcd1602 write data('.');        
         Lcd1602 write cmd(0x88);
Lcd1602 write data(rec[1]/10+0x30);
Lcd1602 write cmd(0x89);
Lcd1602 write data('%');
}
void main ( ) {
Lcd1602 init0;
delayms(1500);
Lcd1602 write cmd(0x80);        
         for(num=0;num<5;num++)
Lcd1602 write data(array[num]);
}
while(1)

delayms(1000);
DHT11 Start();
DHT display();
}
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1068594 发表于 2023-3-27 19:15 来自手机 | 只看该作者
大家有时间帮我看看啊,我改了好几天了,实在想不出来了。明天就到截止日期了
回复

使用道具 举报

板凳
ID:155507 发表于 2023-3-27 21:35 | 只看该作者
错误的地方太多了
给你改了,对比一下就知道哪里错了。

  1. #include <reg52.h>
  2. #define uint unsigned int  //;
  3. #define uchar unsigned char //;
  4. unsigned char rec[5]={'\0'}; //{'\o'};
  5. unsigned char code array[]={"humi:"};
  6. sbit led1=P1^1; //pl^1;
  7. sbit dht=P0^4; //Po^4;
  8. sbit EN=P3^4; //10
  9. sbit rs=P3^5;
  10. uint num;
  11. void delayms(unsigned int xms) {
  12.         unsigned int i, j;
  13.         for(i=xms;i>0;i--)
  14.                 for(j=110;j>0;j--);
  15. }
  16. void delayus(unsigned char xus)
  17. {
  18.         while(xus--);
  19. }
  20. void DHTll_Start(void) {
  21.         dht=1;
  22.         delayus(2);
  23.         dht=0;
  24.         delayms(20);
  25.         dht=1;
  26.         delayus (40);
  27.         dht=1;
  28.         if(dht=-0)
  29.         {
  30.                 while(!dht);
  31.                 while(dht);}
  32. }
  33. unsigned char DHTll_receive_byte() {
  34.         unsigned char i;        
  35.         //60        
  36.         unsigned char flag=0;//o;
  37.         for(i=0;i<8;i++)
  38.         while(!dht);
  39.         delayus(30);
  40.         flag<<=1;
  41.         if(dht==1)
  42.         {
  43.         flag+=1;
  44.         while(dht);
  45.         }
  46.         return flag;
  47. }
  48. void DHTll_receive()
  49. {
  50.         unsigned char R_h,R_L,receive;
  51.         dht=1;
  52.         delayus(30);
  53.         dht=0;
  54.         delayms(20);
  55.         dht=1;
  56.         delayus(30);
  57.         dht=1;
  58.         if(dht==0)
  59.         {
  60.                 while(!dht);
  61.                 while(dht);
  62.                 R_H=DHTll_receive_byte(); //DHTll_receive byte;
  63.                 R_L=DHTll_receive_byte(); //DHTll_receive byte;
  64.                 receive=DHTll_receive_byte(); //DHTll receive byte;
  65.                 dht=0;
  66.                 delayus(55);
  67.                 dht=1;        
  68.                 if((R_H+R_L)==receive)
  69.                 {
  70.                         rec[0]=R_H;        
  71.                         rec[1]=R_L;
  72.                         rec[2]=receive;        
  73.                 }
  74.         }
  75. }
  76. void Lcd1602_write_cmd(unsigned char cmd) {
  77.         RS=0; P0=cmd;
  78.         delayms(5);
  79.         EN=1;
  80.         delayms (5) ;
  81.         EN=0;
  82. }
  83. void Lcd1602_write_data(unsigned char date)
  84. {
  85.         RS=1;
  86.         P0=date;
  87.         delayms (5);
  88.         EN=1;
  89.         delayms (5) ;
  90.         EN=0;
  91. }
  92. void Lcd1602_init() {
  93.         Lcd1602_write_cmd(0x38);
  94.         Lcd1602_write_cmd(0x0c);
  95.         Lcd1602_write_cmd(0x06);
  96.         Lcd1602_write_cmd(0x0l);
  97. }
  98. void DHT_display() {
  99.         Lcd1602_write_cmd(0x85);
  100.         Lcd1602_write_data(rec[0]/10+0x30);
  101.         Lcd1602_write_cmd(0x86);
  102.         Lcd1602_write_data(rec[0]810+0x30);
  103.         Lcd1602_write_cmd(0x87);
  104.         Lcd1602_write_data('.');        
  105.         Lcd1602_write_cmd(0x88);
  106.         Lcd1602_write_data(rec[1]/10+0x30);
  107.         Lcd1602_write_cmd(0x89);
  108.         Lcd1602_write_data('%');
  109. }
  110. void main() {
  111.         Lcd1602_init();
  112.         delayms(1500);
  113.         Lcd1602_write_cmd(0x80);        
  114.         for(num=0;num<5;num++)
  115.         Lcd1602_write_data(array[num]);
  116.         //}
  117.         while(1)
  118.         { //{
  119.         delayms(1000);
  120.         DHT11_Start();
  121.         DHT_display();
  122.         }
  123. }

复制代码


回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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