SlideShare a Scribd company logo
1 of 21
8051
                            Interrupts



M_Nokhodchian @ yahoo.com                Microprocessors 1-1
Interrupts Programming
     An interrupt is an external or internal event that
      interrupts the microcontroller to inform it that a
      device needs its service.
      Interrupts vs. Polling
     A single microcontroller can serve several devices.
     There are two ways to do that:
         interrupts
         polling.
     The program which is associated with the interrupt
      is called the interrupt service routine (ISR) or
      interrupt handler.

M_Nokhodchian @ yahoo.com                         Microprocessors 1-2
Steps in executing an interrupt
    Finish current instruction and saves the PC on stack.

    Jumps to a fixed location in memory depend on type
     of interrupt

    Starts to execute the interrupt service routine until
     RETI (return from interrupt)

    Upon executing the RETI the microcontroller returns
     to the place where it was interrupted. Get pop PC
     from stack




M_Nokhodchian @ yahoo.com                        Microprocessors 1-3
Interrupt Sources
     Original 8051 has 6 sources of interrupts
         Reset
         Timer 0 overflow
         Timer 1 overflow
         External Interrupt 0
         External Interrupt 1
         Serial Port events (buffer full, buffer empty, etc)

     Enhanced version has 22 sources
         More timers, programmable counter array, ADC, more
          external interrupts, another serial port (UART)




M_Nokhodchian @ yahoo.com                                  Microprocessors 1-4
Interrupt Vectors
  Each interrupt has a specific place in code memory where
    program execution (interrupt service routine) begins.

  External Interrupt 0:     0003h
  Timer 0 overflow:         000Bh
  External Interrupt 1:     0013h
  Timer 1 overflow:         001Bh
                                       Note: that there are
  Serial :                  0023h      only 8 memory
  Timer 2 overflow(8052+)   002bh      locations between
                                       vectors.




M_Nokhodchian @ yahoo.com                          Microprocessors 1-5
ISRs and Main Program in 8051
              SJMP      main
              ORG      03H
              ljmp     int0sr
              ORG      0BH
              ljmp     t0sr
              ORG      13H
              ljmp     int1sr
              ORG      1BH
              ljmp     t1sr
              ORG      23H
              ljmp     serialsr
              ORG      30H
    main:
              …
              END

M_Nokhodchian @ yahoo.com         Microprocessors 1-6
Interrupt Enable (IE) register

     All interrupt are disabled after reset
     We can enable and disable them bye IE




M_Nokhodchian @ yahoo.com                       Microprocessors 1-7
Enabling and disabling an
                          interrupt
   by bit operation
   Recommended in the middle of program
            SETB    EA      SETB   IE.7   ;Enable   All
            SETB    ET0     SETB   IE.1   ;Enable   Timer0 ovrf
            SETB    ET1     SETB   IE.3   ;Enable   Timer1 ovrf
            SETB    EX0     SETB   IE.0   ;Enable   INT0
            SETB    EX1     SETB   IE.2   ;Enable   INT1
            SETB    ES                    ;Enable   Serial port
                            SETB   IE.4
   by mov instruction
   Recommended in the first of program
            MOV IE, #10010110B




M_Nokhodchian @ yahoo.com                                  Microprocessors 1-8
Example
   A 10khz square wave with 50% duty cycle
           ORG      0        ;Reset entry poit
           LJMP     MAIN     ;Jump above interrupt

        ORG         000BH    ;Timer 0 interrupt vector
  T0ISR:CPL         P1.0     ;Toggle port bit
        RETI                 ;Return from ISR to Main program

        ORG 0030H            ;Main Program entry point
  MAIN: MOV   TMOD,#02H      ;Timer 0, mode 2
        MOV   TH0,#-50       ;50 us delay
        SETB TR0             ;Start timer
        MOV   IE,#82H        ;Enable timer 0 interrupt
        SJMP $               ;Do nothing just wait
        END
M_Nokhodchian @ yahoo.com                            Microprocessors 1-9
Example
     Write a program using interrupts to
      simultaneously create 7 kHz and 500 Hz
      square waves on P1.7 and P1.6.

                            8051        143µs
                                            71µs
                            P1.7




                                           2ms
                            P1.6                   1ms




M_Nokhodchian @ yahoo.com                                Microprocessors 1-10
ORG        0           Solution
          LJMP       MAIN
          ORG        000BH
          LJMP       T0ISR
          ORG        001BH
          LJMP       T1ISR              8051    143µs
          ORG        0030H                          71µs
                                        P1.7
   MAIN:  MOV        TMOD,#12H
          MOV        TH0,#-71
          SETB       TR0
          SETB       TF1
          MOV        IE,#8AH                       2ms
          MOV        IE,#8AH            P1.6               1ms
          SJMP       $
   T0ISR: CPL        P1.7
          RETI
   T1ISR: CLR        TR1
          MOV        TH1,#HIGH(-1000)
          MOV        TL1,#LOW(-1000)
          SETB       TR1
          CPL        P1.6
          RETI
          END


M_Nokhodchian @ yahoo.com                      Microprocessors 1-11
Timer ISR
     Notice that
          There is no need for a “CLR TFx” instruction in
           timer ISR
          8051 clears the TF internally upon jumping to ISR


     Notice that
          We must reload timer in mode 1
          There is no need on mode 2 (timer auto reload)




M_Nokhodchian @ yahoo.com                          Microprocessors 1-12
External interrupt type control
  By low nibble of Timer control register TCON
  IE0 (IE1): External interrupt 0(1) edge flag.
       set by CPU when external interrupt edge (H-to-L) is detected.
       Does not affected by H-to-L while ISR is executed(no int on int)
       Cleared by CPU when RETI executed.
       does not latch low-level triggered interrupt
  IT0 (IT1): interrupt 0 (1) type control bit.
       Set/cleared by software
       IT=1 edge trigger
       IT=0 low-level trigger

   (MSB)                                                                (LSB)
    TF1 TR1                 TF0 TR0        IE1      IT1 IE0              IT0
      Timer 1                Timer0                for Interrupt
M_Nokhodchian @ yahoo.com                                       Microprocessors 1-13
External Interrupts

                                     (Level-triggered (default
               INT0
             (Pin 3.2)         0
                                                                                            0003
                                           IT0
                               1                                      (IE0 (TCON.3
                               2

                             Edge-triggered



                                          (Level-triggered (default
                   INT0
                 (Pin 3.3)           0                                                      0013
                                                 IT1
                                     1                                   (IE1 (TCON.3
                                     2

                                   Edge-triggered




M_Nokhodchian @ yahoo.com                                                               Microprocessors 1-14
Example of external interuupt
             ORG 0000H
             LJMP MAIN
    ;
    ;interrupt service routine (ISR)
    ;for hardware external interrupt INT1
    ;

             ORG 0013H
             SETB P1.1
             MOV R0,200
    WAIT:    DJNZ R0,WAIT
             CLR P1.1
             RETI
    ;
    ;main program for initialization
    ;
           ORG 30H
    MAIN: SETB IT1           ;on negative edge of INT1
           MOV IE,#10000100B
    WAIT2: SJMP WAIT2
           END

M_Nokhodchian @ yahoo.com                          Microprocessors 1-15
Example of external interuupt




M_Nokhodchian @ yahoo.com            Microprocessors 1-16
Example of external interuupt
             Org 0000h
             Ljmp main

           Org 0003h
    x0isr: clr p1.7
           Reti

           Org 0013h
    x1isr: setb p1.7
           Reti

             Org 0030h
    Main:    mov ie,#85h
             Setb it0
             Setb it1
             Setb p1.7
             Jb p3.2,skip
             Clr p1.7
    Skip:    Sjmp $
    end
M_Nokhodchian @ yahoo.com             Microprocessors 1-17
Interrupt Priorities
    What if two interrupt sources interrupt at the same
     time?
    The interrupt with the highest PRIORITY gets
     serviced first.
    All interrupts have a power on default priority order.
       1. External interrupt 0 (INT0)
       2. Timer interrupt0 (TF0)
       3. External interrupt 1 (INT1)
       4. Timer interrupt1 (TF1)
       5. Serial communication (RI+TI)
    Priority can also be set to “high” or “low” by IP reg.

M_Nokhodchian @ yahoo.com                          Microprocessors 1-18
Interrupt Priorities (IP) Register

       ---       ---        PT2   PS   PT1   PX1   PT0       PX0


     IP.7: reserved
     IP.6: reserved
     IP.5: timer 2 interrupt priority bit(8052 only)
     IP.4: serial port interrupt priority bit
     IP.3: timer 1 interrupt priority bit
     IP.2: external interrupt 1 priority bit
     IP.1: timer 0 interrupt priority bit
     IP.0: external interrupt 0 priority bit


M_Nokhodchian @ yahoo.com                              Microprocessors 1-19
Interrupt Priorities Example
       ---        ---       PT2   PS       PT1     PX1     PT0      PX0

      MOV IP , #00000100B             or SETB IP.2 gives priority order
             1.   Int1
             2.   Int0
             3.   Timer0
             4.   Timer1
             5.   Serial
      MOV IP , #00001100B gives priority order
             1.   Int1
             2.   Timer1
             3.   Int0
             4.   Timer0
             5.   Serial


M_Nokhodchian @ yahoo.com                                     Microprocessors 1-20
Interrupt inside an interrupt
       ---       ---        PT2   PS   PT1   PX1   PT0     PX0

    A high-priority interrupt can interrupt a low-priority
     interrupy
    All interrupt are latched internally
    Low-priority interrupt wait until 8051 has finished
     servicing the high-priority interrupt




M_Nokhodchian @ yahoo.com                            Microprocessors 1-21

More Related Content

What's hot

Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architectureDominicHendry
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERAnkita Jaiswal
 
Programmable Peripheral Interface 8255
 Programmable Peripheral Interface   8255 Programmable Peripheral Interface   8255
Programmable Peripheral Interface 8255Dr.P.Parandaman
 
Architecture of 8085
Architecture of 8085Architecture of 8085
Architecture of 8085Sumit Swain
 
Dc motor interfacing with 8051 microcontroller
Dc motor interfacing with 8051 microcontrollerDc motor interfacing with 8051 microcontroller
Dc motor interfacing with 8051 microcontrollerUmar Shuaib
 

What's hot (20)

Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
8051 i/o port circuit
8051 i/o port circuit8051 i/o port circuit
8051 i/o port circuit
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
8051 Timer
8051 Timer8051 Timer
8051 Timer
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLER
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
 
Programmable Peripheral Interface 8255
 Programmable Peripheral Interface   8255 Programmable Peripheral Interface   8255
Programmable Peripheral Interface 8255
 
Architecture of 8085
Architecture of 8085Architecture of 8085
Architecture of 8085
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Intel 8051 - pin description
Intel 8051  - pin descriptionIntel 8051  - pin description
Intel 8051 - pin description
 
Dc motor interfacing with 8051 microcontroller
Dc motor interfacing with 8051 microcontrollerDc motor interfacing with 8051 microcontroller
Dc motor interfacing with 8051 microcontroller
 
ARM- Programmer's Model
ARM- Programmer's ModelARM- Programmer's Model
ARM- Programmer's Model
 
Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051
 
Programmable logic controllers
Programmable logic controllersProgrammable logic controllers
Programmable logic controllers
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
8251 USART
8251 USART8251 USART
8251 USART
 

Viewers also liked

Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interruptsdharmesh nakum
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edThe 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edĐinh Công Thiện Taydo University
 
7 segment led interfacing with 8051
7 segment led interfacing with 80517 segment led interfacing with 8051
7 segment led interfacing with 8051Sam Patel
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 

Viewers also liked (6)

Interrupt
InterruptInterrupt
Interrupt
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interrupts
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edThe 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
 
7 segment led interfacing with 8051
7 segment led interfacing with 80517 segment led interfacing with 8051
7 segment led interfacing with 8051
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 

Similar to 8 interrupt 8051

Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming vijaydeepakg
 
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
 
Dsp interrupciones
Dsp interrupcionesDsp interrupciones
Dsp interrupcionesJuan Villeda
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interruptstt_aljobory
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051Anil Maurya
 
unit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppunit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppsachin397946
 
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
 
Microbots: microcontroller msp430
Microbots: microcontroller msp430Microbots: microcontroller msp430
Microbots: microcontroller msp430crisurdiales
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Vikas Dongre
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxSujalKumar73
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontrollerTearsome Llantada
 

Similar to 8 interrupt 8051 (20)

DPA
DPADPA
DPA
 
Interrupt.pptx
Interrupt.pptxInterrupt.pptx
Interrupt.pptx
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
Dsp interrupciones
Dsp interrupcionesDsp interrupciones
Dsp interrupciones
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interrupts
 
Embedded systems, lesson 16
Embedded systems, lesson 16Embedded systems, lesson 16
Embedded systems, lesson 16
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051
 
Interrupt
InterruptInterrupt
Interrupt
 
8051
80518051
8051
 
unit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppunit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxppppppppppppppppppppppppppp
 
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
 
8051 Interrupts
8051 Interrupts8051 Interrupts
8051 Interrupts
 
Microbots: microcontroller msp430
Microbots: microcontroller msp430Microbots: microcontroller msp430
Microbots: microcontroller msp430
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontroller
 
8051
80518051
8051
 

Recently uploaded

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

8 interrupt 8051

  • 1. 8051 Interrupts M_Nokhodchian @ yahoo.com Microprocessors 1-1
  • 2. Interrupts Programming  An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Interrupts vs. Polling  A single microcontroller can serve several devices.  There are two ways to do that:  interrupts  polling.  The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler. M_Nokhodchian @ yahoo.com Microprocessors 1-2
  • 3. Steps in executing an interrupt  Finish current instruction and saves the PC on stack.  Jumps to a fixed location in memory depend on type of interrupt  Starts to execute the interrupt service routine until RETI (return from interrupt)  Upon executing the RETI the microcontroller returns to the place where it was interrupted. Get pop PC from stack M_Nokhodchian @ yahoo.com Microprocessors 1-3
  • 4. Interrupt Sources  Original 8051 has 6 sources of interrupts  Reset  Timer 0 overflow  Timer 1 overflow  External Interrupt 0  External Interrupt 1  Serial Port events (buffer full, buffer empty, etc)  Enhanced version has 22 sources  More timers, programmable counter array, ADC, more external interrupts, another serial port (UART) M_Nokhodchian @ yahoo.com Microprocessors 1-4
  • 5. Interrupt Vectors Each interrupt has a specific place in code memory where program execution (interrupt service routine) begins. External Interrupt 0: 0003h Timer 0 overflow: 000Bh External Interrupt 1: 0013h Timer 1 overflow: 001Bh Note: that there are Serial : 0023h only 8 memory Timer 2 overflow(8052+) 002bh locations between vectors. M_Nokhodchian @ yahoo.com Microprocessors 1-5
  • 6. ISRs and Main Program in 8051 SJMP main ORG 03H ljmp int0sr ORG 0BH ljmp t0sr ORG 13H ljmp int1sr ORG 1BH ljmp t1sr ORG 23H ljmp serialsr ORG 30H main: … END M_Nokhodchian @ yahoo.com Microprocessors 1-6
  • 7. Interrupt Enable (IE) register All interrupt are disabled after reset We can enable and disable them bye IE M_Nokhodchian @ yahoo.com Microprocessors 1-7
  • 8. Enabling and disabling an interrupt by bit operation Recommended in the middle of program SETB EA SETB IE.7 ;Enable All SETB ET0 SETB IE.1 ;Enable Timer0 ovrf SETB ET1 SETB IE.3 ;Enable Timer1 ovrf SETB EX0 SETB IE.0 ;Enable INT0 SETB EX1 SETB IE.2 ;Enable INT1 SETB ES ;Enable Serial port SETB IE.4 by mov instruction Recommended in the first of program MOV IE, #10010110B M_Nokhodchian @ yahoo.com Microprocessors 1-8
  • 9. Example  A 10khz square wave with 50% duty cycle ORG 0 ;Reset entry poit LJMP MAIN ;Jump above interrupt ORG 000BH ;Timer 0 interrupt vector T0ISR:CPL P1.0 ;Toggle port bit RETI ;Return from ISR to Main program ORG 0030H ;Main Program entry point MAIN: MOV TMOD,#02H ;Timer 0, mode 2 MOV TH0,#-50 ;50 us delay SETB TR0 ;Start timer MOV IE,#82H ;Enable timer 0 interrupt SJMP $ ;Do nothing just wait END M_Nokhodchian @ yahoo.com Microprocessors 1-9
  • 10. Example  Write a program using interrupts to simultaneously create 7 kHz and 500 Hz square waves on P1.7 and P1.6. 8051 143µs 71µs P1.7 2ms P1.6 1ms M_Nokhodchian @ yahoo.com Microprocessors 1-10
  • 11. ORG 0 Solution LJMP MAIN ORG 000BH LJMP T0ISR ORG 001BH LJMP T1ISR 8051 143µs ORG 0030H 71µs P1.7 MAIN: MOV TMOD,#12H MOV TH0,#-71 SETB TR0 SETB TF1 MOV IE,#8AH 2ms MOV IE,#8AH P1.6 1ms SJMP $ T0ISR: CPL P1.7 RETI T1ISR: CLR TR1 MOV TH1,#HIGH(-1000) MOV TL1,#LOW(-1000) SETB TR1 CPL P1.6 RETI END M_Nokhodchian @ yahoo.com Microprocessors 1-11
  • 12. Timer ISR  Notice that  There is no need for a “CLR TFx” instruction in timer ISR  8051 clears the TF internally upon jumping to ISR  Notice that  We must reload timer in mode 1  There is no need on mode 2 (timer auto reload) M_Nokhodchian @ yahoo.com Microprocessors 1-12
  • 13. External interrupt type control  By low nibble of Timer control register TCON  IE0 (IE1): External interrupt 0(1) edge flag.  set by CPU when external interrupt edge (H-to-L) is detected.  Does not affected by H-to-L while ISR is executed(no int on int)  Cleared by CPU when RETI executed.  does not latch low-level triggered interrupt  IT0 (IT1): interrupt 0 (1) type control bit.  Set/cleared by software  IT=1 edge trigger  IT=0 low-level trigger (MSB) (LSB) TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Timer 1 Timer0 for Interrupt M_Nokhodchian @ yahoo.com Microprocessors 1-13
  • 14. External Interrupts (Level-triggered (default INT0 (Pin 3.2) 0 0003 IT0 1 (IE0 (TCON.3 2 Edge-triggered (Level-triggered (default INT0 (Pin 3.3) 0 0013 IT1 1 (IE1 (TCON.3 2 Edge-triggered M_Nokhodchian @ yahoo.com Microprocessors 1-14
  • 15. Example of external interuupt ORG 0000H LJMP MAIN ; ;interrupt service routine (ISR) ;for hardware external interrupt INT1 ; ORG 0013H SETB P1.1 MOV R0,200 WAIT: DJNZ R0,WAIT CLR P1.1 RETI ; ;main program for initialization ; ORG 30H MAIN: SETB IT1 ;on negative edge of INT1 MOV IE,#10000100B WAIT2: SJMP WAIT2 END M_Nokhodchian @ yahoo.com Microprocessors 1-15
  • 16. Example of external interuupt M_Nokhodchian @ yahoo.com Microprocessors 1-16
  • 17. Example of external interuupt Org 0000h Ljmp main Org 0003h x0isr: clr p1.7 Reti Org 0013h x1isr: setb p1.7 Reti Org 0030h Main: mov ie,#85h Setb it0 Setb it1 Setb p1.7 Jb p3.2,skip Clr p1.7 Skip: Sjmp $ end M_Nokhodchian @ yahoo.com Microprocessors 1-17
  • 18. Interrupt Priorities  What if two interrupt sources interrupt at the same time?  The interrupt with the highest PRIORITY gets serviced first.  All interrupts have a power on default priority order. 1. External interrupt 0 (INT0) 2. Timer interrupt0 (TF0) 3. External interrupt 1 (INT1) 4. Timer interrupt1 (TF1) 5. Serial communication (RI+TI)  Priority can also be set to “high” or “low” by IP reg. M_Nokhodchian @ yahoo.com Microprocessors 1-18
  • 19. Interrupt Priorities (IP) Register --- --- PT2 PS PT1 PX1 PT0 PX0 IP.7: reserved IP.6: reserved IP.5: timer 2 interrupt priority bit(8052 only) IP.4: serial port interrupt priority bit IP.3: timer 1 interrupt priority bit IP.2: external interrupt 1 priority bit IP.1: timer 0 interrupt priority bit IP.0: external interrupt 0 priority bit M_Nokhodchian @ yahoo.com Microprocessors 1-19
  • 20. Interrupt Priorities Example --- --- PT2 PS PT1 PX1 PT0 PX0  MOV IP , #00000100B or SETB IP.2 gives priority order 1. Int1 2. Int0 3. Timer0 4. Timer1 5. Serial  MOV IP , #00001100B gives priority order 1. Int1 2. Timer1 3. Int0 4. Timer0 5. Serial M_Nokhodchian @ yahoo.com Microprocessors 1-20
  • 21. Interrupt inside an interrupt --- --- PT2 PS PT1 PX1 PT0 PX0  A high-priority interrupt can interrupt a low-priority interrupy  All interrupt are latched internally  Low-priority interrupt wait until 8051 has finished servicing the high-priority interrupt M_Nokhodchian @ yahoo.com Microprocessors 1-21