Aim:
Although micro controllers can accept inputs from Digital I/O
Ports,interrupts are preferred for accepting inputs generated by
external events. This is mainly because of the less attention required
for an interrupt based program. An Interrupt Event directs the flow of
program execution to a totally independent piece of code, known as
“Interrupt Sub-Routine”. There are many sources of Interrupts that are
available for a micro controller. Most of them are generated by the
internal modules and are known as internal interrupts. And there are two
pins that accept external signals directly and allows external sources
to generate interrupts.
Description:
External interrupts are fairly powerful, they can be configured to
trigger on one of 4 states. Low level will trigger whenever the pin
senses a LOW (GND) signal. Any Logic Change trigger at the moment the
pin changes from HIGH (Vcc) to LOW (GND) or from LOW (GND) to HIGH(Vcc).
On Falling Edge will trigger at the moment the pin goes from HIGH (Vcc)
to LOW (GND). On Rising Edge will trigger at the moment the pin goes
from LOW (GND) to HIGH (Vcc). The best part is that you can configure
each INTx independently.
External interrupts use the below 3 registers. Which you could find under the “External Interrupts section of the datasheet.
7 bit | 6 bit | 5 bit | 4 bit | 3 bit | 2 bit | 1 bit | 0 bit | |
MCUCR | SE | SM2 | SM1 | SM0 | ISC11 | ISC10 | ISC01 | ISC00 |
MCU Control Register
ISCx1 | ISCx0 | DESCRIPTION |
0 | 0 | Low level of INTx generates an interrupt request |
0 | 1 | Any logic change on INTx generates an interrupt request |
1 | 0 | The falling edge of INTx generates an interrupt request |
1 | 1 | The rising edge of INTx generates an interrupt request |
ISC Bits Settings
7 bit | 6 bit | 5 bit | 4 bit | 3 bit | 2 bit | 1 bit | 0 bit | |
GICR | INT1 | INT0 | – | – | – | – | IVSEL | IVCE |
General Interrupt Control Register
7 bit | 6 bit | 5 bit | 4 bit | 3 bit | 2 bit | 1 bit | 0 bit | |
GIFR | INTF1 | INTF0 | – | – | – | – | – | – |
General Interrupt Flag Register
When the event specified by the Interrupt Sense Control (ISCxy) bits in
the MCU Control Register (MCUCR) is sensed on the INTx pin, the External
Interrupt Flag x (INTFx) in the General Interrupt Flag Register
(GIFR) is set HIGH (1). If the I-bit in SREG and the INT1 bit in the
GICR are both HIGH(1) the MCU will jump to the corresponding vector.
The Flag is set to LOW (0) when the INTx_vect routine is executed.
Block Diagram
Schematic
Code
// ****************************************************** // Project: Interfacing external interrupt to atmega8 // Author: Hack Projects India // Module description: Operate single LED // ****************************************************** #define F_CPU 8000000UL #include <avr/io.h> #include<util/delay.h> #include <avr/interrupt.h> ISR(INT0_vect) { cli(); PORTB=0x01; _delay_ms(1000); PORTB=0x00; _delay_ms(1000); sei(); } int main(void) { DDRB=0xff; DDRD=0x00; MCUCR=0x03; GICR=(1<<INT0); SREG=0x80; while(1); }
Downloads:
The code was compiled in Atmel Studio 6 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.
Further Reading suggestions:
You may also like,
- Interfacing keypad with AVR
- nterfacing DAC with AVR
- Interfacing with UART of AVR controller
- Interfacing SPI communication with AVR
- AVR Displaying Custom Characters on LCD
- AVR Graphical LCD
- RTC interfacing using I2C in AVR
- Interfacing ultrasonic sensor with AVR
- Interfacing GPS Modu with AVR
- Interfacing GSM Module with AVR
- Interfacing PWM in AVR
- Interfacing ADC with AVR
- Scrolling string on LCD using AVR
- Interfacing keypad with AVR
- nterfacing DAC with AVR
- Interfacing with UART of AVR controller
- Interfacing SPI communication with AVR
- AVR Displaying Custom Characters on LCD
- AVR Graphical LCD
- RTC interfacing using I2C in AVR
- Interfacing ultrasonic sensor with AVR
- Interfacing GPS Modu with AVR
- Interfacing GSM Module with AVR
- Interfacing PWM in AVR
- Interfacing ADC with AVR
- Scrolling string on LCD using AVR
No comments:
Post a Comment