Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

i am getting my output in LCD as checksum error

yash_01

Newbie level 5
Newbie level 5
Joined
Dec 26, 2024
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
76
Missing CODE or SYNTAX tags [ Added by moderator ]
i am trying to do a code using a temperature and humidity sensor (DHT11), and i am getting checksum error as my output in LCD. i am using keil uv5 and proteus simulator

what is the error in this code??

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>
#include <reg52.h>
#include <intrins.h>
#define lcd_data P2
 
int i;
int temp=0;
unsigned char humidity=0;
unsigned char humidity_point=0;
unsigned char temperature=0;
unsigned char temp_point=0;
unsigned char check=0;
unsigned char h[]="00.0";
char a,b;
 
sbit DTH=P3^0;
sbit rs=P1^0; //reg select
sbit rw=P1^1; //rewrite
sbit en=P1^2;  //enable
 
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay();
 
void lcd_init()
{
    cmd(0x38);   //defining is first, the peripherals and the line
    cmd(0x0e);  
    cmd(0x01);
    cmd(0x06);  //entry mode - after refreshing we're ready to use it
    cmd(0x0c);  //defining cursor
    cmd(0x80);    // start from the first row first column
}
 
void cmd(unsigned char a)
{
    lcd_data=a;
    rs=0;   //registers select
    rw=0; // write mode
    en=1; //enabling writing to the registers, power should be on when in use
    lcd_delay();
    en=0;
}
 
void dat(unsigned char b)
{
    lcd_data=b;
    rs=1;
    rw=0;
    en=1;
      lcd_delay();
    en=0;
}
 
void show(unsigned char *s)
{
    while(*s) {
        dat(*s++);
    }
}
 
void lcd_delay(){
    int i;
    for (i=0;i<10000;i++){
    }
}
 
delay_ms(unsigned char val){
        if (val == 18){
            TMOD=0x01;
            TH0=0xB9;
            TL0=0xB0;
            TR0=1;
            while (TF0 == 0);
            TR0=0;
        }
        else if (val == 25){
            TMOD=0x01;
            TH0=0x9E;
            TL0=0x58;
            TR0=1;
            while (TF0 == 0);
            TR0=0;
        }
}
delay_us(unsigned char val){
    if (val == 40){
        TMOD=0x01;
        TH0=0xFF;
        TL0=0xD8;
        TR0=1;
        while (TF0 == 0);
        TR0=0;
    }
    else if (val == 35){
        TMOD=0x01;
        TH0=0xFF;
        TL0=0xDD;
        TR0=1;
        while (TF0 == 0);
        TR0=0;
    }
}
void set(){
    DTH=0;
    delay_ms(18);
    DTH=1;
    delay_us(40);
}
 
void response(){
    while (DTH==1);
    while (DTH==0);
    while (DTH==1);
}
 
unsigned char data_transmit(){
    unsigned char datas=0;
    for (i=0;i<8;i++){
        while (DTH==0);
        delay_us(40);
        if (DTH==1){
            datas = (1 << (7-i))|datas;
        }
        while (DTH == 1);
    }
    return datas;
}
 
void main(){
    lcd_init();
   
    while (1){
        set();
        response();
        humidity = data_transmit();
        humidity_point=data_transmit();
        temperature=data_transmit();
        temp_point=data_transmit();
        check=data_transmit();
        cmd(0x80);
        if (check == (humidity+humidity_point+temperature+temp_point)){
            show("humidity:");
            h[0]=(humidity/10)+48;
            h[1]=(humidity%10)+48;
            show(h);
        }
        else {
            cmd(0x80);
            show("Checksum Error!");
        }
        lcd_delay();
        cmd(0x01);
    }
}

 
Last edited by a moderator:
Hi,

the first to debug the problem would be to output:
* the expected checksum
* the calculated checksum
.. and do the calculations by hand

... or to do an internet search on "DHT11 checksum" ..... since you are not the first one with the same problem. So why not see how others solved the same problem?

Klaus
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top