Exp10 1
Exp10 1
10 Date: D D - M M - Y Y
To interface Temperature sensor with AVR microcontroller using ATmega32 ADC and display on LCD
THEORY
To use ATmega32 ADC, the analog input need to be connected to PORTA pins which aremultiplexed
as ADC input pins (labeled as ADC0 to ADC7). LM35 Temperature sensor (Pin 2) is connected to
PORTA Pin 0(ADC0 pin) of ATmega32. PORTA is configured as an input port and PORTD and C as out
put ports.is configured as an output port. Data lines of LCD are connected to PORTD, and PORTC.6
and 7 are used as RS and E. RW is connected to ground.
LM35 series are precision integrated-circuit temperature sensors whose output voltage is linearly
proportional to the temperature. It outputs 10 mV for each degree of temperature.
The ADC has 10-bit resolution. So number of steps will be 1024. We use the internal 2.56 V
reference voltage as Vref, so the step size would be 2.56 V/1024 = 2.5 mV. LM35 sensorproduces 10
mV for each degree of temperature change and the ADC step size is 2.5 mV. So each degree of
temperature change corresponds to 4 ADC steps(10 mV/2.5 mV = 4).This makes the binary output
number for the ADC four times the real temperature. So the 10-bit output of the ADC is divided by 4
to get the real temperature. To divide the 10-bit output of the ADC by 4 we choose the left-justified
option and only read the ADCH register. It is same as shifting the result 2 bits right (division by 4 in
binary).
C Program
//------function declaration---------
void lcd_command(char c);
void lcd_data(char d);
void lcd_puts(const char *s);
//------main function----------------
main()
{
unsigned int ADATA = 0; //storing digital output of ADC
char DIGITS [3]; //for holding string of digits
DDRC=0XFF; //PORT C as o/p line
DDRD=0XFF; //PORT D as o/p line
DDRA = 0; // PORTA as input.
_delay_ms(20);
ADMUX |=(1<<REFS0)|(1<<REFS1) |(1<<ADLAR);
//setting the reference of ADC as 2.56V,left justified data
ADCSRA |=(1<<ADEN)|(1<<ADATE)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
//enabling the ADC, setting free running mode, setting prescalar 128
_delay_us(5);
}
}
RESULT
Interfacing program for LM 35 with 16x2 LCD is written in embedded C, compiled, downloaded to target
board, and implemented.