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

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

CHAPTER 11 INTERRUPTS PROGRAMMING

INTERRUPTS PROGRAMMING

Interrupts. EE4380 Fall 2001 Class 9. 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 6 Interrupt System

1. Pin diagram of 8051 and ports

8051 Interrupt Organization

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

Interrupt Programming: Interrupts vs. Polling Method:

Microprocessors and Microcontrollers (EE-231)

Chapter 09. Programming in Assembly

8051 I/O and 8051 Interrupts

Chapter 09. Programming in Assembly

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

CHAPTER TIMER PROGRAMMING

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

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

Timers and interrupts

8051 Microcontroller Interrupts

1. LCD (Liquid Crystal Display)interface

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

CPEG300 Embedded System Design. Lecture 8 Timer

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

~: Simple Programs in 8051 assembly language :~

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

ELEG3923 Microprocessor Ch.9 Timer Programming


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

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

AGH University of Science and Technology Cracow Department of Electronics

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

Microcontroller & Interfacing

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


8051 Timers and Serial Port

AGH University of Science and Technology Cracow Department of Electronics

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

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

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

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

8051 Microcontroller

8051 Microcontroller memory Organization and its Applications

8085 Interrupts. Lecturer, CSE, AUST

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

EE6502- MICROPROCESSOR AND MICROCONTROLLER

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

8051 Overview and Instruction Set

8086 Interrupts and Interrupt Responses:

Microcontroller and Embedded Systems:

8051 Microcontrollers

Microcontrollers. Fig. 1 gives a comparison of a microprocessor system and a microcontroller system.

Microprocessors & Interfacing

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

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

Microprocessors & Interfacing

Interrupt Lab using PicoBlaze

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

EKT222 Miroprocessor Systems Lab 5

8051 Serial Communication

AVR Subroutine Basics

How to use the PSoC based 16C450 Replacement

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

Department of Electronics and Instrumentation Engineering Question Bank

8051 Microcontroller. Ali Ziya Alkar 1

ELCT 912: Advanced Embedded Systems

Introduction To MCS-51

80C51 Block Diagram. CSE Overview 1

Real-Time Programming

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

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

MACHINE CONTROL INSTRUCTIONS: 1. EI

INTERRUPTS in microprocessor systems

Question Bank Microprocessor and Microcontroller

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

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

Lab-Report Microprocessors

CS 320. Computer Architecture Core Architecture

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Chapter 7 Subroutines. Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C

12. Interrupts and Programmable Multilevel Interrupt Controller

Microcontroller Intel [Instruction Set]

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

Interrupts Peter Rounce - room 6.18

FACULTY OF ENGINEERING LAB SHEET

Fundamental concept in computation Interrupt execution of a program to handle an event

Interrupt Lab using PicoBlaze

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

Newbie s Guide to AVR Interrupts

Interrupts L33-1. Interrupts

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

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Embedded Controller Programming

Lecture 9. Timer Operations and Programming

MODULE-1. Short Answer Questions

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Microprocessors B (17.384) Spring Lecture Outline

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

Transcription:

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text 1. Interrupt An interrupt is the occurrence of a condition--an event -- that cause a temporary suspension of a program while the event is serviced by another program (Interrupt Service Routine ISR or Interrupt Handler). Figure 1. Interrupt Service Routine Figure.1 shows ISR. In which first part of the figure shows main program is interrupted. The next part shows main program is paused and ISR is providing service to interrupt and when it finishes main program is restored. 1.1 Interrupt Vs Polling Interrupt - is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Serving a device can be done in two ways- 1) Interrupt 2) Polling Interrupt: Here, a device needs service, and the device notifies the microcontroller by sending it an interrupt signal. After receiving an interrupt signal, the microcontroller stops whatever it is doing and serves the device. Program associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler. Polling: In this, the microcontroller continuously monitors the status of the given devices. When the conditions are met, (that is, if the device needs some service) it performs the

service. Next, it moves on to monitor the next device. It continues in this fashion until everyone is serviced. Interrupt is preferred over polling for the following reasons: Polling is not efficient, because it wastes much of the microcontroller s time by checking devices that do not need service. Interrupt can serve many devices; and each device can get the service of microcontroller based on priority. In polling there is no priority, only on round robin basis they can get the attention of the microcontroller. In interrupt, a microcontroller can also ignore a device s request for service, this is not possible in the polling method. 2. Interrupt Service Routine(ISR): Each interrupt has an interrupt service routine (ISR), or interrupt handler. When an interrupt is called, the microcontroller runs the interrupt service routine. Every interrupt has a fixed location in memory that holds the address of the ISR. Figure 2. Interrupt Vector table In the above table, 8051 interrupts are listed. When the reset interrupt is given through 9th pin system is reset. At that time the service starts from 0000 location. The two port pins P3.2 and P3.3 are external hardware interrupts. 2.1 Steps followed when interrupt occurs The group of memory locations that hold the addresses of ISRs is called an interrupt vector table. 1. Microcontroller completes the instruction it is executing and saves the address of the next instruction (PC) on the stack. 2. Saves the current status of the system internally in stack. 3. System starts executing ISR routine, where as the starting address of that ISR routine is referred from interrupt vector table

4. The microcontroller gets the location of the ISR from the interrupt vector table and control is transferred to that location. It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine which is RETI (return from interrupt). 5. After executing the RETI instruction, the microcontroller returns to the place where it was interrupted. 6. First, it gets the program counter (PC) address from the stack by popping the top two bytes of the stack into the PC. 7. Restores the system previous program status. 8. Then it starts to execute from that address. 2.2 Six Interrupts in the 8051 Six interrupts are allocated as follows Reset power-up reset- It is nothing but restarting the system. When the reset is pressed the content of the system is stored and again the memory starts from 0000H. Two interrupts are set aside for the timers: One for timer 0 and one for timer 1 Two interrupts are set aside for hardware external interrupts P3.2 and P3.3 are for the external hardware interrupts INT0 (or EX1), and INT1 (or EX2). For any application, interrupts are needed from outside so that the service can be done based on the input given from outside. Serial communication has a single interrupt that belongs to both receive and transfer Interrupt service is ended by noticing return statement (RETI) in ISR routine. There are two returns in instruction set namely RET and RETI. Though it looks similar, there are some differences in them. 2.2 Differences between RET and RETI: RETI performs an additional task of clearing the interrupt-in-service flag. RET instead of RETI as the last instruction of the interrupt service routine, it blocks any new interrupt on that pin after the first interrupt, since the pin status would indicate that the interrupt is still being serviced. RETI instruction clears TF0, TF1, TCON.1, and TCON.3

3.1 Example code segment for 8051 Interrupts Figure 3. Interrupts of 8051 The first line of code indicates that the program starts from the origin 0000H. Then LJMP MAIN means Long jump to main program. Next the Interrupt Service Routine starts from 30H memory location. 3.2 Enabling and Disabling an Interrupt Upon reset, all interrupts are disabled (masked) None will be responded to by the microcontroller if they are activated. The interrupts must be enabled by software in order for the microcontroller to respond to them There is a register called IE (interrupt enable) that is responsible for enabling (unmasking) and disabling (masking) the interrupts. In IE register, there are 8 bits. Based on those 8 bits, an interrupt can be enabled/disabled. 3.3 Steps in Enabling an interrupt: Bit D7 of the IE register (EA) must be set to high to allow the rest of register to take effect. The value of EA If EA = 1, interrupts are enabled and will be responded to if their corresponding bits in IE are high If EA = 0, no interrupt will be responded to, even if the associated bit in the IE register is high EA=1 enable all interrupts, EA=0 disable all interrupts

Figure 4.Enabling an Interrupt Both the EA pin and the corresponding interrupt pin must be 1 for enabling the particular interrupt. Different methods for enabling interrupts is listed below Method-1 MOV IE,#10011001 ;enable serial, ;timer 1, EX0 Method-2 to perform the same task is SETB IE.7 SETB IE.4 SETB IE.3 SETB IE.0 ;EA=1, global enable ;enable serial interrupt ;enable Timer 1 interrupt ;enable EX0 To disable the interrupts Clear command can be used as shown below CLR IE.3 CLR IE.7 ;mask (disable) timer 1 ;interrupt only ;disable all interrupts 3.4 Timer Interrupt For any application which needs timer for a specific purpose and runs for a particular period of time, timer interrupt can be used. The timer interrupt starts and stops the application automatically. The timer flag (TF) is raised when the timer rolls over. Interrupt handles Timer control flag effectively. In polling, System is held up till TF is raised but in Timer Interrupt, System is not locked.

In Timer Interrupts, If the timer interrupt in the IE register is enabled, whenever the timer rolls over, TF is raised. The microcontroller is interrupted in whatever it is doing, and jumps to the interrupt vector table to service the ISR. In this way, the microcontroller can do other work until it is notified that the timer has rolled over. Figure 5. Timer Interrupt Initial count starts from TH and TL register. When the TH and TL register gets FF occurs, then TF0 is set to 1 and the interrupt is automatically enabled. overflow if the timer interrupt is enabled, whenever TF=1, the microcontroller is interrupted in whatever it is doing, and jumps to the interrupt vector table to service the ISR In this way, the microcontroller can do other things until it is notified that the timer has rolled over. 3.4.1 Timer Interrupt Programming Write a program that continuously gets 8-bit data from P0 and sends it to P1 while simultaneously creating a square wave of 200 ms period on pin P2.1. Use Timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz.

. The first line of code indicates that the program is started from 0000H. LJMP indicates that the program has to go for long jump to reach the main loop. The next line indicates that the ISR Routine starts from 000BH.This ISR routine generates a square. The main program is written at position 0030H. In order to set the timer mode, timer 0 mode 2 is set. P0 is used as the input port. Here the square wave generation is for 200 ms, hence 100 ms is for on state and 100 ms for off state. For generating the delay of 100 ms, 92 is used as the count. when the port P0 reaches 0FFH overflow occurs, it means the delay of 92 count is over and the timer is set again. Once the data is stored in P0, it is moved to accumulator and then again the data is moved to port P1. Hence the data is continuously transferred from the Port P0 to P1. 4. Summary In this lecture different concept of Interrupts and difference between interrupt and polling methods are discussed. The steps for executing the interrupts in 8051 are also discussed. The assembly code for 8051 Timer Interrupt Programming has been explained.

5. References 1. Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. McKinlay, The 8051 Microcontroller and Embedded Systems Using Assembly and C -Second Edition.