Вы находитесь на странице: 1из 3

4/10/12

Interrupt Programming
Tuesday, April 10, 2012

mCard MICROPROCESSOR PRESENTATIONS EMBEDDED LINUX NEWS TUTORIALS / ARTICLES CODE BANK QUERY ABOUT US FAQ

SITE SEARCH mCARD

INFOLETTER

because inform ation m atters

Tutorials | Infoletters | New s | Search

INTERRUPT PROGRAMMING IN 8051


INTERRUPT PROGRAMMING CIRCUIT DIAGRAM EXAMPLE CODE Writing Interrupt Interrupt Driven Program for 8051Microcontroller Last Edited: Sep-2009 Interrupt programming, Exceptional handling in 8051, Exceptional handling in processor - Keyw ords

The Microcontroller can serve several devices. The Interrupt is the method to indicate the microcontroller by sending it an interrupt signal. After receiving an interrupt, the microcontroller interrupts what ever it is doing and serves the device. The program associated with the interrupt is called the interrupt service and routine (ISR).

There must be interrupt service routine (ISR), or interrupt Handler. When an interrupt is invoked, the microcontroller runs the interrupt service routine. For every interrupt, there is a fixed location set aside to hold the addresses of ISRs is called

Interrupt Vector Table

Interrupt
INT0 TIMER0 INT1 TIMER1 SERIAL COMMUNICATION INTERRUPT

ROM Location
0003H 000BH 0013H 001BH 0023H

Step in executing an Interrupt: 1) It finish the instruction it is executing and saves the address of the next instruction (PC) on the stack. 2) It also saves the current status of all the interrupt internally. 3) It Jumps to a fixed location in memory called the interrupt vector table that holds the address of the interrupt service routine. 4) The microcontroller gets the address of the ISR from the interrupt vector and jumps to it. It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine. 5) Upon executing the RETI instruction ,the microcontroller returns to the Place where it was interrupt. Interrupt Enable Register (EA) D7 EA D6
-

D5 -

D4 ES

D3 ET1

D2 EX1

D1 ET0

D0 EX0

EA IE.7

Disable all interrupts . If EA= 0 no interrupt is acknowledged If EA=1 , each interrupt source is individually Enable or disable By setting or clearing the enable or disable Enable or disable the serial port interrupt

ES IE.4

ET1 IE.3 Enable or disable Timer 1 overflow interrupt EX1 IE.2 Enable or disable external interrupt 1 ET0 IE.1 Enable or disable Timer 0 overflow interrupt. EX0 IE.0 Enable or disable external interrupt 0.

Enabling and disabling Interrupts Upon reset all interrupts are disable, meaning that known will be responded to by the microcontroller if they are activated. The Interrupt must be enabled by software in order for microcontroller to respond to them there is a register called IE that is responsible for enabling and disabling the interrupts.

www.embeddedcraft.org/interrupt.html

1/3

4/10/12
Steps in Enable an Interrupt

Interrupt Programming

To enable an interrupt an interrupt we take following steps. 1.Bit D7 of the IE Register must to set to high to allow the rest of register to take effect. 2.If EA=1, interrupts are enable and will to responded to if this corresponding bits in IE are High. If EA=1, No Interrupt will be responeded. Programming External Hardware Interrupts The 8051 has two external hardware interrupts PIN 12 (P3.2) and Pin 13 (P3.3) of the 8051, designated as INT0 and INT1 are used as external hardware interrupts. Upon activation of these pins, the 8051 gets interrupts in what ever it is doing and jumps to the vector table to perform the interrupt service routine Type of Interrupt 1)Level-Triggered Interrupt 2)Edge -Triggered Interrupt Level-Triggered Interrupt In this mode, INT0 and INT1 are normally high and if the low level signal is applied to them ,It triggers the Interrupt. Then the microcontroller stops and jumps to the interrupt vector table to service that interrupt .This is all the Level Triggered or Level -Activated interrupt and is the default mode/reset of 8051. Edge -Triggered Interrupt Upon reset 8051 makes INT0 and INT1 low l Level-Triggered Interrupt. To make them Edge -Triggered Interrupt, we must program the bits of the TCON Register. The TCON register holds among other bits and IT0 and IT1 flags bit the determine level- or edge triggered mode. Of the hardware interrupt IT0 and IT1 and bits D0 and D2 of the TCON Register Respectively. In this Section, we have discuss only INT0 and INT1 External Hardware Interrupts. In this example, The Steeper Motor will Rotate when External Interrupt INT1 will Trigger.

Software
This program is w ritten in assemble language

$mod51 ORG 00H LJMP Main ;ISR for hardw are interrupt INT1 to Rotate Steeper Motor MOV A, #88H ; 10001000B LOOP: MOV P1, A ACALL DELAY RR A ; ROTATE BITS SJMP LOOP DELAY: MOV TMOD, #01H MOV TCON, #00H MOV TL1, #0E0H MOV TH0, #0B1H SETB TR0 WAIT: JNB TF0, WAIT RET END ;Main Initilazation ORG 30H

www.embeddedcraft.org/interrupt.html

2/3

4/10/12

Interrupt Programming
MAIN: MOV IE,#1000 0100 ;Enable External INT1 Here: SJMP HERE END

Best view ed in 1024x768 pixels

[Home] [Query] [FAQ] [Aboutus] [Contact us] [Sitemap] [Privacy Policy] [Advertise ]

RSS FEED

Logos and brand names used in this site are belonging to their respected ow ners. We have used them here only for the purpose of information. Enable Active X control from internet options of internet explorer to view all element of this site.

www.embeddedcraft.org/interrupt.html

3/3

Вам также может понравиться