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.

LM35 interfacing with 89S52 using adc0808

Status
Not open for further replies.

fazeelat

Newbie level 4
Joined
Dec 6, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
I am using ADC0808, microcontroller 89S52, and 16X2 Alpha-numeric LCD to display the sensed data using sensor (LM35) connected to ADC0808.
my step size is 10mV by keeping Vref=2.56 but can't obtain accurate temperature on LCD please help me in conversion of binary output of ADC into ASCII data for LCD
here is the C code written in keil ..... plz someone help me :(


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
#include<reg52.h>
sbit ale=P1^0;  //address latch enable
sbit oe=P1^3;  //output enable
sbit sc=P1^1;  //start conversion
sbit eoc=P1^2;  //end of conversion
sbit clk=P1^7;  // clock
sbit ADD_A=P1^4;  // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;
sfr lcd_data_pin=0xA0;  //P2 port
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
sbit led=P3^4;
sfr input_port=0x80;  //P0 port
unsigned int value;
void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}
void delay(unsigned int count)  // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
 
void lcd_command(unsigned char comm)  //Function to send command to LCD.
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(5);
en=0;
}
 
void lcd_data(unsigned char disp)  //Function to send data to LCD.
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(5);
en=0;
}
 
lcd_dataa(unsigned char *disp)  //Function to send string data to LCD.
{
int i=0;
while(disp[i]!='\0')
    {
        lcd_data(disp[i]);
        i++;
        delay(10);
    }
    return;
}
 
void lcd_ini()  //Function to inisialize the LCD
{
lcd_command(0x38); 
delay(2);
lcd_command(0x0F); 
delay(2);
lcd_command(0x80);  //Force cursor to blink at line 1 positon 0
delay(2);
}
  void BCD(unsigned char value)  // Binary to decimal conversion to send the data to LCD
{
 unsigned char x,d1,d2,d3,d4,d5,d6;
x=value/10;
d1=value%10;
d2=x%10;
d3=x/10;
d4=d1+48;
d5=d2+48;
lcd_command(0x01);
lcd_dataa("TEMP :");
lcd_data(d5);
lcd_command(0x87);
lcd_data(d4);
lcd_command(0x88);
lcd_data(223);
delay(10);
lcd_data('C');
delay(10);
led=0;
} 
 
void adc()  //Function to drive ADC
{
while(1)
{
  ADD_C=0;  // Selecting input channel 2 using address lines
  ADD_B=0;
  ADD_A=1;
  delay(2);
  ale=1;
  delay(2);
  sc=1;
  delay(1);
  ale=0;
  delay(1);
  sc=0;
  while(eoc==1);
  while(eoc==0);
  oe=1;
  value=input_port;
  BCD(value);                                                                    
  lcd_command(0x85);
  delay(2);                                                                     
  oe=0;
}
}
 
void main()
{
input_port=0xFF;
eoc=1;
ale=0;
oe=0;
sc=0;
TMOD=0x02;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
TH0=0xFD;
IE=0x82;
TR0=1;
lcd_ini();
adc();
}

 
Last edited by a moderator:

**broken link removed**

//Program to display temperature in Celsius and Farenheit scale.


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
#include<reg51.h>
#define port P3
#define adc_input P1
#define dataport P0
#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_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,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 commands 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;
    return;
}
 
void lcd_data_string(unsigned char *str)  // Function to string to LCD
{
    int i=0;
    while(str[i]!='\0')
    {
        lcd_data(str[i]);
        i++;
        delay(10);
    }
    return;
}
 
void shape()        // Function to make the shape of degree symbol
{
    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;
    lcd_cmd(0x81);      
    delay(2);
    lcd_data_string("TEMP:");
    test_final=(((9*test_intermediate3)/5)+32);
    s=test_final/100;
    test_final=test_final%100;
    lcd_cmd(0x88);
    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('F');
    lcd_data(' ');
 
    test_final=test_intermediate3;
    lcd_cmd(0xc1);        //Setting  cursor to first position of first line
    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);        //2 Line, 5X7 Matrix display
    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[i]=adc_input/10;
                delay(1);
                intr=1;
            }
            for(i=0;i<10;i++)
            test_intermediate2[j]=test_intermediate1[i]+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();
    }
}

 
Last edited by a moderator:

thanx basade.abdul
but above code is for adc 0804 and i m using adc0808.... i think there is some difference in case of conversion in case of adc0808
help me plz :(
 

you said you are not getting accurate temperature on LCD , please describe what are you getting giving an example
 

temperature variation is so random
that is if i get 25 degree C on LCD for 25 degree temperature then on increasing this temp to 26 degree C
i got 88degree C on LCD
 

Alright , are you using an amplifier at the output of lm35 ? like lm324 ?
 

Lm35 gives output in terms of fraction of 1V meanining , 0.32v for 32 degree celsius . . So generally people use an amplifier of gain 10 , for making the output variation coarse
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top