8051 Interrupt Programming By Dr. Min He.
8051 Interrupts Interrupt sources and priority levels Interrupt polling priority Interrupt vector table Registers used by interrupts Hardware steps in executing interrupts Software steps to enable an interrupt Handling external interrupts Interrupt Programming
Introducing Interrupts Interrupts and resets are among the most useful mechanisms that a computer system provides. Benefits provided by interrupts and resets: I/O operations are performed more efficiently Errors a r e handled more smoothly, and  CPU utilization is improved. An interrupt is an event that requires the CPU to stop normal program execution and perform a special piece of code called  Interrupt Service Routine (ISR)  related to the event. External Interrupt:  an external signal that is used to get the attention of the CPU Internal Interrupt:  all microcontrollers has on-chip peripheral devices such as timers, A/D converters, serial peripheral interface, and so on. Signals asserted by these devices to get the attentions of the CPU are called internal interrupts. Software Interrupt:  internal interrupt generated by software errors such as illegal opcodes, overflow, divided-by-zero, and underflow.
Interrupt Service Routine Similar to a procedure call, except that it can occur between any two instructions of the program is transparent to the running program (usually) is typically  not  explicitly requested by the program calls a routine at an address determined by the type of interrupt, not by the program atomically changes some processor mode bits in some special function register, such as TCON in 8051.
Common 8051 Interrupts There are 5 interrupt sources in common 8051. A unique number is assigned to each interrupt: Can set up two interrupt levels. Interrupt Name Number External Interrupt 0 INT0 0 Timer Interrupt 0 TF0 1 External Interrupt 1 INT1 2 Timer Interrupt 1 TF1 3 Serial Interrupt 1 R1+T1 4 Timer 2 TF2 5
Interrupt Polling Priority Upon Reset External Interrupt 0 Timer Interrupt 0 External Interrupt 1 Timer Interrupt 1 Serial Communication
Interrupt Vector Table Interrupt ISR ROM Address (Hex) Pin Flag Clearing Reset 0000 9 Auto External Hardware interrupt 0 (INT0) 0003 P3.2 Auto Timer 0 Interrupt (TF0) 000B Auto External Hardware interrupt 1 (INT1) 0013 P3.3 Auto Timer 1 Interrupt (TF1) 001B Auto Serial COM Interrupt (RI and TI) 0023 Programmer clears it.
Registers Used by Interrupts IE  (Interrupt Enable) : to enable interrupts  IP: set interrupt priority if needed TCON: if external interrupt is used, set control bit: edge-triggered vs. level-triggered. EA -- ET2 ES ET1 EX1 ET0 EX0 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 -- -- PT2 PS PT1 PX1 PT0 PX0
Hardware Steps in Executing an Interrupt Finish executing current instruction and save the address of the next one (PC) on the stack. Save status of all the interrupts internally (not on the stack). Jump to interrupt vector table Get the address of the ISR from interrupt vector table, and jump to execute the ISR. The microcontroller get PC from top of stack and returns to the place where it was interrupted upon executing the RETI instruction of the ISR.
Software Steps to Enable an Interrupt Set EA to enable interrupt EA=1; Set the corresponding interrupt bit in IE to enable a specific interrupt  Example:   ET0 = 1; enable timer 0 overflow interrupt EX0 = 1; enable external interrupt 0
External Interrupts   --Level-triggered vs. Edge-triggered Level-triggered:  Default mode upon reset of the 8051 A low-level signal triggers the interrupt.  The low signal must be held low before the execution of ISR and must be removed before RETI. Edge-triggered:  A high-to-low signal triggers the interrupt Need to set TCON.0(IT0)/TCON.2(IT1)  TCON.1(IE0) and TCON.3(IE1) are set when an falling edge is detected and cleared by RETI.
Use TCON Register to Setup External Interrupts D7 D0 IE1/IE0 : external interrupt 1 & 0 edge flag. Set by CPU when the external interrupt edge is detected. Cleared by CPU when the interrupt is processed. IT1/IT0 : external interrupt 1 & 0 type control bit. Set/cleared by software to specify falling edge/low-level triggered interrupts. TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Sampling of External Interrupts Level-triggered external interrupt: To ensure the activation of the hardware interrupt at the INTn pin, the duration of the low-level signal should be around 4 machine cycles, but not more. This is due to the fact that the level-triggered interrupt is not latched. Edge-triggered external interrupt: the 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.
Interrupt-in-service Flag: IEx Used to keep track of edge-triggered external interrupt only The falling edge is latched by interrupt-in-service flag: IE0/IE1 is set by CPU when external interrupt is detected. No other external interrupt on the same pin will be responded when IE0/IE1 is raised. These flags are cleared when the ISRs are finished upon execution of instruction RETI.
Interrupt Programming  In main: set interrupt mode Ex: Enable external interrupt 0, set it to be edge triggered: IT0=1; // set INT0 to be edge triggered  EX0=1; // enable INT0  EA=1; // enable interrupt  Write ISR function: bit my_flag; … . void chg_mode(void)   interrupt 0 { my_flag=1; } Notice : No function prototype is needed for interrupt service routine. The  interrupt  keyword tells the compiler function chg_mode is an ISR. The number  tell the compiler the interrupt source for the ISR.
Example: Furnace Controller Using interrupts, design an 8051 furnace controller that keeps a building at 20  C+/-1C  . Solution: The furnace ON/OFF solenoid is connected to P1.7 such that: P1.7 = 1 for furnace ON, P1.7=0 for furnace OFF. Temperature sensor is connected to external interrupt 0 and 1 to provide HOT and COLD signal.
Reading Assignment “ Embedded System Design with the C8051 ”, by Han-Way Huang. ISBN: 978-0495-47174-5, Publisher: Cengage Learning, Copyright: 2009. Chapter 6, sections 1, 2, 4.

More Related Content

PPTX
Interrupts programming in embedded C using 8051
PPTX
37471656 interrupts
PPT
8051 Inturrpt
PPT
8 interrupt 8051
PPTX
Micro controller 8051 Interrupts
PPT
8051 interrupts
PPT
Interrupt programming with 8051 microcontroller
Interrupts programming in embedded C using 8051
37471656 interrupts
8051 Inturrpt
8 interrupt 8051
Micro controller 8051 Interrupts
8051 interrupts
Interrupt programming with 8051 microcontroller

What's hot (20)

PPTX
Interrupts in 8051
PPTX
Interrupt programming
PDF
Unit 5_Interrupt programming in 8051 micro controller - part 2
PPTX
Embedded systems, lesson 16
PPTX
Mc module5 ppt_msj
PDF
Timer And Counter in 8051 Microcontroller
PPT
I o ports and timers of 8051
PDF
8051 Timers / Counters
PDF
Interrupt
PDF
At89 c51
PPTX
Interrupts on 8086 microprocessor by vijay kumar.k
PDF
PPTX
Mouse interrupts (Assembly Language & C)
PPT
1206 Interrupts Of 8085
PPTX
Interrupt 8085
PPTX
Interrupt in 8051
PPTX
I o ports.ppt
PDF
PDF
At 89s51
Interrupts in 8051
Interrupt programming
Unit 5_Interrupt programming in 8051 micro controller - part 2
Embedded systems, lesson 16
Mc module5 ppt_msj
Timer And Counter in 8051 Microcontroller
I o ports and timers of 8051
8051 Timers / Counters
Interrupt
At89 c51
Interrupts on 8086 microprocessor by vijay kumar.k
Mouse interrupts (Assembly Language & C)
1206 Interrupts Of 8085
Interrupt 8085
Interrupt in 8051
I o ports.ppt
At 89s51
Ad

Viewers also liked (20)

PPTX
Direct memory access
PPT
Interrupt
PDF
Interrupts
PDF
Interrupt
PPTX
8051 Microcontroller ppt
DOC
8051 Microcontroller Notes
PPTX
8051 memory
DOC
Pull up & pull-down resistors
PDF
Nios2 and ip core
PPTX
Server-side optimization for next-generation ssd in G-Cube
PPT
Fpga 02-memory-and-pl ds
PDF
Basic circuit or cad
PDF
8051 Microcontroller Timer
PPT
Why sending patches back is so important
PDF
Llpc2148 sci
PDF
Operating systems
PDF
PLD's
PDF
Embedded systems ppt iv part b
PDF
Embedded systems ppt iv part a
PDF
8051 Microcontroller I/O ports
Direct memory access
Interrupt
Interrupts
Interrupt
8051 Microcontroller ppt
8051 Microcontroller Notes
8051 memory
Pull up & pull-down resistors
Nios2 and ip core
Server-side optimization for next-generation ssd in G-Cube
Fpga 02-memory-and-pl ds
Basic circuit or cad
8051 Microcontroller Timer
Why sending patches back is so important
Llpc2148 sci
Operating systems
PLD's
Embedded systems ppt iv part b
Embedded systems ppt iv part a
8051 Microcontroller I/O ports
Ad

Similar to DPA (20)

PDF
8051-interrupts-temporary suspension of a program
PPTX
Interrupt.pptx
PPTX
8051 interrupt Presentation Download for ECE
PPTX
Interrupt in 8051 microcontrollers .pptx
PPTX
8051 Microcontroller Overview by Venkatrao Ramisetti
PPTX
Interrupts of 8051 microcontroller.newpp
PPTX
Interrupt in ATMEGA328P.pptx
PPTX
unit 3 a.pptxppppppppppppppppppppppppppp
PPTX
interrupts programming in 8051 microcontroller
PPTX
visitor counter_POLICE_NEWT0N_789456.pptx
PDF
Microprocessor 8051
PDF
interrupts of 8051.pdf
PDF
8051 Interrupts
PPTX
LECTURE_8 Interrupts.pptx hello and thanks for the University of
PDF
Lecture7
PPT
Interrupts for PIC18
PPTX
INTERRUPTS OF 8086 MICROPROCESSOR
PDF
Microcontroller part 2
PPTX
Interrupts
PDF
Chapter 7 Interrupts in microprocessor and assembly language.pdf
8051-interrupts-temporary suspension of a program
Interrupt.pptx
8051 interrupt Presentation Download for ECE
Interrupt in 8051 microcontrollers .pptx
8051 Microcontroller Overview by Venkatrao Ramisetti
Interrupts of 8051 microcontroller.newpp
Interrupt in ATMEGA328P.pptx
unit 3 a.pptxppppppppppppppppppppppppppp
interrupts programming in 8051 microcontroller
visitor counter_POLICE_NEWT0N_789456.pptx
Microprocessor 8051
interrupts of 8051.pdf
8051 Interrupts
LECTURE_8 Interrupts.pptx hello and thanks for the University of
Lecture7
Interrupts for PIC18
INTERRUPTS OF 8086 MICROPROCESSOR
Microcontroller part 2
Interrupts
Chapter 7 Interrupts in microprocessor and assembly language.pdf

More from Ramasubbu .P (20)

PPT
PPT
PPT
Milling 2
PPT
MIlling 1
PPT
Drillings
PPT
Holding
PPT
Saftey
PPT
Harvesting
PPT
Plough
PPT
Tractor PTO
PPT
Tractor Components
PPT
PPT
PPT
PPT
PPT
Hacker
PPT
Denail of Service
PPT
RAID CONCEPT
PPT
Network Security
PPT
Milling 2
MIlling 1
Drillings
Holding
Saftey
Harvesting
Plough
Tractor PTO
Tractor Components
Hacker
Denail of Service
RAID CONCEPT
Network Security

Recently uploaded (20)

PDF
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
PDF
Climate and Adaptation MCQs class 7 from chatgpt
PDF
MA in English at Shiv Nadar University – Advanced Literature, Language & Rese...
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
PDF
CRP102_SAGALASSOS_Final_Projects_2025.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPT
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
PPTX
2025 High Blood Pressure Guideline Slide Set.pptx
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PPTX
Education and Perspectives of Education.pptx
PPTX
Climate Change and Its Global Impact.pptx
PDF
The TKT Course. Modules 1, 2, 3.for self study
PPTX
Module on health assessment of CHN. pptx
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PPTX
UNIT_2-__LIPIDS[1].pptx.................
PDF
semiconductor packaging in vlsi design fab
PPTX
Thinking Routines and Learning Engagements.pptx
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
Climate and Adaptation MCQs class 7 from chatgpt
MA in English at Shiv Nadar University – Advanced Literature, Language & Rese...
Everyday Spelling and Grammar by Kathi Wyldeck
CRP102_SAGALASSOS_Final_Projects_2025.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
2025 High Blood Pressure Guideline Slide Set.pptx
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Education and Perspectives of Education.pptx
Climate Change and Its Global Impact.pptx
The TKT Course. Modules 1, 2, 3.for self study
Module on health assessment of CHN. pptx
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
UNIT_2-__LIPIDS[1].pptx.................
semiconductor packaging in vlsi design fab
Thinking Routines and Learning Engagements.pptx
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic

DPA

  • 1. 8051 Interrupt Programming By Dr. Min He.
  • 2. 8051 Interrupts Interrupt sources and priority levels Interrupt polling priority Interrupt vector table Registers used by interrupts Hardware steps in executing interrupts Software steps to enable an interrupt Handling external interrupts Interrupt Programming
  • 3. Introducing Interrupts Interrupts and resets are among the most useful mechanisms that a computer system provides. Benefits provided by interrupts and resets: I/O operations are performed more efficiently Errors a r e handled more smoothly, and CPU utilization is improved. An interrupt is an event that requires the CPU to stop normal program execution and perform a special piece of code called Interrupt Service Routine (ISR) related to the event. External Interrupt: an external signal that is used to get the attention of the CPU Internal Interrupt: all microcontrollers has on-chip peripheral devices such as timers, A/D converters, serial peripheral interface, and so on. Signals asserted by these devices to get the attentions of the CPU are called internal interrupts. Software Interrupt: internal interrupt generated by software errors such as illegal opcodes, overflow, divided-by-zero, and underflow.
  • 4. Interrupt Service Routine Similar to a procedure call, except that it can occur between any two instructions of the program is transparent to the running program (usually) is typically not explicitly requested by the program calls a routine at an address determined by the type of interrupt, not by the program atomically changes some processor mode bits in some special function register, such as TCON in 8051.
  • 5. Common 8051 Interrupts There are 5 interrupt sources in common 8051. A unique number is assigned to each interrupt: Can set up two interrupt levels. Interrupt Name Number External Interrupt 0 INT0 0 Timer Interrupt 0 TF0 1 External Interrupt 1 INT1 2 Timer Interrupt 1 TF1 3 Serial Interrupt 1 R1+T1 4 Timer 2 TF2 5
  • 6. Interrupt Polling Priority Upon Reset External Interrupt 0 Timer Interrupt 0 External Interrupt 1 Timer Interrupt 1 Serial Communication
  • 7. Interrupt Vector Table Interrupt ISR ROM Address (Hex) Pin Flag Clearing Reset 0000 9 Auto External Hardware interrupt 0 (INT0) 0003 P3.2 Auto Timer 0 Interrupt (TF0) 000B Auto External Hardware interrupt 1 (INT1) 0013 P3.3 Auto Timer 1 Interrupt (TF1) 001B Auto Serial COM Interrupt (RI and TI) 0023 Programmer clears it.
  • 8. Registers Used by Interrupts IE (Interrupt Enable) : to enable interrupts IP: set interrupt priority if needed TCON: if external interrupt is used, set control bit: edge-triggered vs. level-triggered. EA -- ET2 ES ET1 EX1 ET0 EX0 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 -- -- PT2 PS PT1 PX1 PT0 PX0
  • 9. Hardware Steps in Executing an Interrupt Finish executing current instruction and save the address of the next one (PC) on the stack. Save status of all the interrupts internally (not on the stack). Jump to interrupt vector table Get the address of the ISR from interrupt vector table, and jump to execute the ISR. The microcontroller get PC from top of stack and returns to the place where it was interrupted upon executing the RETI instruction of the ISR.
  • 10. Software Steps to Enable an Interrupt Set EA to enable interrupt EA=1; Set the corresponding interrupt bit in IE to enable a specific interrupt Example: ET0 = 1; enable timer 0 overflow interrupt EX0 = 1; enable external interrupt 0
  • 11. External Interrupts --Level-triggered vs. Edge-triggered Level-triggered: Default mode upon reset of the 8051 A low-level signal triggers the interrupt. The low signal must be held low before the execution of ISR and must be removed before RETI. Edge-triggered: A high-to-low signal triggers the interrupt Need to set TCON.0(IT0)/TCON.2(IT1) TCON.1(IE0) and TCON.3(IE1) are set when an falling edge is detected and cleared by RETI.
  • 12. Use TCON Register to Setup External Interrupts D7 D0 IE1/IE0 : external interrupt 1 & 0 edge flag. Set by CPU when the external interrupt edge is detected. Cleared by CPU when the interrupt is processed. IT1/IT0 : external interrupt 1 & 0 type control bit. Set/cleared by software to specify falling edge/low-level triggered interrupts. TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
  • 13. Sampling of External Interrupts Level-triggered external interrupt: To ensure the activation of the hardware interrupt at the INTn pin, the duration of the low-level signal should be around 4 machine cycles, but not more. This is due to the fact that the level-triggered interrupt is not latched. Edge-triggered external interrupt: the 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.
  • 14. Interrupt-in-service Flag: IEx Used to keep track of edge-triggered external interrupt only The falling edge is latched by interrupt-in-service flag: IE0/IE1 is set by CPU when external interrupt is detected. No other external interrupt on the same pin will be responded when IE0/IE1 is raised. These flags are cleared when the ISRs are finished upon execution of instruction RETI.
  • 15. Interrupt Programming In main: set interrupt mode Ex: Enable external interrupt 0, set it to be edge triggered: IT0=1; // set INT0 to be edge triggered EX0=1; // enable INT0 EA=1; // enable interrupt Write ISR function: bit my_flag; … . void chg_mode(void) interrupt 0 { my_flag=1; } Notice : No function prototype is needed for interrupt service routine. The interrupt keyword tells the compiler function chg_mode is an ISR. The number tell the compiler the interrupt source for the ISR.
  • 16. Example: Furnace Controller Using interrupts, design an 8051 furnace controller that keeps a building at 20  C+/-1C  . Solution: The furnace ON/OFF solenoid is connected to P1.7 such that: P1.7 = 1 for furnace ON, P1.7=0 for furnace OFF. Temperature sensor is connected to external interrupt 0 and 1 to provide HOT and COLD signal.
  • 17. Reading Assignment “ Embedded System Design with the C8051 ”, by Han-Way Huang. ISBN: 978-0495-47174-5, Publisher: Cengage Learning, Copyright: 2009. Chapter 6, sections 1, 2, 4.

Editor's Notes

  • #2: Memory space Parallel ports