SlideShare a Scribd company logo
1 of 34
Download to read offline
8051 INTERRUPT PROGRAMMING
                 IN ASSEMBLY
                   Prof. Anish Goel
OBJECTIVES
    Contrast and compare interrupts versus polling
    Explain the purpose of the ISR (interrupt service routine)
    List the 6 interrupts of the 8051
    Explain the purpose of the interrupt vector table
    Enable or disable 8051 interrupts
    Program the 8051 timers using interrupts
    Describe the external hardware interrupts of the 8051
    Contrast edge-triggered with level-triggered interrupts
    Program the 8051 for interrupt-based serial communication
    Define the interrupt priority of the 8051




2                                       Prof. Anish Goel
8051 INTERRUPTS
    Interrupts vs. polling
      on receiving interrupt, the microcontroller interrupts whatever it
      is doing and executes interrupt service routine (ISR)
      microcontroller can serve many devices
      each device gets attention based on the priority
      polling wastes time




3                                       Prof. Anish Goel
8051 INTERRUPTS
    Interrupt service routine
     for each interrupt there must be ISR
     for every interrupt, there is a fixed location in memory that
     holds the address of its ISR
     interrupt vector table




4                                      Prof. Anish Goel
8051 INTERRUPTS




       Table 1   Interrupt Vector Table for the 8051
5                                Prof. Anish Goel
8051 INTERRUPTS
     Steps in executing an interrupt

    1.   mC finishes the instruction it is executing and saves the address of the
         next instruction (PC) on the stack
    2.   it saves the current status of all the interrupts internally
    3.   it jumps to a fixed location in memory called the interrupt vector
         table
    4.   the microcontroller gets the address of the ISR from the interrupt
         vector table and jumps to it and starts to execute the ISR until it
         reaches the last instruction RETI
    5.   the microcontroller returns to the place where it was interrupted, it
         gets the PC address from the stack by popping the top two bytes of the
         stack into the PC and then it starts to execute from that address




6                                            Prof. Anish Goel
8051 INTERRUPTS
    Six interrupts in the 8051
     1 reset interrupt, when the reset pin is activated, the 8051 jumps to
     address location 0000
     2 timer interrupts
     2 external hardware interrupts
     pin 12 (P3.2) and 13 (P3.3) in port 3 are for the external hardware
     interrupts
     1 serial communication interrupt that belongs to both receive and
     transmit
     a limited number of bytes is set aside for each interrupt




7                                            Prof. Anish Goel
8051 INTERRUPTS




    Figure 1   Redirecting the 8051 from the Interrupt Vector Table at Power-up

8                                          Prof. Anish Goel
8051 INTERRUPTS
    Enabling and disabling an interrupt
     upon reset all interrupts are disabled
     interrupts must be enabled by software
     IE register (interrupt enable) is responsible for enabling and
     disabling the interrupts
     IE is a bit-addressable register




9                                      Prof. Anish Goel
8051 INTERRUPTS
     Steps in enabling an interrupt
     1.   EA must be set to 1
     2.   set the relevant bits in IE register to high

          EA = 0, no interrupt will be responded to, even if the
          relevant bit in the IE register is high




10                                        Prof. Anish Goel
8051 INTERRUPTS




     Figure 2   IE (Interrupt Enable) Register
11                                Prof. Anish Goel
Example 1
Show the instructions to (a) enable the serial interrupt, Timer 0 interrupt, and external
hardware interrupt 1 (EX1), and (b) disable (mask) the Timer 0 interrupt, then (c) show how
to disable all the interrupts with a single instruction.




 12                                                Prof. Anish Goel
PROGRAMMING TIMER INTERRUPTS
 Roll-over timer flag and interrupt




                          Figure 3     TF Interrupt

     if the timer interrupt is enabled, whenever TF=1, the microcontroller is
     interrupted in whatever it is doing, and jumps to the interrupt vector table
     to service the ISR
     In this way, the microcontroller can do other things until it is notified that
     the timer has rolled over




13                                            Prof. Anish Goel
Example 2
Write a program that continuously gets 8-bit data from P0 and sends it to P1
while simultaneously creating a square wave of 200 µs period on pin P2.1. Use
Timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz.




 14                                         Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 External interrupts INT0 and INT1




           Figure 4   Activation of INT0 and INT1

15                               Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 Level-triggered interrupt
     INT0 and INT1 pins are normally high
     if low-level signal is applied, it triggers the interrupt
     microcontroller stops whatever it is doing and jumps to the interrupt
     vector table to service the interrupt
     the low-level signal must be removed before the execution of the last
     instruction of the interrupt service routine, RETI
     otherwise, another interrupt will be generated




16                                         Prof. Anish Goel
Example 5
Assume that the INT1 pin is connected to a switch that is normally high. Whenever it goes
low, it should turn on an LED. The LED is connected to P1.3 and is normally off. When it is
turned on it should stay on for a fraction of a second. As long as the switch is pressed low,
the LED should stay on.




 17                                                 Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 Sampling the low level-triggered interrupt
     to ensure the activation of the hardware interrupt at the INTx
     pin, make sure that the duration of the low-level signal is
     around 4 machine cycles




18                                     Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 Sampling the low level-triggered interrupt




     Figure 5 Minimum Duration of the Low Level-Triggered
                     Interrupt (XTAL = 11.0592 MHz)

19                                   Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 Edge-triggered interrupts




                                    Figure 6
                                    TCON (Timer/Counter)
                                    Register (Bit-addressable)




20                           Prof. Anish Goel
Example 6
Assuming that INT1 is connected to a pulse generator. Write a program in which
the falling edge of the pulse will send a high to P 1.3, which is connected to an
LED.




 21                                          Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 Sampling the edge-triggered interrupt
     external source must be held high for at least one machine
     cycle, and then held low for at least one machine cycle to
     ensure that the transition is seen by the microcontroller




22                                    Prof. Anish Goel
PROGRAMMING EXTERNAL HARDWARE
INTERRUPTS
 More about the TCON register




                         Figure 6
                         TCON (Timer/Counter) Register
                         (Bit-addressable)




23                       Prof. Anish Goel
PROGRAMMING THE SERIAL
 COMMUNICATION INTERRUPT
 RI and TI flags and interrupts
     1 interrupt is set for serial communication
     used to both send and receive data
     when RI or TI is raised the 8051 gets interrupted and jumps to
     memory address location 0023H to execute the ISR
     the ISR must examine the TI and RI flags to see which one
     caused the interrupt and respond accordingly




24                                    Prof. Anish Goel
PROGRAMMING THE SERIAL
 COMMUNICATION INTERRUPT




       Figure 7   Single Interrupt for Both TI and RI


25                             Prof. Anish Goel
Example 8
Write a program in which the 8051 reads data from P1 and writes it to P2
continuously while giving a copy of it to the serial COM port to be transferred
serially. Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.




 26                                           Prof. Anish Goel
Example 9
Write a program in which the 8051 gets data from P1 and sends it to P2
continuously while incoming data from the serial port is sent to P0.
Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.




 27                                   Prof. Anish Goel
PROGRAMMING THE SERIAL
COMMUNICATION INTERRUPT




       Table 2   Interrupt Flag Bits for the 8051/52
28                              Prof. Anish Goel
Example 10
Write a program using interrupts to do the following:
(a) Receive data serially and send it to P0, (b) Have port P1 read and transmitted serially,
and a copy given to P2, (c) Make Timer 0 generate a square wave of 5 kHz frequency on
P0.1. Assume that XTAL = 11.0592 MHz. Set the baud rate at 4800.




 29                                                  Prof. Anish Goel
INTERRUPT PRIORITY IN THE 8051/52
 Interrupt priority upon reset




         Table 3   8051/52 Interrupt Priority Upon Reset



30                                  Prof. Anish Goel
INTERRUPT PRIORITY IN THE 8051/52
 Setting interrupt priority with the IP register




         Figure 8   Interrupt Priority Register (Bit-addressable)

31                                    Prof. Anish Goel
Example 12(a)
Program the IP register to assign the highest priority to INT 1, then (b) discuss what
happens if INT0, INT1, and TF0are activated at the same time. Assume that the
interrupts are both edge-triggered.

  (a) MOV IP,#00000100B or "SETB IP.2“

  (b) when INT0, INT1, and TF0 interrupts are activated at
  the same time, the 8051 services INT1 first, then it
  services INT0, then TF0




 32                                          Prof. Anish Goel
INTERRUPT PRIORITY IN THE 8051/52
 Interrupt inside an interrupt
     what happens if the 8051 is executing an ISR belonging to an
     interrupt and another interrupt is activated?
     a high-priority interrupt can interrupt a low-priority interrupt
     no low-priority interrupt can get the immediate attention of the
     CPU until it has finished servicing the high-priority interrupts




33                                     Prof. Anish Goel
INTERRUPT PRIORITY IN THE 8051/52
 Triggering the interrupt by software
     can test an ISR with instructions to set the interrupts high
      "SETB TF1" will interrupt the 8051 in whatever it is doing and
     force it to jump to the interrupt vector table
     don’t have to wait for Timer 1 to roll over
     useful for testing ISR




34                                    Prof. Anish Goel

More Related Content

What's hot

Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSORTRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSORSubash Sambath Kumar
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Jay Patel
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded cVikas Dongre
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1deval patel
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesSrikrishna Thota
 
Finite state machines
Finite state machinesFinite state machines
Finite state machinesdennis gookyi
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
Automated Traffic Light control using 8051 microcontroller
Automated Traffic Light control using 8051 microcontrollerAutomated Traffic Light control using 8051 microcontroller
Automated Traffic Light control using 8051 microcontrollerVijayMaheshwari12
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085ShivamSood22
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 

What's hot (20)

Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
 
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSORTRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Switches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontrollerSwitches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontroller
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
 
Finite state machines
Finite state machinesFinite state machines
Finite state machines
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
Automated Traffic Light control using 8051 microcontroller
Automated Traffic Light control using 8051 microcontrollerAutomated Traffic Light control using 8051 microcontroller
Automated Traffic Light control using 8051 microcontroller
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
8051 memory
8051 memory8051 memory
8051 memory
 
Interrupts of microprocessor 8085
Interrupts of microprocessor  8085Interrupts of microprocessor  8085
Interrupts of microprocessor 8085
 

Similar to Interrupt

Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming vijaydeepakg
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxSujalKumar73
 
Mmai ppt
Mmai pptMmai ppt
Mmai pptGIT
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interruptsdharmesh nakum
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti VenkatraoRamisetti
 
Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy Technogroovy India
 
8449972 embedded-systems-and-model-of-metro-train
8449972 embedded-systems-and-model-of-metro-train8449972 embedded-systems-and-model-of-metro-train
8449972 embedded-systems-and-model-of-metro-trainJitendra Saroj
 
Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Saurav Kumar
 
Electronic voting machine presentation
Electronic voting machine  presentationElectronic voting machine  presentation
Electronic voting machine presentationRavikant Dhayal
 

Similar to Interrupt (20)

Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
Embedded systems, lesson 16
Embedded systems, lesson 16Embedded systems, lesson 16
Embedded systems, lesson 16
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
 
DPA
DPADPA
DPA
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
Interrupt.pptx
Interrupt.pptxInterrupt.pptx
Interrupt.pptx
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
 
Mmai ppt
Mmai pptMmai ppt
Mmai ppt
 
8051 Interrupts
8051 Interrupts8051 Interrupts
8051 Interrupts
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interrupts
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti
 
Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
8051
80518051
8051
 
8449972 embedded-systems-and-model-of-metro-train
8449972 embedded-systems-and-model-of-metro-train8449972 embedded-systems-and-model-of-metro-train
8449972 embedded-systems-and-model-of-metro-train
 
Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52
 
Electronic voting machine presentation
Electronic voting machine  presentationElectronic voting machine  presentation
Electronic voting machine presentation
 
Interrupt
InterruptInterrupt
Interrupt
 

More from anishgoel

Computer Organization
Computer OrganizationComputer Organization
Computer Organizationanishgoel
 
Learning vhdl by examples
Learning vhdl by examplesLearning vhdl by examples
Learning vhdl by examplesanishgoel
 
Dot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry PiDot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry Pianishgoel
 
Input interface with Raspberry pi
Input interface with Raspberry piInput interface with Raspberry pi
Input interface with Raspberry pianishgoel
 
Learning Python for Raspberry Pi
Learning Python for Raspberry PiLearning Python for Raspberry Pi
Learning Python for Raspberry Pianishgoel
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pianishgoel
 
learning vhdl by examples
learning vhdl by exampleslearning vhdl by examples
learning vhdl by examplesanishgoel
 
Digital System Design Basics
Digital System Design BasicsDigital System Design Basics
Digital System Design Basicsanishgoel
 
digital design of communication systems
digital design of communication systemsdigital design of communication systems
digital design of communication systemsanishgoel
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos conceptsanishgoel
 
8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timeranishgoel
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
Serial Communication Interfaces
Serial Communication InterfacesSerial Communication Interfaces
Serial Communication Interfacesanishgoel
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part danishgoel
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part canishgoel
 
Embedded systems ppt iv part b
Embedded systems ppt iv   part bEmbedded systems ppt iv   part b
Embedded systems ppt iv part banishgoel
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt iianishgoel
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iiianishgoel
 
Embedded systems ppt iv part a
Embedded systems ppt iv   part aEmbedded systems ppt iv   part a
Embedded systems ppt iv part aanishgoel
 
Embedded systems ppt i
Embedded systems ppt iEmbedded systems ppt i
Embedded systems ppt ianishgoel
 

More from anishgoel (20)

Computer Organization
Computer OrganizationComputer Organization
Computer Organization
 
Learning vhdl by examples
Learning vhdl by examplesLearning vhdl by examples
Learning vhdl by examples
 
Dot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry PiDot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry Pi
 
Input interface with Raspberry pi
Input interface with Raspberry piInput interface with Raspberry pi
Input interface with Raspberry pi
 
Learning Python for Raspberry Pi
Learning Python for Raspberry PiLearning Python for Raspberry Pi
Learning Python for Raspberry Pi
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
learning vhdl by examples
learning vhdl by exampleslearning vhdl by examples
learning vhdl by examples
 
Digital System Design Basics
Digital System Design BasicsDigital System Design Basics
Digital System Design Basics
 
digital design of communication systems
digital design of communication systemsdigital design of communication systems
digital design of communication systems
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timer
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
Serial Communication Interfaces
Serial Communication InterfacesSerial Communication Interfaces
Serial Communication Interfaces
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part d
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part c
 
Embedded systems ppt iv part b
Embedded systems ppt iv   part bEmbedded systems ppt iv   part b
Embedded systems ppt iv part b
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt ii
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iii
 
Embedded systems ppt iv part a
Embedded systems ppt iv   part aEmbedded systems ppt iv   part a
Embedded systems ppt iv part a
 
Embedded systems ppt i
Embedded systems ppt iEmbedded systems ppt i
Embedded systems ppt i
 

Interrupt

  • 1. 8051 INTERRUPT PROGRAMMING IN ASSEMBLY Prof. Anish Goel
  • 2. OBJECTIVES Contrast and compare interrupts versus polling Explain the purpose of the ISR (interrupt service routine) List the 6 interrupts of the 8051 Explain the purpose of the interrupt vector table Enable or disable 8051 interrupts Program the 8051 timers using interrupts Describe the external hardware interrupts of the 8051 Contrast edge-triggered with level-triggered interrupts Program the 8051 for interrupt-based serial communication Define the interrupt priority of the 8051 2 Prof. Anish Goel
  • 3. 8051 INTERRUPTS Interrupts vs. polling on receiving interrupt, the microcontroller interrupts whatever it is doing and executes interrupt service routine (ISR) microcontroller can serve many devices each device gets attention based on the priority polling wastes time 3 Prof. Anish Goel
  • 4. 8051 INTERRUPTS Interrupt service routine for each interrupt there must be ISR for every interrupt, there is a fixed location in memory that holds the address of its ISR interrupt vector table 4 Prof. Anish Goel
  • 5. 8051 INTERRUPTS Table 1 Interrupt Vector Table for the 8051 5 Prof. Anish Goel
  • 6. 8051 INTERRUPTS Steps in executing an interrupt 1. mC finishes the instruction it is executing and saves the address of the next instruction (PC) on the stack 2. it saves the current status of all the interrupts internally 3. it jumps to a fixed location in memory called the interrupt vector table 4. the microcontroller gets the address of the ISR from the interrupt vector table and jumps to it and starts to execute the ISR until it reaches the last instruction RETI 5. the microcontroller returns to the place where it was interrupted, it gets the PC address from the stack by popping the top two bytes of the stack into the PC and then it starts to execute from that address 6 Prof. Anish Goel
  • 7. 8051 INTERRUPTS Six interrupts in the 8051 1 reset interrupt, when the reset pin is activated, the 8051 jumps to address location 0000 2 timer interrupts 2 external hardware interrupts pin 12 (P3.2) and 13 (P3.3) in port 3 are for the external hardware interrupts 1 serial communication interrupt that belongs to both receive and transmit a limited number of bytes is set aside for each interrupt 7 Prof. Anish Goel
  • 8. 8051 INTERRUPTS Figure 1 Redirecting the 8051 from the Interrupt Vector Table at Power-up 8 Prof. Anish Goel
  • 9. 8051 INTERRUPTS Enabling and disabling an interrupt upon reset all interrupts are disabled interrupts must be enabled by software IE register (interrupt enable) is responsible for enabling and disabling the interrupts IE is a bit-addressable register 9 Prof. Anish Goel
  • 10. 8051 INTERRUPTS Steps in enabling an interrupt 1. EA must be set to 1 2. set the relevant bits in IE register to high EA = 0, no interrupt will be responded to, even if the relevant bit in the IE register is high 10 Prof. Anish Goel
  • 11. 8051 INTERRUPTS Figure 2 IE (Interrupt Enable) Register 11 Prof. Anish Goel
  • 12. Example 1 Show the instructions to (a) enable the serial interrupt, Timer 0 interrupt, and external hardware interrupt 1 (EX1), and (b) disable (mask) the Timer 0 interrupt, then (c) show how to disable all the interrupts with a single instruction. 12 Prof. Anish Goel
  • 13. PROGRAMMING TIMER INTERRUPTS Roll-over timer flag and interrupt Figure 3 TF Interrupt if the timer interrupt is enabled, whenever TF=1, the microcontroller is interrupted in whatever it is doing, and jumps to the interrupt vector table to service the ISR In this way, the microcontroller can do other things until it is notified that the timer has rolled over 13 Prof. Anish Goel
  • 14. Example 2 Write a program that continuously gets 8-bit data from P0 and sends it to P1 while simultaneously creating a square wave of 200 µs period on pin P2.1. Use Timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz. 14 Prof. Anish Goel
  • 15. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS External interrupts INT0 and INT1 Figure 4 Activation of INT0 and INT1 15 Prof. Anish Goel
  • 16. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS Level-triggered interrupt INT0 and INT1 pins are normally high if low-level signal is applied, it triggers the interrupt microcontroller stops whatever it is doing and jumps to the interrupt vector table to service the interrupt the low-level signal must be removed before the execution of the last instruction of the interrupt service routine, RETI otherwise, another interrupt will be generated 16 Prof. Anish Goel
  • 17. Example 5 Assume that the INT1 pin is connected to a switch that is normally high. Whenever it goes low, it should turn on an LED. The LED is connected to P1.3 and is normally off. When it is turned on it should stay on for a fraction of a second. As long as the switch is pressed low, the LED should stay on. 17 Prof. Anish Goel
  • 18. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS Sampling the low level-triggered interrupt to ensure the activation of the hardware interrupt at the INTx pin, make sure that the duration of the low-level signal is around 4 machine cycles 18 Prof. Anish Goel
  • 19. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS Sampling the low level-triggered interrupt Figure 5 Minimum Duration of the Low Level-Triggered Interrupt (XTAL = 11.0592 MHz) 19 Prof. Anish Goel
  • 20. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS Edge-triggered interrupts Figure 6 TCON (Timer/Counter) Register (Bit-addressable) 20 Prof. Anish Goel
  • 21. Example 6 Assuming that INT1 is connected to a pulse generator. Write a program in which the falling edge of the pulse will send a high to P 1.3, which is connected to an LED. 21 Prof. Anish Goel
  • 22. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS Sampling the edge-triggered interrupt external source must be held high for at least one machine cycle, and then held low for at least one machine cycle to ensure that the transition is seen by the microcontroller 22 Prof. Anish Goel
  • 23. PROGRAMMING EXTERNAL HARDWARE INTERRUPTS More about the TCON register Figure 6 TCON (Timer/Counter) Register (Bit-addressable) 23 Prof. Anish Goel
  • 24. PROGRAMMING THE SERIAL COMMUNICATION INTERRUPT RI and TI flags and interrupts 1 interrupt is set for serial communication used to both send and receive data when RI or TI is raised the 8051 gets interrupted and jumps to memory address location 0023H to execute the ISR the ISR must examine the TI and RI flags to see which one caused the interrupt and respond accordingly 24 Prof. Anish Goel
  • 25. PROGRAMMING THE SERIAL COMMUNICATION INTERRUPT Figure 7 Single Interrupt for Both TI and RI 25 Prof. Anish Goel
  • 26. Example 8 Write a program in which the 8051 reads data from P1 and writes it to P2 continuously while giving a copy of it to the serial COM port to be transferred serially. Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600. 26 Prof. Anish Goel
  • 27. Example 9 Write a program in which the 8051 gets data from P1 and sends it to P2 continuously while incoming data from the serial port is sent to P0. Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600. 27 Prof. Anish Goel
  • 28. PROGRAMMING THE SERIAL COMMUNICATION INTERRUPT Table 2 Interrupt Flag Bits for the 8051/52 28 Prof. Anish Goel
  • 29. Example 10 Write a program using interrupts to do the following: (a) Receive data serially and send it to P0, (b) Have port P1 read and transmitted serially, and a copy given to P2, (c) Make Timer 0 generate a square wave of 5 kHz frequency on P0.1. Assume that XTAL = 11.0592 MHz. Set the baud rate at 4800. 29 Prof. Anish Goel
  • 30. INTERRUPT PRIORITY IN THE 8051/52 Interrupt priority upon reset Table 3 8051/52 Interrupt Priority Upon Reset 30 Prof. Anish Goel
  • 31. INTERRUPT PRIORITY IN THE 8051/52 Setting interrupt priority with the IP register Figure 8 Interrupt Priority Register (Bit-addressable) 31 Prof. Anish Goel
  • 32. Example 12(a) Program the IP register to assign the highest priority to INT 1, then (b) discuss what happens if INT0, INT1, and TF0are activated at the same time. Assume that the interrupts are both edge-triggered. (a) MOV IP,#00000100B or "SETB IP.2“ (b) when INT0, INT1, and TF0 interrupts are activated at the same time, the 8051 services INT1 first, then it services INT0, then TF0 32 Prof. Anish Goel
  • 33. INTERRUPT PRIORITY IN THE 8051/52 Interrupt inside an interrupt what happens if the 8051 is executing an ISR belonging to an interrupt and another interrupt is activated? a high-priority interrupt can interrupt a low-priority interrupt no low-priority interrupt can get the immediate attention of the CPU until it has finished servicing the high-priority interrupts 33 Prof. Anish Goel
  • 34. INTERRUPT PRIORITY IN THE 8051/52 Triggering the interrupt by software can test an ISR with instructions to set the interrupts high "SETB TF1" will interrupt the 8051 in whatever it is doing and force it to jump to the interrupt vector table don’t have to wait for Timer 1 to roll over useful for testing ISR 34 Prof. Anish Goel