CNG 336 / EEE 347 Spring 2025-26
CNG 336 Introduction to Embedded Systems Development /
EEE 347 Introduction to Microprocessors
LAB 05 [5%]
Atmega 128 Advanced Assembly Language Programming
[External Interrupt Programming]
Student ID Name Surname
Computer / Electrical & Electronic Engineering Program
Middle East Technical University, North Cyprus Campus
1
CNG 336 / EEE 347 Spring 2025-26
4.1. Lab Objective: To Configure the external interrupt pins of ATmega128, enabling global and
external interrupts.
4.2. Equipment Required:
• AVR Studio
• SimulIDE
4.3. Introduction:
In microcontrollers, an interrupt is a signal that temporarily stops the normal execution of the program
and forces the microcontroller to execute a special function called an Interrupt Service Routine, ISR.
Normally, a microcontroller continuously checks inputs using polling. In polling, the CPU repeatedly
checks whether a button is pressed or not. This wastes CPU time.
With interrupts, the CPU does not need to check the button continuously. When the button is pressed, the
interrupt automatically occurs, and the CPU immediately jumps to the ISR.
For example, if a push button is connected to an external interrupt pin, pressing the button can immediately
turn ON an LED, toggle an output, change LED brightness, or start/stop a motor.
Table 1External Interrupt Pins in ATmega128
Interrupt Pin
INT0 PD0
INT1 PD1
INT2 PD2
INT3 PD3
INT4 PE4
INT5 PE5
INT6 PE6
INT7 PE7
4.3.1. Interrupt Handling and ISR
When an interrupt occurs, the microcontroller automatically jumps to a predefined memory location in
the interrupt vector table, where the corresponding ISR is located. The ISR contains the code that
handles the event, such as updating LED brightness.
To enable interrupts, two conditions must be satisfied:
1. The specific interrupt must be enabled using control registers such as EIMSK.
2. The global interrupt enable bit must be set using the SEI instruction.
The ISR must always end with the RETI instruction, which ensures proper return to the main program
and re-enables interrupt handling.
2
CNG 336 / EEE 347 Spring 2025-26
Lab Example Task:
LED blink with push-button
.include "[Link]"
.org 0x00
; -----------------------------
; Main Program
; -----------------------------
cbi ddra,0
sbi ddra,7
again:
sbis pina,0
rjmp led_off
sbi porta,7
rjmp again
led_off:
cbi porta,7
rjmp again
Figure 1 Push-button operated with microcontroller to control LED
3
CNG 336 / EEE 347 Spring 2025-26
Lab Task 01: (80 Points)
Lab Task: Pedestrian Crossing Control Using External Interrupt
Write an AVR assembly language program for the ATmega128 microcontroller to implement a simple pedestrian
crossing traffic light system using an external interrupt.
Three LEDs representing traffic lights are connected to PORTA pins PA0 (RED), PA1 (YELLOW), and PA2
(GREEN). A push button is connected to the INT0 (PD0) pin to simulate a pedestrian request.
Under normal operation, the system should remain in a default state where the RED LED is continuously ON,
indicating that vehicles are allowed to move.
When the push button is pressed, an external interrupt must be triggered. Upon this event, the system should perform
the following sequence:
• The RED LED turns OFF and the YELLOW LED turns ON for 2 seconds
• After 2 seconds, the YELLOW LED turns OFF and the GREEN LED turns ON for 5 seconds
• After 5 seconds, the system returns to its normal state with the RED LED turned ON
• The push button input must be handled using the external interrupt INT0, and all state transitions must be
implemented within the Interrupt Service Routine (ISR). Polling techniques must not be used.
• Assume that the microcontroller operates with an internal clock frequency of 1 MHz.
Marks Distribution:
• Code: (30 Points)
• Comments: (10 Points)
• Circuit: (30 Points)
• Explanation: (10 Points)
• Pre Lab Quiz: (20 Points)
Total: (100 Points, Weightage 5%)