The 8051 Microcontroller and Embedded Systems: Interrupts Programming in Assembly
The 8051 Microcontroller and Embedded Systems: Interrupts Programming in Assembly
Embedded Systems
CHAPTER 11
INTERRUPTS
PROGRAMMING IN
ASSEMBLY
1
OBJECTIVES
2
SECTION 11.1: 8051 INTERRUPTS
3
SECTION 11.1: 8051 INTERRUPTS
4
SECTION 11.1: 8051 INTERRUPTS
5
SECTION 11.1: 8051 INTERRUPTS
Steps in executing an interrupt
1. C finishes the instruction it is executing and saves the
address of the next instruction (PC) on the stack
2. it saves the current status of all the interrupts internally
3. it jumps to a fixed location in memory called the interrupt
vector table
4. the microcontroller gets the address of the ISR from the
interrupt vector table and jumps to it and starts to execute
the ISR until it reaches the last instruction RETI
5. the microcontroller returns to the place where it was
interrupted, it gets the PC address from the stack by
popping the top two bytes of the stack into the PC and then
it starts to execute from that address
6
SECTION 11.1: 8051 INTERRUPTS
7
SECTION 11.1: 8051 INTERRUPTS
Figure 11–1 Redirecting the 8051 from the Interrupt Vector Table at Power-up
8
SECTION 11.1: 8051 INTERRUPTS
9
SECTION 11.1: 8051 INTERRUPTS
10
SECTION 11.1: 8051 INTERRUPTS
12
SECTION 11.2: PROGRAMMING TIMER
INTERRUPTS
13
Example 11-2
Write a program that continuously gets 8-bit data from P0 and sends it to P1
while simultaneously creating a square wave of 200 s period on pin P2.1.
Use Timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz.
14
SECTION 11.3: PROGRAMMING
EXTERNAL HARDWARE INTERRUPTS
Level-triggered interrupt
– INT0 and INT1 pins are normally high
– if low-level signal is applied, it triggers the interrupt
– microcontroller stops whatever it is doing and jumps to
the interrupt vector table to service the interrupt
– the lowlevel signal must be removed before the
execution of the last instruction of the interrupt service
routine, RETI
– otherwise, another interrupt will be generated
16
Example 11-5
Assume that the INT1 pin is connected to a switch that is normally high. Whenever it goes
low, it should turn on an LED. The LED is connected to P1.3 and is normally off. When it
is turned on it should stay on for a fraction of a second. As long as the switch is pressed
low, the LED should stay on.
17
SECTION 11.3: PROGRAMMING
EXTERNAL HARDWARE INTERRUPTS
18
SECTION 11.3: PROGRAMMING
EXTERNAL HARDWARE INTERRUPTS
Edge-triggered interrupts
Figure 11–6
TCON (Timer/Counter)
Register (Bit-addressable)
20
Example 11-6
Assuming that INT1 is connected to a pulse generator. Write a program
in which the falling edge of the pulse will send a high to P 1.3, which is
connected to an LED.
21
SECTION 11.3: PROGRAMMING
EXTERNAL HARDWARE INTERRUPTS
22
SECTION 11.3: PROGRAMMING
EXTERNAL HARDWARE INTERRUPTS
Figure 11–6
TCON (Timer/Counter) Register
(Bit-addressable)
23
SECTION 11.4: PROGRAMMING THE
SERIAL COMMUNICATION INTERRUPT
24
SECTION 11.4: PROGRAMMING THE
SERIAL COMMUNICATION INTERRUPT
25
Example 11-8
Write a program in which the 8051 reads data from P1 and writes it to P2
continuously while giving a copy of it to the serial COM port to be transferred
serially. Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.
26
Example 11-9
Write a program in which the 8051 gets data from P1 and sends it to P2
continuously while incoming data from the serial port is sent to P0.
Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.
27
SECTION 11.4: PROGRAMMING THE
SERIAL COMMUNICATION INTERRUPT
29
SECTION 11.5: INTERRUPT PRIORITY
IN THE 8051/52
32
SECTION 11.5: INTERRUPT PRIORITY
IN THE 8051/52
33
SECTION 11.5: INTERRUPT PRIORITY
IN THE 8051/52
34
Next …
Proteus Exercise 10
– Do as much of the Proteus exercise as you can
and submit via MeL before the end of the lecture.
35