0% found this document useful (0 votes)
0 views60 pages

06 8051interrupts

The document provides an overview of interrupts in the 8051 microcontroller, detailing their organization, enabling/disabling, and processing. It explains the role of Interrupt Service Routines (ISRs) and the importance of managing interrupt priorities and timings. Additionally, it includes examples of using interrupts for various applications, such as generating square waves and handling serial port communication.

Uploaded by

Baraka Lengay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views60 pages

06 8051interrupts

The document provides an overview of interrupts in the 8051 microcontroller, detailing their organization, enabling/disabling, and processing. It explains the role of Interrupt Service Routines (ISRs) and the importance of managing interrupt priorities and timings. Additionally, it includes examples of using interrupts for various applications, such as generating square waves and handling serial port communication.

Uploaded by

Baraka Lengay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

8051 INTERRUPTS

1
introduction

• interrupt: occurence of a condition (an event)


that causes a temporary suspension of a
program while the condition is serviced by
another program
• interrupt driven program: the interruption is
a response to an event that occurs
asynchronously with the main program
• it is not known when the program will be
interrupted

2
introduction (cont’d)

• Interrupt Service Routine (ISR) (interrupt


handler): a program that deals with an
interrupt
• main programs execute at base-level
(foreground)
• ISRs execute at interrupt-level (background)
• interrupt is asynchronous, not predictable

3
introduction (cont’d)

without interrupts

with interrupts

4
8051 interrupt organization

• a total of 5 interrupt sources


• two external interrupts
• two timer interrupts
• a serial port interrupt
• all interrupts are disabled after a system
reset and are enabled individually by software

5
enabling and disabling interrupts

6
enabling and disabling interrupts (cont’d)

SETB ET1 ; enable Timer 1 interrupt


SETB EA ; set global enable bit

MOV IE, #10001000B

7
enabling and disabling interrupts (cont’d)

SETB ET1 ; enable Timer 1 interrupt


SETB EA ; set global enable bit

MOV IE, #10001000B

initialization

8
enabling and disabling interrupts (cont’d)

SETB ET1 ; enable Timer 1 interrupt


SETB EA ; set global enable bit

MOV IE, #10001000B

modifying on
the fly
initialization

9
interrupt priority
• ISR to be interrupted by another interrupt

10
polling sequence

11
interrupt flag bits

12
processing interrupts

• interrupt accepted by CPU

13
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

14
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

15
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

• current interrupt status saved internally

16
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

• current interrupt status saved internally

• interrupts are blocked at the level of interrupt

17
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

• current interrupt status saved internally

• interrupts are blocked at the level of interrupt

• the PC is loaded with vector address of ISR

18
processing interrupts

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

• current interrupt status saved internally

• interrupts are blocked at the level of interrupt

• the PC is loaded with vector address of ISR

• the ISR executes


19
processing interrupts (cont’d)

• ISR finises with RETI instruction

20
processing interrupts (cont’d)

• ISR finises with RETI instruction

• RETI retrieves old PC value from stack

21
processing interrupts (cont’d)

• ISR finises with RETI instruction

• RETI retrieves old PC value from stack

• RETI restores the old interrupt status

22
interrupt vectors

• interrupt accepted by CPU

• current instruction completes execution

• PC is saved on stack

• current interrupt status saved internally

• interrupts are block at the level of interrupt

• the PC is loaded with vector address of ISR

• the ISR executes


23
interrupt vectors

• the PC is loaded with vector address of ISR

24
interrupt vectors (cont’d)

• when vectoring to an interrupt, the flag that


caused the interrupt is cleared by hardware

25
interrupt vectors (cont’d)

• when vectoring to an interrupt, the flag that


caused the interrupt is cleared by hardware

• RI and TI for serial port interrupts has two


possible sources, so they must be tested and
cleared by software in ISR

26
program design using interrupts

27
program design using interrupts

28
program design using interrupts

29
program design using interrupts

30
small interrupt service routines

• 8 bytes within each


interrupt point

• do not overrun next ISR!

31
large interrupt service routines

• ISRs longer than 8 bytes

32
example: square wave

• use Timer 0 and interrupts for 10kHz square wave

33
example: square wave

• use Timer 0 and interrupts for 10kHz square wave

34
example: square wave

• use Timer 0 and interrupts for 10kHz square wave

35
example: two square waves
• use interrupts for simultaneos 7kHz and 500 Hz
square waves on P1.7 and P1.6

36
example: two square waves
• use interrupts for simultaneos 7kHz and 500 Hz
square waves on P1.7 and P1.6

37
example: two square waves
• use interrupts for simultaneos 7kHz and 500 Hz
square waves on P1.7 and P1.6

38
example: two square waves
• use interrupts for simultaneos 7kHz and 500 Hz
square waves on P1.7 and P1.6

39
serial port interrupts
• RI and TI for serial port interrupts has two
possible sources, so they must be tested and
cleared by software in ISR

• TI occurs when
transmission of character in
SBUF finishes

• RI occurs when a
character is completely
received in SBUF
40
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

41
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

42
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

43
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

44
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

45
example: character output
• continually transmit ASCII code set (excluding control
codes) via serial port using interrupts

46
external interrupts

timer controls

47
example: furnace controller

P3.2

P3.3

48
example: furnace controller (cont’d)

49
example: furnace controller (cont’d)

on

50
example: furnace controller (cont’d)

on

51
example: intrusion warning system

52
example: intrusion warning system (cont’d)

53
example: intrusion warning system (cont’d)

54
interrupt timings

interrupts are
polled on the next
machine cycle

and latched

an interrupt is accepted if:


a) no equal or higher priority interrupt in progress
b) polling cycle is the last machine cycle of instruction
c) current instruction is not RETI or any access to IE or
IP
55
interrupt timings (cont’d)

56
interrupt timings (cont’d)
interrupt latency assume
12 MHz crystal

best case = 3,25 sec

57
interrupt timings (cont’d)
interrupt latency assume
12 MHz crystal

best case = 3,25 sec

worst case = 9,25 sec

58
summary

• interrupt organization and vectors


• processing interrupts
• program design using interrupts

59
references

60

You might also like