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

Similar documents
8051 I/O and 8051 Interrupts

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

CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

CPEG300 Embedded System Design. Lecture 8 Timer

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

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

ELEG3923 Microprocessor Ch.9 Timer Programming

8051 Timers and Serial Port

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


CPEG300 Embedded System Design. Lecture 6 Interrupt System

INTERRUPTS PROGRAMMING

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

Chapter 09. Programming in Assembly

8051 Interrupt Organization

CHAPTER 11 INTERRUPTS PROGRAMMING

Timers and interrupts

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

Interrupt Programming: Interrupts vs. Polling Method:

8051 Microcontroller memory Organization and its Applications

CHAPTER TIMER PROGRAMMING

FACULTY OF ENGINEERING LAB SHEET

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

Embedded Controller Programming

Lecture 9. Timer Operations and Programming

EE6502- MICROPROCESSOR AND MICROCONTROLLER

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

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

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

Microcontroller and Embedded Systems:

8051 Microcontroller

8051 Core Specification

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following.

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

8051 Microcontroller Assembly Programming

Introduction To MCS-51

Chapter 09. Programming in Assembly

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

~: Simple Programs in 8051 assembly language :~

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


Timer programming

8051 Microcontroller Interrupts

Microprocessors and Microcontrollers (EE-231)

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

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

T.Y. Diploma : Sem. V [EJ/EN/ET/EX/DE/IS/IC/IE/EV/MU] Micro-controller

Q 1 a) Attempt any THREE of the following: 12 TMOD.7 TMOD.6 TMOD.5 TMOD.4 TMOD.3 TMOD.2 TMOD.1 TMOD.0 GATE C/T M1 M0 GATE C/T M1 M0

ELEG3923 Microprocessor Ch.4 I/O Ports

8051 Microcontroller. Ali Ziya Alkar 1

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

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

Chapter Family Microcontrollers Instruction Set

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

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

JUMP, LOOP AND CALL INSTRUCTIONS

MICROCONTROLLER BASED WATER LEVEL CONTROL SYSTEM

80C51 Block Diagram. CSE Overview 1

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

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

CS 320. Computer Architecture Core Architecture

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU

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

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

The Final Word on 8051 Microcontroller

MCS -51 Programmer s Guide and Instruction Set

AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

8051 I/O and Class 6 EE4380 Spring 03. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

C51 Family. Architectural Overview of the C51 Family. Summary

How to use the PSoC based 16C450 Replacement

ET2640 Microprocessors

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


Handshake Solutions. HT80C51 User Manual

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

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

VRS570 32K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU VRS580 64K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU

Rev. No. History Issue Date Remark

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

Question Bank Microprocessor and Microcontroller

8XC51RA RB RC Hardware Description

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

Microcontroller and Applications

Principle and Interface Techniques of Microcontroller

II/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION. Microprocessors and Microcontrollers. Answer ONE question from each unit.

Assembly Language programming (3)

Three criteria in Choosing a Microcontroller

Microcontroller Intel [Instruction Set]

Arithmetic and Logic

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.


8051 Microcontroller

WINTER 14 EXAMINATION

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

8XC151SA and 8XC151SB Hardware Description

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Summer 2016 EXAMINATIONS.

Transcription:

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

Polling Vs Interrupts Polling: MCU monitors all served devices continuously, looking for a service request flag Whenever it sees a request, it serves the device and then keeps polling MCU is always busy with polling doing the while any request loop Interrupts If and when a device is ready and needs attention, it informs the MCU MCU drops whatever it was doing and serves the device MCU is always free, when not serving any interrupts 11-Oct-01 2

Interrupt Service Routine MCUs 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 MCU, the ISR-x is executed MCU architecture defines a specific code address for each ISR, which is stored in the, Interrupt vector Table IVT ISRs are basically subroutines, but they end with the RETI, instruction instead of RET When an interrupt occurs, the MCU fetches its ISR code address from the IVT and executes it. 11-Oct-01 3

Interrupt Execution 1. MCU finishes the instruction it is currently executing and stores the PC on the stack 2. MCU saves the current status of all interrupts internally 3. Fetches the ISR address for the interrupt from IVT and jumps to that address 4. Executes the ISR until it reaches the RETI instruction 5. Upon RETI, the MCU pops back the old PC from the stack and continues with whatever it was doiing before the interrupt occurred 11-Oct-01 4

8051 Interrupts Vendors claim 6 hardware interrupts. One of them is the reset. So only 5 real interrupts in the 8051. Clones may differ. Two external interrupts INT0 and INT1, two timer interrupts TF0 and TF1 and one serial port interrupt S0 Interrupts can be individually enabled or disabled. This is done in the IE (Interrupt Enable Register) External interrupts (INT0 and INT1) can be configured to be either level or edge triggered. 11-Oct-01 5

8051 - IVT Each Interrupt has 8 bytes for its ISR. If ISR is too big to fit in 8bytes, then use a ljmp Interrupt ROM Location Pin rom_start: ORG 0 LJMP main_code ORG 13H Reset INT0 0000H 0003H 9 P3.2 int1_vec: main_code: ;. LJMP int1_isr ORG 30H ;bla bla TF0 INT1 TF1 000BH 0013H 001BH P3.3 int1_isr: ;bla bla S0 0023H 11-Oct-01 6

IE Register EA = 0, disable all interrupts EA -- ET2 ES ET1 EX1 ET0 EX0 Other bits if set to 1, enable the corresponding interrupt, if set to 0, disable it. EX0 = enable INT0 ET0 = enable Timer0 EX1 = enable INT1 ET1 = enable Timer1 ES = enable serial port interrupt ET2 = (for 8052 clones only) enable Timer2 Interrupts can be triggered by software by setting the bits in IE setb IE.1 11-Oct-01 7

Simple Example INT1 pin is connected to a switch that is normally high. Whenever it goes low, an LED should be turned on. LED is connected to port pin P1.3 and is normally OFF org 0H ljmp MAIN org 13H ;INT1 ISR INT1_ISR: setb P1.3 ;turn on LED mov r3, #255 BACK: djnz r3, BACK ;keep the led ON for a while clr P1.3 ;turn OFF the LED RETI ;use RETI, ***NOT RET*** org 30H MAIN: mov IE, #1000 0100B ;enable INT1, EA=1, EX1=1 HERE: sjmp HERE ;stay here until interrupted end 11-Oct-01 8

External Interrupts INT0 and INT1 Level triggered : a low level on the pin causes interrupt Default mode Edge triggered : a high-to-low transition on the pin causes interrupt Configuration in TCON register (IT1) TCON.2 = 1 INT1 is edge triggered (IT0) TCON.0 = 1 INT0 is edge triggered IE0 (TCON.1) and IE1 (TCON.3) In edge triggered mode, if interrupt INTx occurs, the MCU sets the IEx bit, which is cleared only aftera RETI is executed Prevents interrupt within interrupt Setup and Hold times for Edge triggered external interrupts One machine cycle each 11-Oct-01 9

Interrupt Priority Default Priority INT0 > TF0 > INT1 > TF1 > S0 The ISR of an interrupt can be interrupted by a higher priority interrupt. The Default Priority can be changed by programming the IP register -- -- PT2 PS PT1 PX1 PT0 PX0 To set higher priority to an interrupt, set its bit in IP to 1 If more than one 1 in IP, the default priority is used for all the interrupts that have 1 in IP 11-Oct-01 10

8051 - Timers Two 16-bit timers T0 and T1 Timer - calculate timing, time etc Event counter Count the occurrence of an event T0 = TH0:TL0 T1 = TH1:TL1 Timer mode is controlled by TMOD register Gate, C/T, M0, M1 Timers are controlled by TCON register (upper 4 bits) TR0, TR1, TF0, TF1 11-Oct-01 11

8051 Timer : TMOD Register Gate1 C/T1 M1 M0 Gate0 C/T0 M1 M0 Gate = 0, software gate of Timer (TRx bit in TCON) Gate = 1, hardware gate of Timer (INTx) pin C/T = 0 Timer operation C/T = 1 Counter operation M1:M0 = 00 Mode 0 (13bit timer) M1:M0 = 01 Mode 1 (16 bit timer) M1:M0 = 10 Mode 2 (8 bit timer, with auto-reload) M1:M0 = 11 Mode 3 (split timer) Clock source for the timer is sys_clk/12 11-Oct-01 12

Timer Mode 1 16 bit timer Operation 1. Load TMOD register to set mode 2. Load TLx and THx with the initial count values 3. Start timer (setb TRx) 4. Keep monitoring TFx flag (jnb TFx, target) 5. Stop timer (clrb TRx) and clear TFx flag 6. Go back to step 2 to load again Time spent Telapsed = (65536 - intial_value)*cycle_time Instead of polling for TFx flag, an ISR could be used 11-Oct-01 13

Timer : Mode 1 Example Generate a 50% duty cycle square wave on P1.5, with Timer0 Timer0 sequence FFF2 TF=0 FFF3 TF=0 FFF4 TF=0.. FFFE TF=0 FFFF TF=1 mov TMOD, #01 ;Timer 0, mode 1 Here: mov TL0, #0F2H mov TH0, #0FFH ;Initial Value = FFF2H cpl P1.5 acall delay sjmp Here Delay: setb TR0 ;start Timer0 Again: jnb TF0, Again ;poll for TF0 (timer overflow) clr TR0 ;stop timer clr TF0 ;clear TF0 flag RET 11-Oct-01 14