Lab 08 - MES
Lab 08 - MES
Lab Manual 08
Session Fall 22
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.
Code (Assembly):
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
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):
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):
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.