Professional Documents
Culture Documents
Exp 4
Exp 4
Exp 4
Lab Report
Section: 01 Group No: 10
Experiment no: 04
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;
#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