Exp 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EEE373L

Course Title: - Microprocessor and Interfacing Laboratory

Lab Report
Section: 01 Group No: 10

Experiment no: 04

Name of the experiment: Single and Multiple External


Interrupts

All Group members:

Sl. Name Contribution ID Signature

1. Munirun Nessa Part B 20321022


Software

2. Sadman Seam Part B 20121054


Hardware

3. Motasim Faiyaz Part A 20121069


Hardware

4. Muhtasim Billah Nahin Part A 20121013


Software

Date of Submission: 23rd February, 2023


1. Objective: The objective of this experiment is to understand the basics of external single
interrupts and multiple interrupts.
2. Introduction/ Theoretical Background/ Problem Statement: Interrupt is a method of giving
attention to a task which is not scheduled as a usual task. In a microcontroller the usual task is to
follow line by line execution of a program. If a programmer wants to break the flow and attend a
different task, then that has to be done by Interrupt. Whenever such a situation occurs, the
microcontroller raises a flag corresponding to that task. The programmer sets the microcontroller
in such a way that the microcontroller on its own monitors the flag, does the task automatically –
using ISR (Interrupt Service Routine), whenever the flag is raised.

Registers related to the External Interrupts

GICR (General Interrupt Control Register): this defines enable/disable of the external
interrupts

MCUCR (Micro Controller Unit Control Register): this defines the senses of the interrupts of
Int0 and Int1

MCUCSR (Micro Controller Unit Control and Status Register): this defines the senses of
interrupt Int2

GIFR (General Interrupt Flag Register): The interrupt flags of this register are raised

3. Components Required:

• ATmega32
• Seven Segment Display
• LED
• Connecting Wires
PART A: Single External Interrupt
• Modify the code in such a way that will count the digits of the seven-segment display
in reverse order

HARDWARE

CODE

#include <mega32.h>
#include <delay.h>
interrupt [EXT_INT0] void ext_int0_isr(void)
{
unsigned int cathode[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned int i=9,k=0;
PORTB=0x01;
for (i=9;i>0;i--)
{
PORTA= cathode[i];
delay_ms(1000);
}
PORTA=0;
PORTB=0;
}
void main(void)
{
char i;
DDRA=0xFF;
DDRC=0xFF;
DDRB=0x01;
PORTA=0;
PORTC=0;
PORTB=0;

GICR|=(0<<INT1) | (1<<INT0) | (0<<INT2);


MCUCR=(0<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
MCUCSR=(0<<ISC2);
GIFR=(0<<INTF1) | (1<<INTF0) | (0<<INTF2);

#asm("sei")
while (1)
{
PORTC=0x80;
for (i=0;i<9;i++)
{
delay_ms(1000);
PORTC>>=1;
}
}
}

PROTEUS
PART B: Multiple External Interrupts
• Modify the code in such a way that will set INT1 higher than INT0

HARDWARE

CODE

#include <mega32.h>
#include <delay.h>
interrupt [EXT_INT0] void ext_int0_isr(void)
{
unsigned int cathode[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned int i=0,k=0;
#asm("sei")
PORTB=0x01;
for (i=0;i<10;i++)
{
PORTA= cathode[i];
delay_ms(1000);
}
PORTA=0;
PORTB=0;
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
char i;

PORTC=0x80;
for (i=0;i<8;i++)
{
delay_ms(1000);
PORTC>>=1;
}
}
void main(void)
{

DDRA=0xFF;
DDRC=0xFF;
DDRB=0x01;
PORTA=0;
PORTC=0;
PORTB=0;
GICR|=(1<<INT1) | (1<<INT0) | (0<<INT2);
MCUCR=(1<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
MCUCSR=(0<<ISC2);
GIFR=(1<<INTF1) | (1<<INTF0) | (0<<INTF2);
#asm("sei")
while (1)
{
// Place your code here

}
}

PROTEUS
Discussion

When the main function gets interrupted it pauses and the function in an ISR is carried out. Once its
complete, the main function resumes from where it had left off.

We have also seen how we can change the priority of certain interrupts. This enables us to use the
same microcontroller to carry out multiple unidirectional tasks sequentially based on the ISR’s
priority.

We can use it to make many advanced machines like Robotic arm, CNC router etc.

Drive links

1) Hardware output video:


PART A:
https://drive.google.com/file/d/1fhbavvDET-
9O6npF0iNHbDRxeSrnbsxb/view?usp=share_link
PART B:
https://drive.google.com/file/d/10OQGt1nT9SqtMQ8VZar63LtO1dLHPc4h/view?usp=share_
link
2) Proteus project file:
PART A:
https://drive.google.com/file/d/1kD8Ow7I6vZhI6KbjbSyCkmI1mXpJvA6W/view?usp=share
_link
PART B:
https://drive.google.com/file/d/1DsoAFi7n-wM-
uVrvqYCvPJNX12bzn3cg/view?usp=share_link

You might also like