0% found this document useful (0 votes)
51 views6 pages

Lab 05 - MES

This document is a lab manual for a microcontroller and embedded systems class. It contains two lab tasks: 1. Writing a name to EEPROM memory and displaying it on an LCD screen in Proteus and on hardware. 2. Controlling LED brightness using fast PWM to vary between 0-45% on Proteus and an Arduino Mega. The document provides code examples and step-by-step procedures to complete the tasks in Proteus and on hardware. It concludes that the lab tasks taught how to configure ports and interface an LCD display and keypad with a microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

Lab 05 - MES

This document is a lab manual for a microcontroller and embedded systems class. It contains two lab tasks: 1. Writing a name to EEPROM memory and displaying it on an LCD screen in Proteus and on hardware. 2. Controlling LED brightness using fast PWM to vary between 0-45% on Proteus and an Arduino Mega. The document provides code examples and step-by-step procedures to complete the tasks in Proteus and on hardware. It concludes that the lab tasks taught how to configure ports and interface an LCD display and keypad with a microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MT-359L Microcontroller and Embedded Systems

MT-359L Microcontroller and Embedded System

Lab Manual 05

Muhammad Sarmad Baig


Name Shahzaib Khalil
Abdur Rab
Ayesha Siddiqua
201133
Registration Number 201097
201106
201088
Class BEMTS-F20-VA

Instructor’s Name Engr. Iraj Kainat

Session Fall 22

Air University, Islamabad Page 1


Lab # 05
Read and Write Data on EEPROM, Timers, PWM

Objectives:
In this lab we will learn:
1. Interfacing of 16x2 LCD & Keypad with ATMEGA Microcontrollers.

Lab Task 01:


Write your First and last name in EEPROM register and then display that stored name on LCD in
proteus.

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_PORTC1
#define D5 eS_PORTC2
#define D6 eS_PORTC3
#define D7 eS_PORTC4
#define RS eS_PORTC6
#define EN eS_PORTC7

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"

int main(void)
{
DDRD = 0XFF; // Setting the register D for output
DDRC = 0xFF; // Setting the register C for output
char a[8];
Lcd8_Init();

unsigned char i[]="Sarmad07";

while (EECR & (1<<EEPE));

EEAR = 0x5F;
for(int x=0; x<8;x++ )
{
EEDR=i[x];
}
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
EECR |= (1<<EERE);

for(int y=0; y<8;y++)


{
a[y]=EEDR;
Lcd8_Write_Char(a[y+8]) ;

}
return 0;
}

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 (Proteus Simulation):

Figure 1: Proteus Simulation

Output (Hardware Simulation):

Figure 2: Hardware Implementation


Lab Task 02:
Control LED brightness to vary between 0 to a 45% using Fast PWM.

Code (Assembly):
#define F_CPU 16000000UL
#include "avr/io.h"
#include <util/delay.h>

int main (void)


{

DDRB=0x80;
unsigned char duty; //set fast PWM mode with non-inverted output
TCCR0A|=(1<<WGM00)|(1<<WGM01)|(1<<COM0A1);
TCCR0B |=(1<<CS00);
while (1)
{
for(duty=0; duty<115; duty++)
{
OCR0A=duty; /*increase the LED light intensity*/
_delay_ms(10);
}

for(duty=115; duty>0; duty--)


{
OCR0A=duty; /*decrease the LED light intensity*/
_delay_ms(10);
}
}
}

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 (Proteus Simulation):

Figure 3: Proteus Simulation

CONCLUSION
In this lab, we have learned how to configure port for input and output in C language and we have also
learned how to interface 16x2 LCD Displays and Keypad with AT mega Microcontrollers. We are given lab
tasks that are implemented on proteus as well as on hardware. Hence, our tasks are completed successfully.

You might also like