0% found this document useful (0 votes)
61 views

Lab 08 - MES

This document describes two lab tasks involving external interrupts on an ATmega2560 microcontroller. The first task uses an external interrupt to toggle an LED when a button is pressed, overriding the main program. The second task displays which of three external interrupts is triggered by buttons on an LCD screen. Both tasks are programmed in assembly language and simulated using Proteus software. In conclusion, the document states key points learned about generating and responding to external interrupts from buttons using interrupts and an LCD display.
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)
61 views

Lab 08 - MES

This document describes two lab tasks involving external interrupts on an ATmega2560 microcontroller. The first task uses an external interrupt to toggle an LED when a button is pressed, overriding the main program. The second task displays which of three external interrupts is triggered by buttons on an LCD screen. Both tasks are programmed in assembly language and simulated using Proteus software. In conclusion, the document states key points learned about generating and responding to external interrupts from buttons using interrupts and an LCD display.
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/ 8

MT-359L Microcontroller and Embedded Systems

MT-359L Microcontroller and Embedded System

Lab Manual 08

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 # 08
Introduction to External Interrupts on ATMEGA 2560 using
Atmel Studio and Proteus

Objectives:
 Introduction to External interrupts.
 To display all the interrupts on LCD by using Arduino MEGA2560.

Equipment/Software Used:
 Microcontroller (ATMEGA 328p/2560)
 Atmel Studio
 LCD
 Resistors
 Proteus

Introduction:
An interrupt is the automatic transfer of software execution in response to a hardware event that is
asynchronous with the current software execution. This hardware event is called a trigger.

External Interrupts:
 Atmega32 has three external hardware interrupts on pins PD0, PD1, and PD2 which are referred to as
INT0, INT1, and INT2 respectively.
 External interrupts can be level-triggered or edge-triggered.

Programming External Interrupt


Lab Task 01:
Design a system such that in which an LED is set to turn ON but as soon as an eternal interrupt is
generated it exits the main program turns ON the second LED and then comes bac to the main program.

Code (Assembly):

#define F_CPU 16000000UL


#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

int main(void)
{
DDRB=0xFF; // Make PORTC as output PORT
DDRD=0x00; // PORTD as input
PORTD |= (1 << PIND0); // PD0 is now an input with pull-up enabled
EIMSK |= (1 << INT0); // Turns on INT0
MCUCR = 1<<ISC01 | 1<<ISC00; // Trigger INT0 on falling edge

sei(); // Enable Interrupts


while (1)
{
PORTB=0x80;
}
}
//Interrupt Service Routine for INT0
ISR(INT0_vect)
{
PORTB=0x40; //Toggle PORTB
_delay_ms(1000);
}

Procedure:
 Open proteus on your computer and place down Arduino Mega 2560, resistor ,LED’s 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

Lab Task 02:


Control LED brightness to vary between 0 to a 45% using Fast PWM.

Code (Assembly):
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif

#define D0 eS_PORTB0
#define D1 eS_PORTB1
#define D2 eS_PORTB2
#define D3 eS_PORTB3
#define D4 eS_PORTB4
#define D5 eS_PORTB5
#define D6 eS_PORTB6
#define D7 eS_PORTB7
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "lcd.h"

int main(void)
{

DDRC= 0xFF;
DDRB = 0xFF;
DDRD=0x00; // PORTD as input
PORTD |= (1 << PIND0); // PD0 is now an input with pull-up enabled
PORTD |= (1 << PIND1); // PD1 is now an input with pull-up enabled
PORTD |= (1 << PIND2); // PD2 is now an input with pull-up enabled
EIMSK |= (1 << INT0); // Turns on INT0
EIMSK |= (1 << INT1); // Turns on INT1
EIMSK |= (1 << INT2); // Turns on INT2
MCUCR = 1<<ISC01 | 1<<ISC00; // Trigger INT0 on falling edge
MCUCR = 1<<ISC11 | 1<<ISC10; // Trigger INT1 on falling edge
MCUCR = 1<<ISC20; // Trigger INT2 on falling edge
sei(); // Enable Interrupts
Lcd8_Init();
while (1)
{
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Main");
}
}
//Interrupt Service Routine for INT0
ISR(INT0_vect)
{
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Interrupt 0");
_delay_ms(1000);
Lcd8_Clear();
}

ISR(INT1_vect)
{
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Interrupt 1");
_delay_ms(1000);
Lcd8_Clear();
}

ISR(INT2_vect)
{
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Interrupt 2");
_delay_ms(1000);
Lcd8_Clear();
}
Procedure:

 Open proteus on your computer and place down Arduino Mega 2560, one LCD display, push
buttons, 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 the following points which are given below:
 I performed the task on proteus in which we set one LED to turn ON but when external interrupts
generate then it exits the main program and turn ON the second LED and then come back to the main
function.
 I performed the task on proteus and generates all the external interrupts INT0, INT1, INT2 and then
display it on the LCD.

You might also like