0% found this document useful (0 votes)
4 views7 pages

Lab 10 - Group11 - ShaheerAsghar - SaadRabani - HuzyephaJavaid - BahramJamalKhan

The document outlines Lab 1 for the EE-222 Microprocessor Systems course, focusing on AVR hardware interrupts using the ATmega328p microcontroller. Students are expected to code hardware interrupts, submit commented code, and perform calculations related to timer values. The lab emphasizes efficient scheduling and event handling in embedded systems through the implementation of interrupt service routines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Lab 10 - Group11 - ShaheerAsghar - SaadRabani - HuzyephaJavaid - BahramJamalKhan

The document outlines Lab 1 for the EE-222 Microprocessor Systems course, focusing on AVR hardware interrupts using the ATmega328p microcontroller. Students are expected to code hardware interrupts, submit commented code, and perform calculations related to timer values. The lab emphasizes efficient scheduling and event handling in embedded systems through the implementation of interrupt service routines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Department of Electrical Engineering

Faculty Member: Muhammad Adnan Dated: 14/5/2025

Semester: 4th Section: BEE-15D

EE-222: Microprocessor Systems

Lab 1: AVR Hardware Interrupts

PLO4-CLO3 PLO3- PLO8- PLO9-


CLO4 CLO5 CLO6
Student Name Reg. No Viva / Analysis Modern Ethics Individual
Quiz / Lab of data Tool and and Team
Performa in Lab Usage Safety Work
nce Report

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks


Huzyepha Javaid 467747

Shaheer Asghar 456020

Bahram Jamal Khan 476706

Saad Rabbani 463533

EE-222: Microprocessor Systems Page 1


1. Acknowledgements
This lab exercise is prepared by Lab Engr. Shaiza for the course EE-222 Microprocessor Systems.
Reporting any errors or discrepancies found in the text is appreciated.

2. Administrivia

2.1. Learning Outcomes


By the end of this lab you will be able to:

• Code hardware interrupts for efficient scheduling in ATmega328p.

2.2. Deliverable
You are required to submit:
•Appropriately Commented Code

•Explicit Calculations for Timer Values

•Issues in Developing the Solution and your Response in the beginning of next lab

2.3.Hardware Resources
• Arduino Uno board with ATmega328p microcontroller

• Arduino USB cable

• Universal Programmer

• Seven Segment Display x2

• Resistance 47Ω x2

• Switch

EE-222: Microprocessor Systems Page 2


3. Interrupts
In this lab, hardware interrupts are utilized to enable communication between microcontrollers and
external devices. Hardware interrupts allow the microcontroller to respond immediately to external
signals, pausing its current tasks to handle the interrupt before resuming its normal operations.

3.1. Hardware Interrupts


The ATmega328P has two external hardware interrupts, which are:

1. INT0: Pin PD2 (PORTD.2)

2. INT1: Pin PD3 (PORTD.3)

In addition, the ATmega328P has an additional external interrupt source, but it is handled differently
compared to the dedicated INT0 and INT1 pins. Specifically:

• PCINT (Pin Change Interrupts) can be triggered on several pins in PORTB, PORTC, and
PORTD.

Task 1:
Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

int counter_e = 0;
int counter_o = 1;
void display_number(int n);
void display_even();
void display_odd();
void delay();

int main()
{

EE-222: Microprocessor Systems Page 3


DDRB = 0xFF; // For tens
DDRC = 0xFF; // For ones
DDRA = 0xFF; // For pins
DDRD = 0x00;
GICR = (1<<INT0) | (1<<INT1);
MCUCR = (1<<ISC00 ) | (1<<ISC10);

delay();
display_number(0);
PORTA = 0xFF;

sei();
while(1)
{
if(counter_e > 2)
{
counter_e = 0;
}
if(counter_o > 2)
{
counter_o = 1;
}
}
}
ISR(INT0_vect)
{
display_even();
_delay_ms(1000);
counter_e += 2;
}
ISR(INT1_vect)
{
display_odd();
_delay_ms(1000);
counter_o += 2;
}
void display_number(int n)
{
int a, b;

EE-222: Microprocessor Systems Page 4


a = n / 10;
b = n % 10;

{
if (a==0) {PORTB = 0xC0;}
if (a==1) {PORTB = 0xF9;}
if (a==2) {PORTB = 0xA4;}
if (a==3) {PORTB = 0xB0;}
if (a==4) {PORTB = 0x99;}
if (a==5) {PORTB = 0x92;}
if (a==6) {PORTB = 0x82;}
if (a==7) {PORTB = 0xF8;}
if (a==8) {PORTB = 0x80;}
if (a==9) {PORTB = 0x90;}
{
if (b==0) {PORTC = 0xC0;}
if (b==1) {PORTC = 0xF9;}
if (b==2) {PORTC = 0xA4;}
if (b==3) {PORTC = 0xB0;}
if (b==4) {PORTC = 0x99;}
if (b==5) {PORTC = 0x92;}
if (b==6) {PORTC = 0x82;}
if (b==7) {PORTC = 0xF8;}
if (b==8) {PORTC = 0x80;}
if (b==9) {PORTC = 0x90;}
}
}
}
void display_even()
{
display_number(counter_e);
PORTA = 0b10101010;
}
void display_odd()
{
display_number(counter_o);
PORTA = 0b01010101;
}
void delay()

EE-222: Microprocessor Systems Page 5


{
TCNT1 = 0;
OCR1A = 46875;
TCCR1A = 0;
TCCR1B = 0x0B;
while (TIFR && 1<<OCF1A == 0)
{

}
TCCR1B = 0;
TIFR = 1<<OCF1A;
}

Output and Hardware:

EE-222: Microprocessor Systems Page 6


Conclusion:
In this lab, we implemented hardware interrupts in the ATmega16A microcontroller for efficient
scheduling. By setting up interrupt service routines, we were able to handle external events without
constant polling. This approach improves system efficiency, especially in real-time applications where
timing is critical. Overall, the lab provided valuable experience in interrupt-driven programming and
event handling for embedded systems.

EE-222: Microprocessor Systems Page 7

You might also like