kashanu.ac.ir Microprocessors 8-1 8051 Interrupts Lec note 8.

Slides:



Advertisements
Similar presentations
Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
Advertisements

Interrupts Professor Yasser Kadah –
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.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
8051 Interrupts.  Contrast edge-triggered with level-triggered interrupts  Program the 8051 for interrupt-based serial communication  Define the interrupt.
Chapter 6 Interrupts (I. Scott Mackenzie).
Embedded Systems UNIT 3. Pin Details of 8051 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: The positive voltage.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
UNIT V INTERFACING MICROCONTROLLER
8051 timer/counter.
8051 timer/counter.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
Chapter 11 Interrupts Programming in Assembly and C
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
Prof. Cherrice TraverEE/CS-152: Microprocessors and Microcontrollers The 8051 Assembly Language.
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
1 Chapter 11 Interrupts Programming. 2 Example 主程式不斷的從 P1 輸入資料,再送到與 LCD 相連的 P2 。但是偶爾 serial port 會收到一些 PC 送來的資料,要送到 P0 ,產生蜂鳴聲,提醒使 用者。 如果主程式是一個無限迴圈,輸入.
Lecture Set 9 MCS-51 Serial Port.
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
Serial Communication Lec note 9.
Interrupt.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Microprocessors 1 MCS-51 Interrupts.
Lecture 8 Interrupts. 2  Introduction  Interrupt organization  Interrupt summary  Enabling and disabling interrupts  Interrupt priority  Interrupt.
8051 Timer/Counter Lec note 7.
8051 Micro controller. Architecture of 8051 Features of 8051.
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.
Microcontrollers Class : 4th Semister E&C and EEE Subject Code: 06ES42
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
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.
Prepared by:- Man Mohan Krishna ECE  Advance technology  Establishment 1999  Location chandigarh  Working area  Products  Key area of training.
Timer Programming in Assembly and C Prepared By:
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Embedded Microcontroller Systems
Chapter 11 INTERRUPTS PROGRAMMING
80C51 Block Diagram ECE Overview.
Assembly Language * * * * * * * 8051 Timer
Microprocessor and Assembly Language
Timer and Interrupts.
Interrupts In 8085 and 8086.
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
ECE,JYOTHI ENGG COLLEGE
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
* * * * * * * 8051 Interrupts Programming.
Interrupt.
Lecture 8 Interrupts.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
Timer Source: under
Interrupt Source: under
Interrupt.
Interrupt Source: under
Timer Source: under
PIC18 Interrupt Programming
Interrupts of 8051 Introduction 8051 Interrupt organization
Presentation transcript:

kashanu.ac.ir Microprocessors Interrupts Lec note 8

kashanu.ac.ir Microprocessors 8-2 Interrupts … mov a, #2 mov b, #16 mul ab mov R0, a mov R1, b mov a, #12 mov b, #20 mul ab add a, R0 mov R0, a mov a, R1 addc a, b mov R1, a end Program Execution interrupt ISR:inc r7 mov a,r7 jnz NEXT cpl P1.6 NEXT:reti return

kashanu.ac.ir Microprocessors 8-3 Interrupts Programming  An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Interrupts vs. Polling  A single microcontroller can serve several devices.  There are two ways to do that:  interrupts  polling.  The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler.

kashanu.ac.ir Microprocessors 8-4 Steps in executing an interrupt  Finish current instruction and saves the PC on stack.  Jumps to a fixed location in memory depend on type of interrupt  Starts to execute the interrupt service routine until RETI (return from interrupt)  Upon executing the RETI the microcontroller returns to the place where it was interrupted. Get pop PC from stack

kashanu.ac.ir Microprocessors 8-5 Interrupt Sources  Original 8051 has 6 sources of interrupts  Reset  Timer 0 overflow  Timer 1 overflow  External Interrupt 0  External Interrupt 1  Serial Port events (buffer full, buffer empty, etc)  Enhanced version has 22 sources  More timers, programmable counter array, ADC, more external interrupts, another serial port (UART)

kashanu.ac.ir Microprocessors 8-6 Interrupt Vectors Each interrupt has a specific place in code memory where program execution (interrupt service routine) begins. External Interrupt 0: 0003h Timer 0 overflow: 000Bh External Interrupt 1:0013h Timer 1 overflow: 001Bh Serial : 0023h Timer 2 overflow(8052+) 002bh Note: that there are only 8 memory locations between vectors.

kashanu.ac.ir Microprocessors 8-7 SJMP main ORG03H ljmpint0sr ORG0BH ljmpt0sr ORG13H ljmpint1sr ORG1BH ljmpt1sr ORG23H ljmpserialsr ORG30H main: … END ISRs and Main Program in 8051

kashanu.ac.ir Microprocessors 8-8 Interrupt Enable (IE) register  All interrupt are disabled after reset  We can enable and disable them bye IE

kashanu.ac.ir Microprocessors 8-9 Enabling and disabling an interrupt  by bit operation  Recommended in the middle of program SETB EA ;Enable All SETB ET0 ;Enable Timer0 ovrf SETB ET1 ;Enable Timer1 ovrf SETB EX0 ;Enable INT0 SETB EX1 ;Enable INT1 SETB ES ;Enable Serial port  by mov instruction  Recommended in the first of program MOV IE, # B SETB IE.7 SETB IE.1 SETB IE.3 SETB IE.0 SETB IE.2 SETB IE.4

kashanu.ac.ir Microprocessors 8-10 Example  A 10khz square wave with 50% duty cycle ORG 0 ;Reset entry poit LJMPMAIN ;Jump above interrupt ORG000BH ;Timer 0 interrupt vector T0ISR:CPLP1.0 ;Toggle port bit RETI ;Return from ISR to Main program ORG 0030H ;Main Program entry point MAIN:MOVTMOD,#02H ;Timer 0, mode 2 MOVTH0,#-50 ;50 us delay SETBTR0 ;Start timer MOVIE,#82H ;Enable timer 0 interrupt SJMP$ ;Do nothing just wait END

kashanu.ac.ir Microprocessors 8-11 Example  Write a program using interrupts to simultaneously create 7 kHz and 500 Hz square waves on P1.7 and P  s 143  s 1ms 2ms P1.7 P

kashanu.ac.ir Microprocessors  s 143  s 1ms 2ms P1.7 P Solution ORG0 LJMPMAIN ORG000BH LJMPT0ISR ORG001BH LJMPT1ISR ORG0030H MAIN:MOVTMOD,#12H MOVTH0,#-71 SETBTR0 SETBTF1 MOVIE,#8AH SJMP$ T0ISR:CPLP1.7 RETI T1ISR:CLRTR1 MOVTH1,#HIGH(-1000) MOVTL1,#LOW(-1000) SETBTR1 CPLP1.6 RETI END

kashanu.ac.ir Microprocessors 8-13 Timer ISR  Notice that  There is no need for a “CLR TFx” instruction in timer ISR  8051 clears the TF internally upon jumping to ISR  Notice that  We must reload timer in mode 1  There is no need on mode 2 (timer auto reload)

kashanu.ac.ir Microprocessors 8-14 External interrupt type control  By low nibble of Timer control register TCON  IE0 (IE1): External interrupt 0(1) edge flag.  set by CPU when external interrupt edge (H-to-L) is detected.  Does not affected by H-to-L while ISR is executed(no int on int)  Cleared by CPU when RETI executed.  does not latch low-level triggered interrupt  IT0 (IT1): interrupt 0 (1) type control bit.  Set/cleared by software  IT=1 edge trigger  IT=0 low-level trigger TF1TR1TF0TR0IE1IT1IE0IT0 Timer 1 Timer0for Interrupt (MSB)(LSB)

kashanu.ac.ir Microprocessors 8-15 External Interrupts IE0 (TCON.3) 0003 INT0 (Pin 3.2) IT0 Edge-triggered Level-triggered (default) IE1 (TCON.3) INT0 (Pin 3.3) IT1 Edge-triggered Level-triggered (default) 0013

kashanu.ac.ir Microprocessors 8-16 Example of external interuupt ORG 0000H LJMP MAIN ; ;interrupt service routine (ISR) ;for hardware external interrupt INT1 ; ORG 0013H SETB P1.1 MOV R0,200 WAIT:DJNZ R0,WAIT CLR P1.1 RETI ; ;main program for initialization ; ORG 30H MAIN:SETB IT1 ;on negative edge of INT1 MOV IE,# B WAIT2:SJMP WAIT2 END

kashanu.ac.ir Microprocessors 8-17 Example of external interuupt

kashanu.ac.ir Microprocessors 8-18 Example of external interuupt Org 0000h Ljmp main Org 0003h x0isr:clr p1.7 Reti Org 0013h x1isr:setb p1.7 Reti Org 0030h Main: mov ie,#85h Setb it0 Setb it1 Setb p1.7 Jb p3.2,skip Clr p1.7 Skip: Sjmp $ end

kashanu.ac.ir Microprocessors 8-19 Interrupt Priorities  What if two interrupt sources interrupt at the same time?  The interrupt with the highest PRIORITY gets serviced first.  All interrupts have a power on default priority order. 1.External interrupt 0 (INT0) 2.Timer interrupt0 (TF0) 3.External interrupt 1 (INT1) 4.Timer interrupt1 (TF1) 5.Serial communication (RI+TI)  Priority can also be set to “high” or “low” by IP reg.

kashanu.ac.ir Microprocessors 8-20 Interrupt Priorities (IP) Register IP.7: reserved IP.6: reserved IP.5: timer 2 interrupt priority bit(8052 only) IP.4: serial port interrupt priority bit IP.3: timer 1 interrupt priority bit IP.2: external interrupt 1 priority bit IP.1: timer 0 interrupt priority bit IP.0: external interrupt 0 priority bit ---PX0PT0PX1PT1PSPT2---

kashanu.ac.ir Microprocessors 8-21 Interrupt Priorities Example  MOV IP, # B or SETB IP.2 gives priority order 1.Int1 2.Int0 3.Timer0 4.Timer1 5.Serial  MOV IP, # B gives priority order 1.Int1 2.Timer1 3.Int0 4.Timer0 5.Serial ---PX0PT0PX1PT1PSPT2---

kashanu.ac.ir Microprocessors 8-22 Interrupt inside an interrupt ---PX0PT0PX1PT1PSPT2---  A high-priority interrupt can interrupt a low-priority interrupy  All interrupt are latched internally  Low-priority interrupt wait until 8051 has finished servicing the high-priority interrupt