CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

Similar documents
Chapter 6 Interrupts. (I. Scott Mackenzie) By: Masud-ul-Hasan

8051 Interrupt Organization

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

CPEG300 Embedded System Design. Lecture 6 Interrupt System

8051 I/O and 8051 Interrupts

INTERRUPTS PROGRAMMING

CHAPTER 11 INTERRUPTS PROGRAMMING

MCS-51 Serial Port A T 8 9 C 5 2 1

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

Interrupt Programming: Interrupts vs. Polling Method:

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

8051 Timers and Serial Port


Chapter 09. Programming in Assembly

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

Mod-3: Interrupts,Timer operation,serial communication 1

Chapter 09. Programming in Assembly

CPEG300 Embedded System Design. Lecture 8 Timer

8051 Microcontroller Interrupts

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Timers and interrupts

ELEG3923 Microprocessor Ch.9 Timer Programming

Introduction To MCS-51

8051 Microcontroller memory Organization and its Applications

Microprocessors and Microcontrollers (EE-231)

Embedded Controller Programming

MicroConverter Technical Note uc001 MicroConverter I 2 C Compatible Interface

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Serial Port Programming in Assembly Module No: CS/ES/12 Quadrant 1 e-text

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

The Timers/Counters The Serial Interface The Interrupt System Reset P0.0-P0.7 P2.0-P2.7. Port 2 Drivers. Port 2 Latch

8051 Serial Communication

Microcontroller and Embedded Systems:

EE6502- MICROPROCESSOR AND MICROCONTROLLER


CS 320. Computer Architecture Core Architecture

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

These three counters can be programmed for either binary or BCD count.

Serial I-O for Dinesh K. Sharma Electrical Engineering Department I.I.T. Bombay Mumbai (version 14/10/07)

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

How to use the PSoC based 16C450 Replacement

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATION ENGINEERING QUESTION BANK

~: Simple Programs in 8051 assembly language :~

8051 Microcontroller. Ali Ziya Alkar 1

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

ELEG3923 Microprocessor Ch.4 I/O Ports

8051 Core Specification


Department of Electronics and Instrumentation Engineering Question Bank

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

A Facilitated Learning Environment for Mentally Disabled Children

C51 Family. Architectural Overview of the C51 Family. Summary

Microcontroller and Applications

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Advantages of Using a Dallas Semiconductor DS1232 MicroMonitor

80C451 operation of port 6

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

MLR INSTITUTE OF TECHNOLOGY DUNDIGAL , HYDERABAD

The Final Word on 8051 Microcontroller

Microcontroller Intel [Instruction Set]

8051 Microcontroller

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.


Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

INTEGRATED CIRCUITS. AN433 I 2 C slave routines for the 83C751

ELEG3923 Microprocessor Ch.10 Serial Port Programming

Flash Microcontrollers. Application Note. Migrating from AT89C2051/C4051 to AT89LP2052/LP4052

User-defined Download Application Note

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

FACULTY OF ENGINEERING LAB SHEET

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Interrupt is a process where an external device can get the attention of the microprocessor. Interrupts can be classified into two types:

8-bit Microcontroller with 2/4-Kbyte Flash AT89LP2052 AT89LP4052

8086 Interrupts and Interrupt Responses:

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

Rev. No. History Issue Date Remark

MODULE-1. Short Answer Questions

MicroConverter Technical Note - uc007 User Download (ULOAD) Mode

MCS -51 Programmer s Guide and Instruction Set

INTEGRATED CIRCUITS. AN408 80C451 operation of port 6

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

WINTER 14 EXAMINATION

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Module Contents of the Module Hours COs

Interrupts Peter Rounce - room 6.18

Lecture 9. Timer Operations and Programming

Chapter 3. Bit Addressable Area. By DeccanRobots

INTEGRATED CIRCUITS DATA SHEET. P89C738; P89C739 8-bit microcontrollers Dec 15. Product specification File under Integrated Circuits, IC20

Timer Counter and Interrupt. Equation (16 bits counter, Mode 1, 16MHz):

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Overview and Instruction Set

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

Principle and Interface Techniques of Microcontroller

8085 Interrupts. Lecturer, CSE, AUST

MICROCONTROLLER BASED WATER LEVEL CONTROL SYSTEM

Transcription:

CoE3DJ4 Digital Systems Design Chapter 6: Interrupts

Interrupts An interrupt is the occurrence of an event that causes a temporary suspension of a program while the condition is serviced by another program. Allows a system to respond asynchronously to an event and deal with the event while another program is executing. An interrupt driven system gives the illusion of doing many things simultaneously. Of course, the CPU cannot execute more than one instruction at a time. It can temporarily suspend execution of one program, execute another, then return to the first program. In a way, interrupts are like subroutines. Except that one does not know when the interrupt code will be executed.

Interrupts Examples we covered in previous chapters did not use interrupts but made use of wait loops to test timer overflow flag or serial port transmit and receive flags In this approach the CPU s time is wasted waiting for flags to be set. We can use interrupts to avoid using wait loops. Interrupts If and when a device is ready and needs attention, it informs the CPU CPU drops whatever it was doing and serves the device and then returns back to its original task CPU is always free, when not serving any interrupts

Example: Write a program using Timer 0 to create a 10 khz square wave on P1.0 MOV TMOD,#02H MOV TH0,#-50 SETB TR0 LOOP: JNB TF0, LOOP CLR TF0 CPL P1.0 SJMP LOOP This program creates a square wave on P1.0 with a high-time of 50 us and low time of 50 us.

8051 Block Diagram

Interrupt Service Routines CPUs have fixed number of interrupts Every interrupt has to be associated with a piece of code called Interrupt Service Routine, or ISR. If interrupt-x is received by CPU, the ISR-x is executed ISRs are basically subroutines, but they end with the RETI, instruction instead of RET CPU architecture defines a specific code address for each ISR, which is stored in the Interrupt vector Table (IVT) When an interrupt occurs, the CPU fetches its ISR code address from the IVT and executes it.

Interrupt vector table Interrupt System reset External 0 Timer 0 External 1 Timer 1 Serial port Vector address 0000H 0003H 000BH 0013H 001BH 0023H

Interrupt Execution 1. CPU finishes the instruction it is currently executing and stores the PC on the stack 2. CPU saves the current status of all interrupts internally 3. Interrupts are blocked at the level of the interrupt 4. Fetches the ISR address for the interrupt from IVT and jumps to that address 5. Executes the ISR until it reaches the RETI instruction 6. Upon RETI, the CPU pops back the old PC from the stack and continues with whatever it was doing before the interrupt occurred

There are 5 interrupts in the 8051. 8051 Interrupts Two external interrupts (INT0 and INT1), two timer interrupts (TF0 and TF1) and one serial port interrupt. Interrupts can be individually enabled or disabled. This is done in the IE (Interrupt Enable) register (A8H). IE is bit addressable. All interrupts correspond to bits in registers. Therefore, it is possible to cause an interrupt by setting the appropriate bit in the appropriate register. The end result is exactly as if the hardware interrupt occurred.

The IE Register MSB LSB EA - ET2 ES ET1 EX1 ET0 EX0 Bit IE.7 IE.6 IE.5 IE.4 IE.3 IE.2 IE.1 IE.0 Name EA - ET2 ES ET1 EX1 ET0 EX0 Description Enable/Disable all interrupts If 0 all interrupts are disabled. If 1, interrupts are enabled based on their individual bits Reserved Enable/Disable Timer 2 interrupt (8052) Enable/Disable Serial Input Interrupt Enable/Disable Timer 1 Interrupt (TF1) Enable/Disable External Interrupt 1 (INT1) Enable/Disable Timer 0 Interrupt (TF0) Enable/Disable External Interrupt 0 (INT0) Putting a 1 in a bit enables its interrupt. Putting a 0 masks that interrupt.

Interrupt Priority The 8051 implements 2 types of interrupt priority. User Defined Priority. Using the IP register, the user can group interrupts into two levels high and low. An interrupt is assigned a high priority level by setting its bit in the IP register to 1. If the bit is set to 0, the interrupt gets a low priority. Automatic Priority. Within each priority level, a strict order is observed. Interrupts are polled in this sequence: INT0, TF0, INT1, TF1, Serial port.

The IP Register MSB LSB - - PT2 PS PT1 PX1 PT0 PX0 Bit Name Description IP.7 - Reserved IP.6 - Reserved IP.5 ET2 Timer 2 interrupt priority (8052) IP.4 ES Serial Port Interrupt priority IP.3 ET1 Timer 1 Interrupt priority (TF1) IP.2 EX1 External Interrupt 1 priority (INT1) IP.1 ET0 Timer 0 Interrupt priority (TF0) IP.0 EX0 External Interrupt 0 priority (INT0) Putting a 1 in a bit assigns its interrupt to the high priority level.

Interrupts Interrupt FLAG bit generating the interrupt SFR and Bit position Description External 0 IE0 TCON.1 Set by hardware when external interrupt detected. Cleared by hardware only if edge activated External 1 IE1 TCON.3 Set by hardware when external interrupt detected. Cleared by hardware only if edge activated Timer 1 TF1 TCON.7 Set by hardware on timer overflow. Cleared by hardware when processor vectors to interrupt routine Timer 0 TF0 TCON.5 Set by hardware on timer overflow. Cleared by hardware when processor vectors to interrupt routine Serial port TI or RI SCON.1 or SCON.0 Set by hardware on transmission or reception of data. Cleared by software

Bit addressable. TCON Register MSB LSB TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Bit TCON.7 TCON.6 TCON.5 TCON.4 TCON.3 TCON.2 TCON.1 TCON.0 Name TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Description Timer 1 overflow flag Timer 1 run-control bit. Used to turn the timer on/off Timer 0 overflow flag Timer 0 run-control bit. External Interrupt 1 flag External Interrupt 1 type flag External Interrupt 0 flag External Interrupt 0 type flag

Pending Interrupts If an interrupt occurs while it is disabled, or while a another interrupt is active (not lower priority), it becomes pending. As soon as the interrupt is enabled, it will cause a call. It is also possible to cancel it by software by clearing the appropriate bit in the register.

Interrupt service routines Interrupt service routines must begin near the bottom of code memory There are only eight bytes between each interrupt entry point This 8 bytes might be enough for short ISR If the ISR is long we can use a jump instruction to jump to another area of code memory where ISR can stretch out Interrupt System reset External 0 Timer 0 External 1 Timer 1 Serial port Vector address 0000H 0003H 000BH 0013H 001BH 0023H

Example Write a program using Timer 0 and interrupts to create a 10 khz square wave on P1.0 ORG 0 0000 LJMP MAIN ORG 000BH 000B T0ISR: CPL P1.0 000D RETI ORG 0030H 0030 MAIN: MOV TMOD,#02H 0033 MOV TH0,#-50 0036 SETB TR0 0038 MOV IE,#82H 003B SJMP $ TF0 is not cleared by software because it is automatically cleared by hardware when CPU services the interrupt

Example Write a program using interrupts to simultaneously create 7 khz and 500 Hz square waves on P1.7 and P1.6. Timer 0 operating in mode 2 is used to generate the 7 khz signal and timer 1 is used for 500 Hz signal operating in mode 1. ORG 0 0000 LJMP MAIN ORG 000BH 000B LJMP T0ISR ORG 001BH 001B LJMP T1ISR ORG 0030H 0030 MAIN: MOV TMOD, #12H 0033 MOV TH0,-71 0036 SETB TR0 0038 SETB TF1 003A MOV IE,#8AH 003D SJMP $

Example 003F T0ISR: CPL P1.7 0041 RETI 0042 T1ISR: CLR TR1 0044 MOV TH1,#HIGH(-1000) 0047 MOV TL1,#LOW(-1000) 004A SETB TR1 004C CPL P1.6 004E RETI END

Serial port interrupts Serial port interrupts occur when either TI or RI is set. TI is set when transmission of previous character written to SBUF has finished RI is set when a character has been completely received and is waiting in SBUF to be read The flag that causes a serial port interrupt (TI or RI) is not cleared by hardware when CPU vectors to the interrupt Software has to clear the interrupt flag (unlike timer interrupt which is cleared by hardware)

Serial port interrupts Write a program using interrupts to continually transmit the ASCII code set (excluding control codes) to a terminal attached to the 8051 s serial port at 1200 bit/s ASCII characters to be transmitted are 7 bits and are from 20H to 7EH. ORG 0 0000 LJMP MAIN ORG 0023H 0023 LJMP SPISR ORG 0030H 0030 MAIN: MOV TMOD, #20H 0033 MOV TH1,#-26 0036 SETB TR1 0038 MOV SCON,#42H 003B MOV A,#20H 003D MOV IE,#90H 0040 SJMP $

Serial port interrupts 0042 SPISR: CJNE A,#7FH,SKIP 0045 MOV A,#20H 0047 SKIP: MOV SBUF,A 0049 INC A 004A CLR TI 004C RETI END

External Interrupts External interrupts occur as a result of low-level or negative edge on INT0 or INT1 (P3.2 and P3.3) Flags that actually generate interrupts are bits IE0 and IE1 in TCON Choice of low-level activated interrupt versus negative-edgeactivated interrupts is programmable through IT0 and IT1 bits in TCON If IT1=0 external interrupt 1 is triggered by a detected low at INT1 pin If IT1=1, external interrupt 1 is edge triggered

External Interrupts If the external interrupt is edge-activated, external source must hold request pin high for at least one machine cycle and then hold it low for at least one more cycle IE0 and IE1 are automatically cleared when CPU vectors to interrupts in edge-activated interrupts If external interrupt is level-activated, external source must hold the request active until the requested interrupt is generated External source then must deactivate the request before interrupt service routine is completed Usually an action taken in ISR causes the requesting source to return the interrupting signal to inactive state

Furnace controller Using interrupts, design an 8051 furnace controller that keeps a building at between 19 and 21 degrees. Assume that the furnace ON/OFF solenoid is connected to P1.7 and P1.7=1 turns the furnace ON and P1.7=0 turns it off. Temperature sensors are connected to INT0 and INT1 and provide HOT and COLD signals: HOT=0 if T>21 COLD=0 if T<19

ORG 0 0000 LJMP MAIN Furnace controller 0003 EX0ISR: CLR P1.7 0005 RETI 0013 EX1ISR: SETB P1.7 0015 RETI ORG 30H 0030 MAIN: MOV IE,#85H 0033 SETB IT0 0035 SETB IT1 0037 SETB P1.7 0039 JB P3.2,SKIP 003C CLR P1.7 003E SKIP: SJMP $ END

Intrusion Warning Design an intrusion warning system using interrupts that sounds a 400 Hz tone for 1 second (using a loudspeaker connected to P1.7) whenever a door connected to INT0 makes a high to low transition We use three interrupts: external 0 (door sensor), Timer 1 (400 Hz tone) and Timer 0 (1second timeout)