Lab 09 - MES
Lab 09 - MES
Lab 09 - MES
Lab Manual 09
Session Fall 22
Objectives:
Understand the function of ADC in microcontroller.
Learn different mode of operation of ADC
Integration of LM35 temperature sensor with Atmega2560.
Equipment/Software Used:
AVR Studio
Proteus ISIS
Microcontroller
Breadboard
LCD 16 x 2
Capacitors
Variable resistor
Resistor
Introduction:
Analogue to Digital Converter
ADC is a system that converts an analog signal into a digital signal. In almost all digital systems there is a
frequent need to convert analog signals generated by analog devices such as microphone, sensors and
potentiometers into digital values that can be stored and processed by digital system. The ADC system of
Atmega16 has following features:
10-bit ADC
±2 LSB absolute accuracy
13 ADC clock cycle conversion rate
8 multiplexed single-ended input channels
selectable right or left result justification
0 to Vcc ADC input voltage range
ADLAR=0:
ADLAR=1
Code (Assembly):
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz CPU CLOCK SPEED
#endif
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTC0
#define D5 eS_PORTC1
#define D6 eS_PORTC2
#define D7 eS_PORTC3
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include<util/delay.h> #include
"lcd.h" int main (void)
{
unsigned char temp[10];
DDRF = 0x00;
DDRD = 0xFF;
DDRC = 0xFF;
ADCSRA = 0x87;//ADC enable and select ck/128 ADMUX =
0xC0;// Vref, ADC0, right-justified while (1){
ADCSRA |= (1<<ADSC);//start conversion
while((ADCSRA&(1<<ADIF))==0); //wait for end of conversion ADCSRA |=
(1<<ADIF); //clear the ADIF flag
unsigned int x= (ADCL|(ADCH<<8))/4;//x = adc value/4
Lcd8_Init();
itoa(x,temp,10); Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Temperature: ");
Lcd8_Write_String(temp);
_delay_ms(50);
}
}
Procedure:
Open proteus on your computer and place down Arduino Mega 2560, one LCD display, variable
resistor and a ground as shown in the picture.
Copy the hex file from Atmel Software and paste the hex file in the Arduino Mega configuration in
Proteus.
Lab Task 02
To check the ADC value by using a Potentiometer show the ADC value on LCD.
Code (Assembly):
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTC0
#define D5 eS_PORTC1
#define D6 eS_PORTC2
#define D7 eS_PORTC3
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include
<util/delay.h>
#include "lcd.h"
int main (void)
{
unsigned char temp[10];
DDRF = 0x00;
DDRD = 0xFF;
DDRC = 0xFF;
ADCSRA = 0x87;//make ADC enable and select ck/128
ADMUX = 0xC0;// Vref, ADC0, right-justified
while (1)
{
ADCSRA |= (1<<ADSC);//start conversion
while((ADCSRA&(1<<ADIF))==0); //wait for end of conversion
ADCSRA |= (1<<ADIF); //clear the ADIF flag
unsigned int x= (ADCL|(ADCH<<8));//x = adc value/4
Lcd8_Init();
itoa(x,temp,10);
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("ADC VALUE: ");
Lcd8_Write_String(temp);
_delay_ms(50);
} }
Procedure:
Open proteus on your computer and place down Arduino Mega 2560, one LCD display, keypad,
resistor pack and a ground as shown in the picture.
Copy the hex file from Atmel Software and paste the hex file in the Arduino Mega configuration in
Proteus.
Output (Hardware Simulation):
CONCLUSION
In this lab was based on analogue to detail converter. in this lab we perform two tasks one of which was the
resistance measurement in which we differentiated the resistance of a potential meter and displayed the
respective value after processing through the ADC onto the LCD screen and a second task was performed
using LM35 virtual temperature sensor and in this lobby measure different temperature based on the input from
the LM35 and then converted it into a particular DC value and display their respective temperature on the LCD
screen.