Interrupts in Atmega328P
(Lecture-13)
R S Ananda Murthy
Associate Professor and Head
Department of Electrical & Electronics Engineering,
Sri Jayachamarajendra College of Engineering,
Mysore 570 006
R S Ananda Murthy Interrupts in Atmega328P
Methods of I/O Operation
Synchronous I/O operation.
This is possible when the I/O device operates at the same
speed as that of MCU.
In this case the I/O operation with the device is performed
by the MCU assuming that the device is always ready.
Asynchronous I/O Operation.
In this case, generally the I/O device is very slow when
compared to the MCU. Then, it can perform I/O operation
by the following methods:
By polling.
By using interrupts.
R S Ananda Murthy Interrupts in Atmega328P
I/O Operation by Polling
Is
the device
ready
?
Request device to get ready
Service the device
No
Yes
Polling results in waste of MCU time and power and does
not permit masking of devices since all devices have to be
checked.
R S Ananda Murthy Interrupts in Atmega328P
Polling Example
R S Ananda Murthy Interrupts in Atmega328P
I/O Operation by Interrupts
The MCU keeps on doing some useful operation, or it
remains in a low-power state after enabling interrupts.
When I/O device is ready, it interrupts the MCU.
The MCU completes execution of the current instruction,
saves the return address on the stack, and then jumps to
the Interrupt Service Routine (ISR) to serve the device.
After this, the MCU returns back to the interrupted program
by loading the return address from the stack to the
Program Counter.
Interrupts can be enabled or disabled dynamically and
when multiple interrupts come simultaneously priorities
can be assigned.
R S Ananda Murthy Interrupts in Atmega328P
Interrupt Example
R S Ananda Murthy Interrupts in Atmega328P
Default Interrupt Vectors in Atmega328P
R S Ananda Murthy Interrupts in Atmega328P
Interrupt Vectors in Atmega328P
Interrupt vector is a definite address in the program
memory where a JMP instruction should be written to jump
to the ISR corresponding to the interrupt.
Each interrupt vector occupies two program memory words
in order to provide space for JMP instruction.
In Atmega328P, the RESET Vector is affected by
BOOTRST fuse and the Interrupt Vector start address is
affected by IVSEL bit in the MCUCR.
R S Ananda Murthy Interrupts in Atmega328P
Enabling and Disabling Interrupts in Atmega328P
In SREG if I = 1, then all interrupts are enabled.
We can make I = 1 by using SEI instruction in ALP and
sei() function in C program.
In SREG if I = 0, then all interrupts are disabled.
We can make I = 0 by using CLI instruction in ALP and
cli() function in C program.
Upon reset I = 0 so all interrupts are disabled.
R S Ananda Murthy Interrupts in Atmega328P
Bits of EICRA Control Nature of INT1 and INT0
Bits 7, 6, 5, and 4 are not used and are always read as 0.
R S Ananda Murthy Interrupts in Atmega328P
Bits of EIMSK Mask/Unmask INT1 and INT0
Masking/unmasking means disabling/enabling respectively.
When INT1 = 1 INT1 is unmasked if I = 1 in SREG.
When INT1 = 0 INT1 is masked even if I = 1 in SREG.
When INT0 = 1 INT0 is unmasked if I = 1 in SREG.
When INT0 = 0 INT0 is masked even if I = 1 in SREG.
Activity on the pins of INT1/INT0 will cause an interrupt
request even if the corresponding pins are configured as
output pins.
Bits 2 to 7 are unused and will always be read as 0.
R S Ananda Murthy Interrupts in Atmega328P
Bits of EIFR Show Status of INT1 and INT0
Bits 2 to 7 are unused and will always be read as 0.
When INT1 interrupt is triggered, INTF1 becomes 1. This
flag is cleared when ISR is executed.
When INT0 interrupt is triggered, INTF0 becomes 1. This
flag is cleared when ISR is executed.
INTF1/INTF0 flags can be cleared by writing a logical 1 to
the respective bit.
INTF1/INTF0 flags are always cleared when the respective
interrupts are configured as a level interrupt.
R S Ananda Murthy Interrupts in Atmega328P
C-Code to use INT0
R S Ananda Murthy Interrupts in Atmega328P
Problem Statement to use INT0/INT1
Assume that a push button is connected to the INT0/PD2 pin of
Atmega328P MCU with internal pull-up resistor enabled and
that a 7-segment common cathode display is connected to
PORTB lines of the MCU through 330Ω current limiting
resistors. Let a high-to-low logic change on this pin cause an
INT0 interrupt. Sketch a diagram showing the hardware
connections. Write a program in C which displays on the LED
display any integer in the range 1 to 6, both inclusive, when
ever the push button is pressed, thus simulating throwing of a
die. Sketch a flow chart to show the logic.
Also write ALP to achieve the task mentioned above.
Modify the programs written above to use INT1/PD3.
R S Ananda Murthy Interrupts in Atmega328P
License
This work is licensed under a
Creative Commons Attribution 4.0 International License.
R S Ananda Murthy Interrupts in Atmega328P

More Related Content

PDF
L15 timers-counters-in-atmega328 p
PDF
L12 c-language-programming-of-atmega328 p
PPTX
8051 memory
PPTX
LPC 2148 ARM MICROCONTROLLER
PDF
Unit IV DA & AD Convertors and Phase Locked Loop
PPT
AUTOMATIC FIRE ALARM using IR LED and BUZZER
PPTX
Counters & time delay
PPTX
RTC Interfacing and Programming
L15 timers-counters-in-atmega328 p
L12 c-language-programming-of-atmega328 p
8051 memory
LPC 2148 ARM MICROCONTROLLER
Unit IV DA & AD Convertors and Phase Locked Loop
AUTOMATIC FIRE ALARM using IR LED and BUZZER
Counters & time delay
RTC Interfacing and Programming

What's hot (20)

PPTX
Bidirect visitor counter
PPT
PPTX
ARDUINO BASED HEART BEAT MONITORING SYSTEM
PDF
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
PDF
Project report on bidirectional visitor counter & home automation
PPTX
Basics of open source embedded development board (
PDF
Arduino IDE
PPTX
Automatic room light controller with bi directional visitor counter using Ard...
PPTX
Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
PPTX
Key board interfacing with 8051
PDF
Digital Alarm Clock 446 project report
PPTX
module 1.pptx
PPTX
Divide by N clock
DOCX
Bidirectional Visitor counter Project Proposal
PPTX
Lecture 1.pptx
PPTX
Interrupt in 8051
PPT
Microcontroller 8051
PPTX
ATMEGA 328
Bidirect visitor counter
ARDUINO BASED HEART BEAT MONITORING SYSTEM
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Project report on bidirectional visitor counter & home automation
Basics of open source embedded development board (
Arduino IDE
Automatic room light controller with bi directional visitor counter using Ard...
Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
Key board interfacing with 8051
Digital Alarm Clock 446 project report
module 1.pptx
Divide by N clock
Bidirectional Visitor counter Project Proposal
Lecture 1.pptx
Interrupt in 8051
Microcontroller 8051
ATMEGA 328
Ad

Viewers also liked (20)

PDF
Lecture-1 : Introduction to Power Electronics
PDF
Trends in-power-electronics
PDF
L5 data-parallel-computers
PDF
L6 primary-memory
PDF
L1 intro-to-mpu-mcu
PDF
Introduction to-Tex-and-LaTeX
PDF
Transformers
PDF
L4 speeding-up-execution
PDF
Lecture-5 : Semiconductor Power Switching Devices-2
PDF
L3 instruction-execution-steps
PDF
L7 starting-to-use-mcu
PDF
Lecture-3 : More Applications of Power Electronics
PDF
Lecture-7 : Semiconductor Power Switching Devices-4
PDF
Lecture-2 : Applications of Power Electronics
PDF
L14 kb-lcd-interfacing-with-atmega328 p
PDF
Three phase-circuits
PDF
L9 understanding-atmega328 p-2
PDF
L16 usart-atmega328 p
PDF
L8 understanding-atmega328 p-1
PDF
Synchronous generators
Lecture-1 : Introduction to Power Electronics
Trends in-power-electronics
L5 data-parallel-computers
L6 primary-memory
L1 intro-to-mpu-mcu
Introduction to-Tex-and-LaTeX
Transformers
L4 speeding-up-execution
Lecture-5 : Semiconductor Power Switching Devices-2
L3 instruction-execution-steps
L7 starting-to-use-mcu
Lecture-3 : More Applications of Power Electronics
Lecture-7 : Semiconductor Power Switching Devices-4
Lecture-2 : Applications of Power Electronics
L14 kb-lcd-interfacing-with-atmega328 p
Three phase-circuits
L9 understanding-atmega328 p-2
L16 usart-atmega328 p
L8 understanding-atmega328 p-1
Synchronous generators
Ad

Similar to L13 interrupts-in-atmega328 p (20)

PPTX
Interrupt in ATMEGA328P.pptx
PPT
Interrupt
PPT
Interrupt11
PPTX
Chapter 4 - Interrupts of 8085
PPTX
Interrupt 8085
PPT
Types of Interrupts with details Mi ppt
PDF
Microcontroller 8085.ppt mmmmmmmmmmmmmmmmmm
PDF
8085 interrupts
PDF
8085 interrupts
PPT
8051 Inturrpt
PPT
8085 interrupts
PPTX
Interrupts
PPT
Interruptsof8085
PPT
Interrupts
PPTX
Interrupts of 8085
PPTX
Interrupts of microprocessor 8085
DOCX
pdf-obstacle-avoiding-robot.docx
PPT
Drivers2
PPT
Drivers2
PPTX
8085 interrupts
Interrupt in ATMEGA328P.pptx
Interrupt
Interrupt11
Chapter 4 - Interrupts of 8085
Interrupt 8085
Types of Interrupts with details Mi ppt
Microcontroller 8085.ppt mmmmmmmmmmmmmmmmmm
8085 interrupts
8085 interrupts
8051 Inturrpt
8085 interrupts
Interrupts
Interruptsof8085
Interrupts
Interrupts of 8085
Interrupts of microprocessor 8085
pdf-obstacle-avoiding-robot.docx
Drivers2
Drivers2
8085 interrupts

Recently uploaded (20)

PDF
Mechanics of materials week 2 rajeshwari
PPT
Programmable Logic Controller PLC and Industrial Automation
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPTX
MAD Unit - 3 User Interface and Data Management (Diploma IT)
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
PPTX
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
PDF
Unit1 - AIML Chapter 1 concept and ethics
PPTX
Software Engineering and software moduleing
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
Solar energy pdf of gitam songa hemant k
PDF
Project_Mgmt_Institute_-Marc Marc Marc .pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
Mechanics of materials week 2 rajeshwari
Programmable Logic Controller PLC and Industrial Automation
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
distributed database system" (DDBS) is often used to refer to both the distri...
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
August -2025_Top10 Read_Articles_ijait.pdf
MAD Unit - 3 User Interface and Data Management (Diploma IT)
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
Beginners-Guide-to-Artificial-Intelligence.pdf
Micro1New.ppt.pptx the mai themes of micfrobiology
Amdahl’s law is explained in the above power point presentations
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
Unit1 - AIML Chapter 1 concept and ethics
Software Engineering and software moduleing
MLpara ingenieira CIVIL, meca Y AMBIENTAL
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Solar energy pdf of gitam songa hemant k
Project_Mgmt_Institute_-Marc Marc Marc .pdf
Management Information system : MIS-e-Business Systems.pptx

L13 interrupts-in-atmega328 p

  • 1. Interrupts in Atmega328P (Lecture-13) R S Ananda Murthy Associate Professor and Head Department of Electrical & Electronics Engineering, Sri Jayachamarajendra College of Engineering, Mysore 570 006 R S Ananda Murthy Interrupts in Atmega328P
  • 2. Methods of I/O Operation Synchronous I/O operation. This is possible when the I/O device operates at the same speed as that of MCU. In this case the I/O operation with the device is performed by the MCU assuming that the device is always ready. Asynchronous I/O Operation. In this case, generally the I/O device is very slow when compared to the MCU. Then, it can perform I/O operation by the following methods: By polling. By using interrupts. R S Ananda Murthy Interrupts in Atmega328P
  • 3. I/O Operation by Polling Is the device ready ? Request device to get ready Service the device No Yes Polling results in waste of MCU time and power and does not permit masking of devices since all devices have to be checked. R S Ananda Murthy Interrupts in Atmega328P
  • 4. Polling Example R S Ananda Murthy Interrupts in Atmega328P
  • 5. I/O Operation by Interrupts The MCU keeps on doing some useful operation, or it remains in a low-power state after enabling interrupts. When I/O device is ready, it interrupts the MCU. The MCU completes execution of the current instruction, saves the return address on the stack, and then jumps to the Interrupt Service Routine (ISR) to serve the device. After this, the MCU returns back to the interrupted program by loading the return address from the stack to the Program Counter. Interrupts can be enabled or disabled dynamically and when multiple interrupts come simultaneously priorities can be assigned. R S Ananda Murthy Interrupts in Atmega328P
  • 6. Interrupt Example R S Ananda Murthy Interrupts in Atmega328P
  • 7. Default Interrupt Vectors in Atmega328P R S Ananda Murthy Interrupts in Atmega328P
  • 8. Interrupt Vectors in Atmega328P Interrupt vector is a definite address in the program memory where a JMP instruction should be written to jump to the ISR corresponding to the interrupt. Each interrupt vector occupies two program memory words in order to provide space for JMP instruction. In Atmega328P, the RESET Vector is affected by BOOTRST fuse and the Interrupt Vector start address is affected by IVSEL bit in the MCUCR. R S Ananda Murthy Interrupts in Atmega328P
  • 9. Enabling and Disabling Interrupts in Atmega328P In SREG if I = 1, then all interrupts are enabled. We can make I = 1 by using SEI instruction in ALP and sei() function in C program. In SREG if I = 0, then all interrupts are disabled. We can make I = 0 by using CLI instruction in ALP and cli() function in C program. Upon reset I = 0 so all interrupts are disabled. R S Ananda Murthy Interrupts in Atmega328P
  • 10. Bits of EICRA Control Nature of INT1 and INT0 Bits 7, 6, 5, and 4 are not used and are always read as 0. R S Ananda Murthy Interrupts in Atmega328P
  • 11. Bits of EIMSK Mask/Unmask INT1 and INT0 Masking/unmasking means disabling/enabling respectively. When INT1 = 1 INT1 is unmasked if I = 1 in SREG. When INT1 = 0 INT1 is masked even if I = 1 in SREG. When INT0 = 1 INT0 is unmasked if I = 1 in SREG. When INT0 = 0 INT0 is masked even if I = 1 in SREG. Activity on the pins of INT1/INT0 will cause an interrupt request even if the corresponding pins are configured as output pins. Bits 2 to 7 are unused and will always be read as 0. R S Ananda Murthy Interrupts in Atmega328P
  • 12. Bits of EIFR Show Status of INT1 and INT0 Bits 2 to 7 are unused and will always be read as 0. When INT1 interrupt is triggered, INTF1 becomes 1. This flag is cleared when ISR is executed. When INT0 interrupt is triggered, INTF0 becomes 1. This flag is cleared when ISR is executed. INTF1/INTF0 flags can be cleared by writing a logical 1 to the respective bit. INTF1/INTF0 flags are always cleared when the respective interrupts are configured as a level interrupt. R S Ananda Murthy Interrupts in Atmega328P
  • 13. C-Code to use INT0 R S Ananda Murthy Interrupts in Atmega328P
  • 14. Problem Statement to use INT0/INT1 Assume that a push button is connected to the INT0/PD2 pin of Atmega328P MCU with internal pull-up resistor enabled and that a 7-segment common cathode display is connected to PORTB lines of the MCU through 330Ω current limiting resistors. Let a high-to-low logic change on this pin cause an INT0 interrupt. Sketch a diagram showing the hardware connections. Write a program in C which displays on the LED display any integer in the range 1 to 6, both inclusive, when ever the push button is pressed, thus simulating throwing of a die. Sketch a flow chart to show the logic. Also write ALP to achieve the task mentioned above. Modify the programs written above to use INT1/PD3. R S Ananda Murthy Interrupts in Atmega328P
  • 15. License This work is licensed under a Creative Commons Attribution 4.0 International License. R S Ananda Murthy Interrupts in Atmega328P