3
Most read
4
Most read
6
Most read
INTERRUPTS
Prepared by:

Islam Samir
Interrupts
INTERRUPT

-

Definition:
An interrupt is an asynchronous signal indicate for an
event which needs processor’s attention immediately
regardless to the instruction it executes at this moment.

It’s like a
Doorbell.
WHY DO WE USE INTERRUPTS?
Example. (Software Polling)
Assume that the MCU is supposed to do two tasks.
-

In one of them, it needs to know if a certain I/O pin is „1‟ or not yet.

-

We can do so by checking if this pin is „1‟ or „0‟, which called
“Polling”.

-

By this method, the MCU is doing nothing but waiting for the pin to
be high, the 2nd task can‟t be done in this time.

 Wasting MCU’s time.
-

If the MCU left this task to do the 2nd task. While executing it, the pin
became high. It won‟t know (the check won‟t be done) until it leaves
the 2nd task.

 Slow response to important events.
INTERRUPT


Instead of checking each pin constantly (polling) and wasting the
processor’s time, the MCU waits for the interrupt signal that
indicates for the waited event.



When this interrupt signal equals ‘1’ :
The MCU leaves the current program.
Executes the predefined code for this event and returns back to
the original program.

I.

II.
COMPARISON
Interrupts

Software Polling

Save processor‟s time.

Waste processor‟s time.

Fast response from the CPU to the
event that has happened

The processor‟s response depends
on where it‟s in the program.

Can‟t be used with switches or
sensors. (because of Bouncing)

Used with switches or sensors

Ex. Timers.

Ex. Switches.
INTERRUPT DEFINITIONS

-


-


-

Interrupt Flag (IF):
A bit that is automatically set if the interrupt source (event) happens.
Global Interrupt Enable (GIE):
Enables (if set) all un-masked interrupts (interrupts with IE=1) or disables
(if cleared) all interrupts.
Interrupt Enable (IE):
If the GIE was ‘1’, this bit forces the CPU to respond to the interrupt signal
when IF=1  when the waited event happens.
Interrupts
INTERRUPT DEFINITIONS

-

-

-

Interrupt service routine (ISR):
The code which the CPU jumps to when an interrupt happens.
Actually, the CPU will automatically jumps to the (interrupt vector)
0004h.
From there the code should be written to force the MCU to jump to
the ISR address.
INTERRUPTS


1)

2)

3)

When the event (interrupt source) happens, the following steps happen:

The corresponding interrupt flag (IF) will equal ‘1’.
If the interrupt enable (IE) was ‘1’, and the global interrupt enable
(GIE) was ‘1’ also, the GIE is cleared by hardware to avoid
responding any further interrupt
The return address is pushed into the stack and the PC is loaded with
0004h (the interrupt vector).
INTERRUPTS
4)

In the ISR, you can determine the source of interrupt by polling the
interrupt flag bits and do the required action for it.

5)

(Context Switching) You have to save key registers values before
interrupt has happened e.g. W register and STATUS register. This has
to be implemented in software
If you use high level language the compiler will do it for you.

-

4)

At the end of the ISR, you’ve to clear the IF in software then set the
GIE bit in the end of the ISR code.
Interrupts
HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?
If interrupts are not used, the control unit goes through the
ordinary instruction cycle:
I.
Fetch instruction. ( Ins. register<--M[PC] ).
II.
Decode the instruction.
III. Execute it.

HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?


When interrupts are used in the microprocessor, the control
unit checks first if there is an interrupt signal or not.

If the interrupt signal was „1‟, it goes through interrupt cycle:
I.
Store the current address into the stack.

(the address of the next instruction which should have been
loaded if there is no interrupt).
II.
Load the PC with the interrupt vector address.
III. Make the GIE=„0‟.

Interrupt
signal?
T

F

Interrupt cycle

Instruction cycle

Stack <-- return address

PC <-- Interrupt vector

In
S.W., m
ake
IF=0

GIE=0

Fetch

Decode

Execute
HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?


The last instruction in the ISR should be:
RETFIE (return from interrupt).



This instruction makes the control unit loads the PC with the address
stored in the stack so that the original program can continue.
INTERRUPT SOURCES IN THE PIC 16 MCU


INT Pin Interrupt (external interrupt)



TMR0 Overflow Interrupt



PORTB Change Interrupt (pins RB7:RB4)



Comparator Change Interrupt



Parallel Slave Port Interrupt



USART Interrupts



Receive Interrupt



Transmit Interrupt



A/D Conversion Complete Interrupt



Data EEPROM Write Complete Interrupt



Timer1 Overflow Interrupt



Timer2 Overflow Interrupt



CCP Interrupt



SSP Interrupt
INTERRUPT SOURCES
-

-

Many peripherals use interrupts when finishing its job (ex.
USART, ADC, Timers …), or when there is a problem needs to
be configured (ex. EEPROM Write Complete ).
Here, we’ll talk about the simplest type of interrupt, and the
rest of interrupt sources should be handled in the same way.

Very important:
 If you configure the MCU to respond to more than one
interrupt source at the same time, to determine which one has
happened, pull their flags in the ISR (check which one equals
1).
RB0/INT


The RB0/INT pin is a single external interrupt source.



When the waited edge rising or falling edge as selected)
happens on RB0 pin, the interrupt signal is generated.



It can be configured to react to signal raising edge or signal
falling edge.
RB0/INT
Steps:
1.
Configure the interrupt source to work as you want, here :
falling or rising edge.



2.

Set the IE bit of this interrupt source.

3.

Write the Interrupt Service Routine (ISR).

4.

Set the GIE bit.
EXAMPLE



Make the led illuminates when the button is pressed, using
RB0 interrupt.
ASSIGNMENT

-

Make an application using interrupts,
detects raising edge signals on RB0,
and detect any change happens is PORTB <7:4> and
respond to it as specified in the next table:
PORTB<7:4>

PORTC<7:4>

xxx1

xxx1

xx1x

xx1x

x1xx

x1xx

1xxx

1xxx

More Related Content

PPT
Input output module
PPTX
Interrupt presentaion
PPT
Bus interconnection
PPTX
Microprogrammed Control Unit
PPS
Interrupts
PPT
Instruction cycle
PPTX
Interrupts ppt
PPTX
Instruction cycle with interrupts
Input output module
Interrupt presentaion
Bus interconnection
Microprogrammed Control Unit
Interrupts
Instruction cycle
Interrupts ppt
Instruction cycle with interrupts

What's hot (20)

PPTX
INTERRUPTS
PPTX
Interrupts
PPTX
design of accumlator
PPTX
General register organization (computer organization)
PPTX
Computer registers
PPTX
Control unit
PPTX
INTERCONNECTION STRUCTURE
PPT
8 interrupt 8051
PPT
ALU arithmetic logic unit
DOCX
Control Units : Microprogrammed and Hardwired:control unit
PPTX
System Programming- Unit I
PPTX
Instruction Set Architecture
PPTX
Interrupts
PPTX
Assembly language
PPTX
Modes of data transfer
PPTX
Micro Programmed Control Unit
PPTX
Intel 8051 Programming in C
PPTX
8251 USART
PPT
Computer Organization and Assembly Language
PPTX
8257 DMA Controller
INTERRUPTS
Interrupts
design of accumlator
General register organization (computer organization)
Computer registers
Control unit
INTERCONNECTION STRUCTURE
8 interrupt 8051
ALU arithmetic logic unit
Control Units : Microprogrammed and Hardwired:control unit
System Programming- Unit I
Instruction Set Architecture
Interrupts
Assembly language
Modes of data transfer
Micro Programmed Control Unit
Intel 8051 Programming in C
8251 USART
Computer Organization and Assembly Language
8257 DMA Controller
Ad

Similar to Interrupts (20)

PPTX
Interrupts on 8086 microprocessor by vijay kumar.k
PPTX
Interrupt in ATMEGA328P.pptx
PPTX
Interrupt in 8051
PPTX
8051 interrupt Presentation Download for ECE
PPTX
Interrupt 8085
PPT
PPTX
INTERRUPTS OF 8086 MICROPROCESSOR
PPTX
Interrupts programming in embedded C using 8051
DOCX
Interrupts
PPTX
Mc module5 ppt_msj
PPTX
Micro controller 8051 Interrupts
PPTX
Unit 3 timer and counter and there application .pptx
PPTX
Interrupts at AVR
PDF
Microcontroller part 2
PPTX
LECTURE_8 Interrupts.pptx hello and thanks for the University of
PPTX
Interrupts of 8085
PDF
Microcontroller 8085.ppt mmmmmmmmmmmmmmmmmm
PPTX
Interrupts in 8051
PPTX
Embedded systems, lesson 16
PPTX
8086 Interrupts & With DOS and BIOS by vijay
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupt in ATMEGA328P.pptx
Interrupt in 8051
8051 interrupt Presentation Download for ECE
Interrupt 8085
INTERRUPTS OF 8086 MICROPROCESSOR
Interrupts programming in embedded C using 8051
Interrupts
Mc module5 ppt_msj
Micro controller 8051 Interrupts
Unit 3 timer and counter and there application .pptx
Interrupts at AVR
Microcontroller part 2
LECTURE_8 Interrupts.pptx hello and thanks for the University of
Interrupts of 8085
Microcontroller 8085.ppt mmmmmmmmmmmmmmmmmm
Interrupts in 8051
Embedded systems, lesson 16
8086 Interrupts & With DOS and BIOS by vijay
Ad

More from Islam Samir (6)

PPTX
PPTX
Interfacing to the analog world
PPTX
Timers
PPTX
I/O Ports
PPTX
Introduction to Embedded Systems and Microcontrollers
PDF
4838281 operating-system-scheduling-on-multicore-architectures
Interfacing to the analog world
Timers
I/O Ports
Introduction to Embedded Systems and Microcontrollers
4838281 operating-system-scheduling-on-multicore-architectures

Recently uploaded (20)

PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PPTX
Internet of Everything -Basic concepts details
PDF
SaaS reusability assessment using machine learning techniques
PPTX
future_of_ai_comprehensive_20250822032121.pptx
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PPTX
Microsoft User Copilot Training Slide Deck
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
Improvisation in detection of pomegranate leaf disease using transfer learni...
Auditboard EB SOX Playbook 2023 edition.
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
LMS bot: enhanced learning management systems for improved student learning e...
Data Virtualization in Action: Scaling APIs and Apps with FME
Internet of Everything -Basic concepts details
SaaS reusability assessment using machine learning techniques
future_of_ai_comprehensive_20250822032121.pptx
sbt 2.0: go big (Scala Days 2025 edition)
Lung cancer patients survival prediction using outlier detection and optimize...
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
SGT Report The Beast Plan and Cyberphysical Systems of Control
Microsoft User Copilot Training Slide Deck
Custom Battery Pack Design Considerations for Performance and Safety
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC

Interrupts

  • 3. INTERRUPT  - Definition: An interrupt is an asynchronous signal indicate for an event which needs processor’s attention immediately regardless to the instruction it executes at this moment. It’s like a Doorbell.
  • 4. WHY DO WE USE INTERRUPTS? Example. (Software Polling) Assume that the MCU is supposed to do two tasks. - In one of them, it needs to know if a certain I/O pin is „1‟ or not yet. - We can do so by checking if this pin is „1‟ or „0‟, which called “Polling”. - By this method, the MCU is doing nothing but waiting for the pin to be high, the 2nd task can‟t be done in this time.  Wasting MCU’s time. - If the MCU left this task to do the 2nd task. While executing it, the pin became high. It won‟t know (the check won‟t be done) until it leaves the 2nd task.  Slow response to important events.
  • 5. INTERRUPT  Instead of checking each pin constantly (polling) and wasting the processor’s time, the MCU waits for the interrupt signal that indicates for the waited event.  When this interrupt signal equals ‘1’ : The MCU leaves the current program. Executes the predefined code for this event and returns back to the original program. I. II.
  • 6. COMPARISON Interrupts Software Polling Save processor‟s time. Waste processor‟s time. Fast response from the CPU to the event that has happened The processor‟s response depends on where it‟s in the program. Can‟t be used with switches or sensors. (because of Bouncing) Used with switches or sensors Ex. Timers. Ex. Switches.
  • 7. INTERRUPT DEFINITIONS  -  -  - Interrupt Flag (IF): A bit that is automatically set if the interrupt source (event) happens. Global Interrupt Enable (GIE): Enables (if set) all un-masked interrupts (interrupts with IE=1) or disables (if cleared) all interrupts. Interrupt Enable (IE): If the GIE was ‘1’, this bit forces the CPU to respond to the interrupt signal when IF=1  when the waited event happens.
  • 9. INTERRUPT DEFINITIONS  - - - Interrupt service routine (ISR): The code which the CPU jumps to when an interrupt happens. Actually, the CPU will automatically jumps to the (interrupt vector) 0004h. From there the code should be written to force the MCU to jump to the ISR address.
  • 10. INTERRUPTS  1) 2) 3) When the event (interrupt source) happens, the following steps happen: The corresponding interrupt flag (IF) will equal ‘1’. If the interrupt enable (IE) was ‘1’, and the global interrupt enable (GIE) was ‘1’ also, the GIE is cleared by hardware to avoid responding any further interrupt The return address is pushed into the stack and the PC is loaded with 0004h (the interrupt vector).
  • 11. INTERRUPTS 4) In the ISR, you can determine the source of interrupt by polling the interrupt flag bits and do the required action for it. 5) (Context Switching) You have to save key registers values before interrupt has happened e.g. W register and STATUS register. This has to be implemented in software If you use high level language the compiler will do it for you. - 4) At the end of the ISR, you’ve to clear the IF in software then set the GIE bit in the end of the ISR code.
  • 13. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS? If interrupts are not used, the control unit goes through the ordinary instruction cycle: I. Fetch instruction. ( Ins. register<--M[PC] ). II. Decode the instruction. III. Execute it. 
  • 14. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS?  When interrupts are used in the microprocessor, the control unit checks first if there is an interrupt signal or not. If the interrupt signal was „1‟, it goes through interrupt cycle: I. Store the current address into the stack.  (the address of the next instruction which should have been loaded if there is no interrupt). II. Load the PC with the interrupt vector address. III. Make the GIE=„0‟. 
  • 15. Interrupt signal? T F Interrupt cycle Instruction cycle Stack <-- return address PC <-- Interrupt vector In S.W., m ake IF=0 GIE=0 Fetch Decode Execute
  • 16. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS?  The last instruction in the ISR should be: RETFIE (return from interrupt).  This instruction makes the control unit loads the PC with the address stored in the stack so that the original program can continue.
  • 17. INTERRUPT SOURCES IN THE PIC 16 MCU  INT Pin Interrupt (external interrupt)  TMR0 Overflow Interrupt  PORTB Change Interrupt (pins RB7:RB4)  Comparator Change Interrupt  Parallel Slave Port Interrupt  USART Interrupts  Receive Interrupt  Transmit Interrupt  A/D Conversion Complete Interrupt  Data EEPROM Write Complete Interrupt  Timer1 Overflow Interrupt  Timer2 Overflow Interrupt  CCP Interrupt  SSP Interrupt
  • 18. INTERRUPT SOURCES - - Many peripherals use interrupts when finishing its job (ex. USART, ADC, Timers …), or when there is a problem needs to be configured (ex. EEPROM Write Complete ). Here, we’ll talk about the simplest type of interrupt, and the rest of interrupt sources should be handled in the same way. Very important:  If you configure the MCU to respond to more than one interrupt source at the same time, to determine which one has happened, pull their flags in the ISR (check which one equals 1).
  • 19. RB0/INT  The RB0/INT pin is a single external interrupt source.  When the waited edge rising or falling edge as selected) happens on RB0 pin, the interrupt signal is generated.  It can be configured to react to signal raising edge or signal falling edge.
  • 20. RB0/INT Steps: 1. Configure the interrupt source to work as you want, here : falling or rising edge.  2. Set the IE bit of this interrupt source. 3. Write the Interrupt Service Routine (ISR). 4. Set the GIE bit.
  • 21. EXAMPLE  Make the led illuminates when the button is pressed, using RB0 interrupt.
  • 22. ASSIGNMENT  - Make an application using interrupts, detects raising edge signals on RB0, and detect any change happens is PORTB <7:4> and respond to it as specified in the next table: PORTB<7:4> PORTC<7:4> xxx1 xxx1 xx1x xx1x x1xx x1xx 1xxx 1xxx