Accessing External Interrupts in AVR Primer

Accessing External Interrupts in AVR Primer

Tags: Interfacing External Interrupts with AVR, Circuit Diagram for ExtInterrupt with AVR C Program to interface ExtInterrupt in AVR,
Overall rating
AVR Primer Board

The AVR Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports In-system programming (ISP) which is done through Parallel/Printer port.

ATMEL’s AVR (Atmega8535), AVR Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

External Interrupts

A set of interrupt that occurs when there is a change in pin state of a microcontroller. Interrupts are special events that require immediate attention. Also we can set them to trigger whenever

  • The pin is low
  • There is any change on the pin
  • When the pin goes from high to low
  • When the pin goes from low to high

By using external interrupt we can say many things related to that signal on the corresponding pin of the microcontroller.

Interfacing External Interrupts

Fig. 1 shows how to interface the External Interrupt to microcontroller. Interrupts cause the processor to cease the running task to serve a special task for which the interrupt event had occurred. After the special task is over, the processor resumes performing the original task.

The processor can also serve these events by polling method. But polling is an inefficient technique as compared to interrupts. In the polling method, the processor has to continuously wait for the event signal. Thus it always remains busy using extra resources.


Fig. 1 Interfacing External Interrupts to Microcontroller

Interfacing External Interrupts with AVR Primer

We now want to display some messages in PC when occur an external interrupt signal in AVR Primer Board. The Interrupt signal is occurred by using switches. When the switch is pressed to LOW, then the external interrupt is occurred.

The AVR Primer board has three External Interrupt, connected with I/O Port line PORTD.2, PORTD.3, PORTB.2, as a switch.

Pin Assignment with AVR Primer






Press INT0, INT1 and INT2 Push button switches SW2, SW3 and SW4

Connect Serial cable between USARTSection in the Board and PC.

The Message “INTx Detected...” will

be displayed.

In INTx, x is 0 or 1 or 2.






Circuit Diagram for Ext-Interrupt with AVR


Source Code

The Interfacing External Interrupt with AVR Primer program is very simple and straight forward, that accessed by using switches. When anyone of the three external interrupts occurring, some messages are displayed in PC through serial port at 9600 baud rate. The C programs are written in CodeVision AVR Software.

C Program to interface Ext-Interrupt using AVR Primer


Title : Program to interface an external Interrupt







#define INT0 GIFR = 0x40

#define INT1 GIFR = 0x80

#define INT2 GIFR = 0x20


#define TXIF        UCSRA.5

#define FOSC        16000000L                            //Oscillator Frequency  16Mhz 

#define USART_Baud  9600                                                

#define BaudH       ((unsigned int)(((FOSC/16/USART_Baud)-1) >> 8))

#define BaudL       ((unsigned int)(((FOSC/16/USART_Baud)-1) & 0xFF))


void Interrupt_init(void);

void Serial_init(void);


void main()







            printf("Interrupt Demo Program:\n\r");       




void Interrupt_init(void)


        DDRB  = 0x00;

                PORTB = 0xff;     

                DDRD  = 0x00;

                PORTD = 0xff;


        MCUCR  = 0x0a;

        MCUCSR = 0x00;

        GICR   = 0xe0;

        GIFR   = 0xe0;   




void Serial_init(void)


     UCSRA = 0x00;                //Status Register

     UCSRB = 0x18;                //Transmit Enable,Receive enable,interrupts disabled   

     UCSRC = 0x86;                //8 databits,no parity,single stop   

     UBRRH = BaudH;

     UBRRL = BaudL;          



#define _ALTERNATE_PUTCHAR_       


void putchar(unsigned char Data)


    UDR = Data;     



interrupt [EXT_INT0] void ext_int0_isr(void)


        printf("INT0 Detected...\r");      





interrupt [EXT_INT1] void ext_int1_isr(void)


        printf("INT1 Detected...\r");   





interrupt [EXT_INT2] void ext_int2_isr(void)


        printf("INT2 Detected...\r"); 





To compile the above C code you need the CodeVision AVR software. The software has it’s own IDE and built-in AVR gcc- Compiler. They must be properly installed and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In CodeVision AVR software, you can develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without microcontroller Board.

The AVR Code Blaster software is used to download the hex file into your microcontroller through Parallel port.

Testing the External Interrupts with AVR Primer

Give +12V power supply to AVR Primer Board; the serial cable is connected between the AVR Primer Board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show which external interrupt is selected.

When you pressed the external interrupt key, the screen should update which interrupt is now pressed. The Interrupts are controlled by using switches. If any data is not coming in Hyper Terminal, then you just check the serial cable is working or not. Otherwise you just check the code with debugging mode in CodeVisionAVR.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.

Join the World's Largest Technical Community

we respect your privacy.