* * * * * * * 8051 Interrupts Programming.

Slides:



Advertisements
Similar presentations
Interrupts Professor Yasser Kadah –
Advertisements

8051 Core Specification.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
Chapter 6 Interrupts (I. Scott Mackenzie).
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
Embedded Systems 7763B Mt Druitt College of TAFE
Introduction to Embedded Systems
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
Interrupt.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Microprocessors 1 MCS-51 Interrupts.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
Lecture 8 Interrupts. 2  Introduction  Interrupt organization  Interrupt summary  Enabling and disabling interrupts  Interrupt priority  Interrupt.
8051 Micro controller. Architecture of 8051 Features of 8051.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
MCS51 - lecture 5. Lecture 5 2/28 Interrupts in MCS51 Step work Power consumption reducing.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Chapter 11 INTERRUPTS PROGRAMMING
8085 Interrupts LAKSHMI.B.E..
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Timer and Interrupts.
Computer Architecture
Interrupts In 8085 and 8086.
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
Timer Operations and Programming
Interrupt.
Lecture 8 Interrupts.
Subject Name: Microprocessors Subject Code:10EC46 Department: Electronics and Communication Date: /20/2018.
Computer System Overview
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
Processor Fundamentals
11.1 Interrupt Mechanism, Type, and Priority
X1 & X2 These are also called Crystal Input Pins.
Interrupt Source: under
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupt.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupt Source: under
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer System Overview
Interrupts of 8051 Introduction 8051 Interrupt organization
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

* * * * * * * 8051 Interrupts Programming

8051 Interrupts An interrupt is the occurrence of a condition – an event - which interrupts normal program flow Interrupts allow a system to respond to asynchronous events (not in program flow) and handle the events while another task is running An interrupt driven system gives the illusion of doing many things simultaneously (multitasking on one CPU) The routine that deal’s with a specific interrupt is called an Interrupt Service Routine (ISR) or an “interrupt handler” Interrupts routines are activated by the occurrence of either an external or an internal event (a.k.a. exceptions) Interrupt routines are said to run in the “background” while the main system program runs in the “foreground”

Interrupt Service Interrupts allow the 8051 to respond to asynchronous events (external or internal) only when required. The alternative is called “polling” – testing status bits - which can be time consuming, wasting precious CPU resources/cycles Interrupts introduce the concept of “priority” where one interrupt is given preference over another simultaneous interrupt Interrupt Vectors--where is the address of the ISR when a particular interrupt occurs? only when interrupts are enabled 8051 Interrupt Vector Table (Atmel 89C51RD2 has 3 more – not covered) Interrupt Vector Address Number Bytes Pin Flag Clearing Comment Reset 0000H 3 Auto Power-on INT0 0003H 8 P3.2 External Hardware TF0 000BH Timer 0 INT1 0013H P3.3 TF1 001BH Timer 1 RI/TI 0023H Programmer Serial Communication TF2/EXF2 002Bh Timer 2 Each has 2 possible reasons for interrupt

Interrupt Service Sequence When an interrupt is activated the 8051… Finishes the instruction currently being executed Saves the current status of all the interrupts and stores the current PC  Stack Vectors (i.e. jumps) to the corresponding location within the interrupt vector table, i.e. PC  Vector Table address Option 1: If the ISR fits in the available space you can immediately service the interrupt Option 2: If the ISR is too large then the vector table contains a long jump (ljmp) to the Interrupt Service Routing (ISR) The last instruction of the ISR is a “reti” (Return from Interrupt) Responsibility of ISR to save/restore any registers that it uses, including the PSW, having the same number of pushes and pops to/from the stack for the “reti” instruction to work correctly Original PC is popped off the stack – returning to where program was when the interrupt occurred

Enabling/Disabling Interrupts All interrupts are disabled (masked) at system reset Software enables those interrupts required IE (A8h) Interrupt Enable SFR is used to enable/disable interrupts EA -- ET2 ES ET1 EX1 ET0 EX0 7 6 5 4 3 2 1 0 EA IE.7 Global enable. If EA = 0, no interrupt is acknowledged. If EA = 1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit - IE.6 Not implemented. Don’t set. ET2 IE.5 Enables/disables Timer 2 TF2 or EXF2 interrupt (8052) ES IE.4 Enables/disables Serial Port RI or TI interrupt ET1 IE.3 Enables/disables Timer 1 overflow interrupt EX1 IE.2 Enables/disables External interrupt 1 ET0 IE.1 Enables/disables Timer 0 overflow interrupt EX0 IE.0 Enables/disables External interrupt 0

Interrupt Priority Levels Each interrupt source is individually programmed as being a “high” or “low” priority interrupt Prioritized allows resolution of simultaneous interrupts Prioritized interrupts allow for “preemptive” interrupt handlers IP (B8h) – Interrupt Priority SFR Priority is either high (1) or low (0) If an ISR is active and a higher priority interrupt occurs, it is interrupted (i.e. preempted). A high level ISR can not be interrupted. -- IP.7 Undefined -- IP.6 Undefined PT2 IP.5 Priority for Timer 2 interrupt PS IP.4 Priority for serial port interrupt PT1 IP.3 Priority for Timer 1 interrupt PX1 IP.2 Priority for external 1 interrupt PT0 IP.1 Priority for Timer 0 interrupt PX0 IP.0 Priority for external 0 interrupt

Interrupt Priority Levels (enhanced) Each interrupt source is individually programmed to one of four priority levels (00, 01, 10, 11) IPH (B7h) – Interrupt Priority HIGH IPL (B8h) – Interrupt Priority LOW Priority from highest to lowest (3,2,1,0) If an ISR is active and a higher priority interrupt occurs, it is interrupted. A higher level ISR can not be interrupted. Equal priorities yield to polling sequence (cf. page 75, AT8951RD2 spec) -- IP (H/L). 7 Undefined -- IP (H/L). 6 PCA (Programmable Counter Array) PT2 IP (H/L). 5 Priority for Timer 2 interrupt PS IP (H/L). 4 Priority for serial port interrupt PT1 IP (H/L). 3 Priority for Timer 1 interrupt PX1 IP (H/L). 2 Priority for external 1 interrupt PT0 IP (H/L). 1 Priority for Timer 0 interrupt PX0 IP (H/L). 0 Priority for external 0 interrupt

External Interrupts 8051 has two external interrupts: INT0 and INT1 Tied to external pins: INT0 (P3.2), INT1 (P3.3) P3.2 and P3.3 are general purpose I/O pins until the respective Interrupt Enable bits are set (i.e. EX0 and EX1, respectively) Activation of external interrupts 8051 external interrupts activated in one of two ways (1) Level-triggered of (2) edge-triggered TCON.0 (IT0) and TCON.2 (IT1) defines “interrupt type“ IT0/IT1 = 0 for level-triggered interrupts (default) IT0/IT1 = 1 for edge triggered interrupts INT1 Vcc 8051 Pull-up IE1 IT1 TCON (88h) 7 6 5 4 3 2 1 0 IE0 IT0 TF1 TR1 TF0 TR0

External Interrupts (cont.) Level-triggered interrupts INT0/INT1 held normally HIGH. A LOW level on one of these signals will trigger the respective interrupt The 8051 keeps sampling INTn for a LOW once each machine cycle Some 8051’s specify that “the pin must be held in a LOW state until the start of the execution of the ISR. If the INTn pin is brought back to a HIGH before the start of the ISR, there will be no interrupt.” Thus, to ensure activation of an external interrupt, it must remain LOW for at least 4 machine cycles The LOW on the pin must be removed before the last instruction in the ISR (reti) is executed else another interrupt will occur

External Interrupts (cont.) Edge-triggered interrupts Setting IT1 or IT0 to “1” programs the 8051 to detect edge-triggered signals INT1/INT0 held normally HIGH. A HIGH-to-LOW transition on one of these signals will trigger the respective interrupt In edge-triggered interrupts, the INT1/INT0 signal 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 8051 The 8051 automatically sets the respective “External Interrupt Edge Flag” (IE1/IE0) in the TCON register when using edge-trigerring Regarding the “Interrupt Type” bits (IT1/IT0) in the TCON register, the following two points must be emphasized: Upon execution of a “RETI” instruction, the respective IEn bit will be cleared automatically, indicating the edge-triggered interrupt has been serviced While the ISR is being executed, the 8051 ignores all transitions on the external interrupt signals INT1/INT0 IE1 IT1 TCON (88h) 7 6 5 4 3 2 1 0 IE0 IT0 TF1 TR1 TF0 TR0

Review of Timer Control register - TCON TCON (88h) Bit Symbol Comment TCON.7 TF1 T1 Overflow Flag TCON.6 TR1 T1 Run Control (1=ON, 0=OFF) TCON.5 TF0 T0 Overflow Flag TCON.4 TR0 T1 Run Control (1=ON, 0=OFF) TCON.3 IE1 EI1 edge flag. SET on H2L transition. Cleared by CPU TCON.2 IT1 I1 type control. 1=falling edge,0=low-level activated TCON.1 IE0 EI0 edge flag. SET on H2L transition. Cleared by CPU TCON.0 IT0 I0 type control. 1=falling edge,0=low-level activated Edge-detect: the input must be held HIGH for one cycle and LOW for another. IE0/IE1 automatically cleared when CPU vectors to interrupt Level-activated: the input must be held until interrupt generated. Must also be de-activated before the ISR is completed. Usually the ISR “acknowledges” the interrupt and the interrupting device removes the interrupt request External Interrupts are sampled once each machine cycle so input should be held for at least 12 oscillator periods to ensure proper sampling

Programming the Serial Comm. Interrupt TI (Transmit Interrupt) is set when the last bit of framed data, the stop bit, is transmitted – indicating that SBUF is empty and ready for another byte RI (Receive Interrupt) is set when an entire frame of data is correctly received indicating that SBUF now has a byte ready to be read Behavior of TI and RI is the same whether we are polling or using interrupts. Difference is how we detect and respond to its occurrence TI and RI are OR’d to generate a single interrupt User must determine which is the source in the ISR Typical use relies on RI for data received but will poll TI to ensure data sent Analogous to receiving and generating a phone call Always clear TI or RI prior to execution of reti