External Interrupt in Atmega 16
External Interrupt in Atmega 16
External Interrupt in Atmega 16
-KELVIN MANOJ
WHAT IS INTERRUPT ?
Interrupt is very important and powerful concepts and features in microcontroller and microprocessor applications, Almost all the Embedded Application are make use of interrupts.
instructions is suspended by the microcontroller or microprocessor and the code corresponding to the interrupt which has occurred is executed. Once the code corresponding to the interrupt is executed completely the execution again begins from the same instruction where it was stopped.
of the program code that handle the interrupt requests. Each interrupt have an associated ISR. When an Interrupt is triggered, the processor breaks away from the current task, moves the instruction pointer to the ISR, and then continues operation. When the ISR has completed, the processor returns execution to the previous location.
being executed.
When interrupt is occurred program control is transfers to Interrupt
is encountered.
When ISR is over, the microcontroller resumes processing where it left
off before the interrupt occurred, i.e., program control is transfer back to the main program.
ATMEGA16 INTERRUPTS
microcontroller,.
4 are External interrupts and remaining 17 are
Internal interrupts.
Register).
GICR REGISTER
Bit5, Bit6 and Bit7 called the interrupt masks are used to disable/enable the respective interrupt. Interrupt is disabled when bit value is set to 0 and enabled when bit value is set to 1. By default all the interrupts are disabled.
I-bit (Bit7, Global Interrupt Enable) of SREG register must also be set to 1. If Global Interrupt enable bit is set to 0, none of the interrupts will work irrespective of the other register settings. The set and clear of I-bit is done by SEI and CLI instructions.
MCUCR REGISTER
MCUCSR REGISTER
Clear Global Interrupt enable bit in SREG register. Initialize the interrupt by appropriately configuring the
the interrupt.
#define ISR(vector,attributes)
#define SIGNAL(vector) #define sei() #define cli() #define reti()
ISR for INT0 can be written in following two ways: ISR (INT0_vect) SIGNAL (SIG_INTERRUPT0)
PROGRAM:
#include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> ISR (INT0_vect) { PORTA = ~PORTA; _delay_ms(100); } int main(void) { DDRA = 0xFF; PORTA = 0xFF; cli(); GICR =(1<<INT0); MCUCR =(3<<ISC00); sei(); while(1); } //io port registers //to use delay function //interrupt macros eg. sei(), cli().. //ISR for INT0 //toggle PORTA //wait time for toggle
//configure PORTA as output port //Make all 8 pins in PORTA High //Disable Global Interrupts //Set Bit6 of GICR to unmask INT0 interrupt. //Configuring MCUCR for Rising Edge interrupt for INT0 //Enable Global Interrupts
CIRCUIT:
Sensors like proximity sensor, Heart beat sensor, reed switch etc..
It is efficient to write a code for External Interrupts whenever
THANK YOU