LM35 temperature conversion problem

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
HI to all,
i found a code for interfacing 8051 with LM35 and LCD which is not working very well.
1-The problem is: The temperature conversion is not good, for example when i ajdust LM35 to 89°C the LCD displays 39°C or for 30°C the LCD displays 09°C.

2- When running Proteus, if i change the value of LM35, the LCD value do not change lively, i have to stop simulation and restart the simulation.

Can you please check, i tried for all week-end and i did not fix.:(

Thank you
Have a nice day

Here is the code found with google.

Rich (BB code):
#include<reg51.h>


#define port P3
#define port0 P0
#define adc_input P1
#define dataport P2
#define sec 100

sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;

sbit wr= port^3;
sbit rd= port^4;
sbit intr= port^5;
int test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0},test_intermediate3=0;

void delay(unsigned int msec )
{
int i ,j ;
for(i=0;i<msec;i++)
  for(j=0; j<1275; j++);
}

void lcd_cmd(unsigned char item)  //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
//delay(100);
return;
}

void lcd_data_string(unsigned char *str)  // Function to send string to LCD
{
int i=0;
while(str!='\0')
{
  lcd_data(str);
  i++;
  delay(10);
}
return;
}

void shape()     // Function to create the shape of degree
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}
    
void convert()    // Function to convert the values of ADC into numeric value to be sent to LCD
{
int s;
test_final=test_intermediate3;
lcd_cmd(0xc1);
delay(2);
lcd_data_string("TEMP:");
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc8);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('c');
lcd_data(' ');
delay(2);
}

void main()
{
int i,j;
adc_input=0xff;
lcd_cmd(0x38);
lcd_cmd(0x0c);  //Display On, Cursor  Blinking
delay(2);
lcd_cmd(0x01);  // Clear Screen
delay(2);
while(1)
{
  for(j=0;j<3;j++)
  {
   for(i=0;i<10;i++)
   {
    delay(1);
    rd=1;
    wr=0;
    delay(1);
    wr=1;
    while(intr==1);
    rd=0;
    lcd_cmd(0x88);
    test_intermediate1=adc_input/10;
    delay(1);
    intr=1;
   }
   for(i=0;i<10;i++)
   test_intermediate2[j]=test_intermediate1+test_intermediate2[j]; 
   
  }

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
convert();
				 
}
                                                   
}
 

tshuck

Joined Oct 18, 2012
3,534
Sounds like you should try writing the code yourself, that way you might understand how it works, and understand any probable causes.

This is probably a school assignment. As such, you will be hard pressed to find someone willing to do the work for you, because then you are left without an understanding of how it works, as evidenced by this post.
 

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Thank you sir, but i'm not a student, i'm 40 year old and i want to learn 8051 by myself,
it's not an assignement or anything else.
But you are right, at this moment i already resolved my problem myself and it's working well.
Thank you for your support
 

tshuck

Joined Oct 18, 2012
3,534
Good! It's usually much harder to try to figure out how someone did something instead of doing it yourself (as far as code is concerned)...
 

MrChips

Joined Oct 2, 2009
35,115
Separate the problem into two separate problems:

1) Display readout
2) Temperature conversion

Adapt your program to output numbers from 0 to 99.
Test that the program works correctly.

After you have confirmed this is ok we can tackle the next problem.
 
Top