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.

[SOLVED] LCD problem for display the second part

Status
Not open for further replies.

jackrude

Newbie level 6
Joined
Mar 22, 2012
Messages
13
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
United State
Activity points
1,374
Hello all, I'm have trouble for displaying the second part of the message on to the LCD, it only display "temp controller, cur temp degree", it's not showing "temp =, deg C", please help me, i dont know it's the code problem or it's the hardware issue, this code is working on my demo board XL400, but is not working on my prototype,



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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include<reg51.h>
#define data P0
#define UPTEMP 45
#define DOWNTEMP 35
#define AL 50
 
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit adc_read=P3^4;
sbit adc_write=P3^3;
sbit adc_intr=P3^5;
sbit output=P3^7;
sbit alam=P3^6;
bit loadon=0;
 
void delay(int time)
    {   
        int i, j;   
            for(i=0;i<127;i++)  
                {
                    for (j=0;j<time;j++);
                }       
    }
 
void lcd_data(unsigned char a)
    {
        rs =1;
        data=a;
        en =1;
        delay(5);
        en = 0;
        delay(5);
    }
 
void lcd_cmd(unsigned char a)
    {
        rs=0;
        data=a;
        en=1;
        delay(1);
        en=0;
        delay(1);
 
    }
void lcd_string (char * s)
    {
        while(*s)
            
            {
                lcd_data(*s);
                s++;
            }
    }
 
void lcd_init()
{
    lcd_cmd(0x38);
    lcd_cmd(0x0e);
    lcd_cmd(0x01);
    lcd_cmd(0x0c);
    lcd_cmd(0x80);
}
 
void pwmm(int i)
{  int j,k;
   output=1;    
   for(j=0;j<i;j++)
    delay(5);
   k=10-i;
   output=0;
   for(j=0;j<k;j++)
    delay(5);
}
 
void main()
{
    unsigned char val=0, temp=0;
    unsigned int x=0;
    float temp1;
    output=0;
    alam=1;
    rw=0;
    lcd_init();
    lcd_string (" Temp controller" );
    lcd_cmd(0xC0);
    lcd_string( "Cur temp degree");
    adc_read = 1;
    adc_write = 1;
    delay(1000);
    lcd_cmd(0x01);
 
    while (1)
        {
            delay(100);
            adc_read=1;
            adc_write=0;
            delay(1);
 
            adc_write=1;
            while(adc_intr==1);
 
            adc_read=0;
            val=P1;
 
            temp=((float)val/255)*100.00;
 
            x+=(int)temp1;
            delay(10);
 
            delay (100);
 
            adc_read=1;
            adc_write=0;
            delay(1);
 
            adc_write=1;
            while(adc_intr==1);
 
            adc_read=0;
            val=P1;
            temp=((float)val/255)*100;
            x+=(int)temp1;
            delay(10);
            delay(100);
 
            adc_read=1;
            adc_write=0;
            delay(1);
            adc_write=1;
            while(adc_intr==1);
            adc_read=0;
            val=P1;
            temp=((float)val/255)*100;
            x+=(int)temp1;
 
            temp=x/3;
            x=0;
 
            if(temp>UPTEMP&&loadon==0)
                {
                    output=1;
                    loadon=1;
                }
            if(temp<=DOWNTEMP&&loadon==1)
                {
                    pwmm(10);
                    loadon=0;
                }
            if(temp>=AL)
                {
                    alam=0;
                }
                                        
            lcd_cmd(0x80);
            lcd_string("TEMP=");
            lcd_data((temp/10)%10+48);
            lcd_data(temp%10+48);
            lcd_string(" DEG. C");
            lcd_cmd(0xc0);
 
            if(loadon==1)
                {
                    lcd_string("COOLER ON ");
                }
            else
                {
                    lcd_string("COOLER OFF");
                }
            lcd_cmd(0x80);
        }
}

 
Last edited by a moderator:

Firstly please provide some details regarding your hardware , i can see 8051 series , what ADC are you using ? what temp. sensor ?

Just provide little briefing so that we can help you !!!
 

I am using AT89s52 as the MCU, and the converter is ADC0804, and LM35 for the sensor
 

Hello all, I'm have trouble for displaying the second part of the message on to the LCD, it only display "temp controller, cur temp degree", it's not showing "temp =, deg C", please help me, i dont know it's the code problem or it's the hardware issue, this code is working on my demo board XL400, but is not working on my prototype,



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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include<reg51.h>
#define data P0
#define UPTEMP 45
#define DOWNTEMP 35
#define AL 50
 
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit adc_read=P3^4;
sbit adc_write=P3^3;
sbit adc_intr=P3^5;
sbit output=P3^7;
sbit alam=P3^6;
bit loadon=0;
 
void delay(int time)
    {   
        int i, j;   
            for(i=0;i<127;i++)  
                {
                    for (j=0;j<time;j++);
                }       
    }
 
void lcd_data(unsigned char a)
    {
        rs =1;
        data=a;
        en =1;
        delay(5);
        en = 0;
        delay(5);
    }
 
void lcd_cmd(unsigned char a)
    {
        rs=0;
        data=a;
        en=1;
        delay(1);
        en=0;
        delay(1);
 
    }
void lcd_string (char * s)
    {
        while(*s)
            
            {
                lcd_data(*s);
                s++;
            }
    }
 
void lcd_init()
{
    lcd_cmd(0x38);
    lcd_cmd(0x0e);
    lcd_cmd(0x01);
    lcd_cmd(0x0c);
    lcd_cmd(0x80);
}
 
void pwmm(int i)
{  int j,k;
   output=1;    
   for(j=0;j<i;j++)
    delay(5);
   k=10-i;
   output=0;
   for(j=0;j<k;j++)
    delay(5);
}
 
void main()
{
    unsigned char val=0, temp=0;
    unsigned int x=0;
    float temp1;
    output=0;
    alam=1;
    rw=0;
    lcd_init();
    lcd_string (" Temp controller" );
    lcd_cmd(0xC0);
    lcd_string( "Cur temp degree");
    adc_read = 1;
    adc_write = 1;
    delay(1000);
    lcd_cmd(0x01);
 
    while (1)
        {
            delay(100);
            adc_read=1;
            adc_write=0;
            delay(1);
 
            adc_write=1;
            while(adc_intr==1);
 
            adc_read=0;
            val=P1;
 
            temp=((float)val/255)*100.00;
 
            x+=(int)temp1;
            delay(10);
 
            delay (100);
 
            adc_read=1;
            adc_write=0;
            delay(1);
 
            adc_write=1;
            while(adc_intr==1);
 
            adc_read=0;
            val=P1;
            temp=((float)val/255)*100;
            x+=(int)temp1;
            delay(10);
            delay(100);
 
            adc_read=1;
            adc_write=0;
            delay(1);
            adc_write=1;
            while(adc_intr==1);
            adc_read=0;
            val=P1;
            temp=((float)val/255)*100;
            x+=(int)temp1;
 
            temp=x/3;
            x=0;
 
            if(temp>UPTEMP&&loadon==0)
                {
                    output=1;
                    loadon=1;
                }
            if(temp<=DOWNTEMP&&loadon==1)
                {
                    pwmm(10);
                    loadon=0;
                }
            if(temp>=AL)
                {
                    alam=0;
                }
                                        
            lcd_cmd(0x80);
            lcd_string("TEMP=");
            lcd_data((temp/10)%10+48);
            lcd_data(temp%10+48);
            lcd_string(" DEG. C");
            lcd_cmd(0xc0);
 
            if(loadon==1)
                {
                    lcd_string("COOLER ON ");
                }
            else
                {
                    lcd_string("COOLER OFF");
                }
            lcd_cmd(0x80);
        }
}


Port P1 is connected to D0-D7 of the ADC.
Make the port as input at the start of the main().
like, P1=0xFF;

And, also make INTR, RD, WR pin high before that infinite while loop like:-

adc_read=1;
adc_write=1;
adc_intr=1;

After that in the while loop before conversion,

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
........................
............
while (1)
        {
            adc_write=0;
            adc_write=1;
            while(adc_intr==1);
            adc_read=0;
            val=P1;
            adc_read=1;
            temp=((float)val/255)*100.00;
.................................................
}


Make these changes to get reading from ADC.
It would be good if you pass the value of "val" to a seperate function and process there. The main() will look good. Also take average of multiple(>1000) readings.
Use loop.
At a quick glance these are the changes you need.
 

thank you for help, we had initial the input P1= 0xff, all the message is displaying on the LCD, but the temperature is changing, look like the sensor is detecting any heat source, we had check over and over again of the circuit, but still not working, plz help
 

You are using LM35 so check the output pin of LM35 i.e. pin2 , it should be like :

for 35 C - 0.35 V
for 40 C - 0.4 V

check if it remains constant for 5 sec and then tell me
 

This generally happens if you do not take average of multiple readings. Take average of 2000 readings. The output will be stable.
For Idea:-


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void read_adc(void)
{
unsigned short i;
unsigned long result_temp=0;
      for(i=2000;i>0;i-=1) //looping 2000 times for getting average value
      {
            adc_write=0;
            adc_write=1;
            while(adc_intr==1);
            adc_read=0;
            val=P1;
            adc_read=1;
           result_temp+=val;
      }
result = result_temp/2000; //getting average value result declared as global
}


Call the function from main and then continue with the value stored in result. [check data types]
This is the idea.
 

But thats not the case with lm35 because one of its key features is minimal self heating , so dont worry about that problem !
 

hi there, we did measure the output voltage from the LM35 on the output, it keep increase on the voltage from 0.338......
 

So it increases from 0.338 upto what ? if it changes a lot then there is some problem wit your lm35 coz generally they are stable output transducers

---------- Post added at 09:10 ---------- Previous post was at 09:07 ----------

Still as it shows some readings near room temp i will say its alright , so now just take an average of some 500 readings and show at the output , more readings avg u take less would be the fluctuations . . .

hope it helped !
 

the output voltage seems find, and we reconnect the diagram, and measure all the pin to pin voltage, it look find, I am wondering can it be code problem?
 

Publish the final code

I agree... We can't just guess...

One little suggestion about temperatures and averages, control and stuff... keep in mind that a user don't need to get real time info on the lcd... we probably will never note if the info comes a fraction of a second later.. my suggestion is: use timed display info refreshing, according to what is reasonable... avoid the flashing unreadable numbers... you should separate what is working actions from report actions in time domain
 

Code:
#include <REGX51.H>
#define data P0
#define input P1
#define UPTEMP 45
#define DOWNTEMP 35
#define AL 50

sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit adc_read=P3^4;
sbit adc_write=P3^3;
sbit adc_intr=P3^5;
sbit output=P3^7;
sbit alam=P3^6;
bit loadon=0;

void delay(int time)
	{	
		int i,j;	
			for(i=0;i<127;i++)	
				{
					for (j=0;j<time;j++);
				}		
	}

void lcd_data(unsigned char a)
	{
		rs=1;
		data=a;
		en=1;
		delay(1);
		en=0;
		delay(1);
	}

void lcd_cmd(unsigned char a)
	{
		rs=0;
		data=a;
		en=1;
		delay(1);
		en=0;
		delay(1);

	}

void lcd_string(char*s)
	{
		while(*s)
			
			{
				lcd_data(*s);
				s++;
			}
	}

void lcd_init()
{
	lcd_cmd(0x38);
	lcd_cmd(0x0e);
	lcd_cmd(0x01);
	lcd_cmd(0x0c);
	lcd_cmd(0x80);
}

void pwmm(int i)
{  
	int j,k;
   	output=1;	
   	for(j=0;j<i;j++);
	delay(5);
   	k=10-i;
   	output=0;
   	for(j=0;j<k;j++);
	delay(5);
}

void main()
{
	unsigned char val=0, temp=0;
	unsigned int x=0;
	float temp1;
	output=0;
	alam=1;
	rw=0;
	lcd_init();
	lcd_string (" Temp controller" );
	lcd_cmd(0xC0);
	lcd_string( "Cur temp degree");
	adc_read=1;
	adc_write=1;
	delay(1000);
	lcd_cmd(0x01);
	input=0xff;

	while (1)
		{
			delay(100);
			adc_read=1;
			adc_write=0;
			delay(1);

			adc_write=1;
			while(adc_intr==1);

			adc_read=0;
			val=input;

			temp=((float)val/255)*100.00;

			x+=(int)temp1;
			delay(10);
			delay (100);

			adc_read=1;
			adc_write=0;
			delay(1);

			adc_write=1;
			while(adc_intr==1);

			adc_read=0;
			val=input;
			temp=((float)val/255)*100.00;
			x+=(int)temp1;
			delay(10);
			delay(100);

			adc_read=1;
			adc_write=0;
			delay(1);
			adc_write=1;
			while(adc_intr==1);
			adc_read=0;
			val=input;
			temp=((float)val/255)*100.00;
			x+=(int)temp1;

			temp=x/3;
			x=0;

			if(temp>=UPTEMP&&loadon==0)
				{
					pwmm(10);
					loadon=1;
				}
			if(temp<=DOWNTEMP&&loadon==1)
				{
					
					output=0;
					loadon=0;
				}
			if(temp>=AL)
				{
					alam=0;
				}
									    
			lcd_cmd(0x80);
			lcd_string("TEMP= ");
			lcd_data((temp/10)%10+48);
			lcd_data(temp%10+48);
			lcd_string("DEG.C");

			lcd_cmd(0xc0);
			if(loadon==1)
				{
					lcd_string("Fast running");
				}
			else
				{
					lcd_string("Slow running");
				}
			lcd_cmd(0x80);
		}
}
 

Well.. you are actually displaying garbage....
float temp 1 is never defined

also I don't understand why is temp and x is integer.. probably you have dead code mixed with new code

Code:
float temp1; 

.....

val=input;

temp=((float)val/255)*100.00;

x+=(int)temp1;  // you are adding garbage to you sum... with out any temperature info at all

then you do it again ....

val=input;
temp=((float)val/255)*100.00;
x+=(int)temp1;

and again...

val=input;
temp=((float)val/255)*100.00;
x+=(int)temp1;

until you  get the mean value of a variable with garbage
temp=x/3;
x=0;

And finally you print the mean of garbage

lcd_string("TEMP= ");
lcd_data((temp/10)%10+48);
lcd_data(temp%10+48);
 

yeh, we also recognized it too, and we had change the temp1 to temp, now is give some value, but the degree is not accuracy, wondering for the calculation, any suggestion, thank you for reply
 

well.. your calculation is not so bright :(

LM35 --> 10mV/ºC
0.5°C accuracy guaranteeable (at +25°C) --> 5mV

ADC0804, using REF/2= 2.500 V

1LSB = 5000mV/256 =19.53 mV --> 2 degrees aprox. note you have a +/- 1LSB error with this setup, meaning you have +/- 2 ºC error on the measuring... this without considering noise..

conclusion... you have a a bad overall temperature accuracy, and also a bad signal to noise relationship..
advice... figure out the max temp your system will be dealing with, then make the higher temp lm35 output match the adc max input voltage (5V) using an OPAMP to introduce the desired gain on the LM35 signal..
 

Hmmm... You are not able to display reading on second line...
This mainly occurs when your lcd is not properly initialized..

I had also faced this problem... few months back...

So just give some delay after initialization command
Code:
void lcd_init()
{
	lcd_cmd(0x38);
        //Give Some Delay Here
	lcd_cmd(0x0e);
        //Give Some Delay Here
	lcd_cmd(0x01);
        //Give Some Delay Here
	lcd_cmd(0x0c);
        //Give Some Delay Here
	lcd_cmd(0x80);
        //Give Some Delay Here
}

OKay, if this works then great, otherwise write a test code to check your lcd display to display some string on first and second line.


Hope this helps
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top