Documente Academic
Documente Profesional
Documente Cultură
1. External Interrupt 0
2. Timer Interrupt 0
3. External Interrupt 1
4. Timer Interrupt 1
5. Serial Communication
6
Interrupt Vector Table
Interrupt ISR ROM Pin Flag Clearing
Address (Hex)
Reset 0000 9 Auto
8
Hardware Steps in Executing an Interrupt
10
External Interrupts
--Level-triggered vs. Edge-triggered
Level-triggered:
Default mode upon reset of the 8051
A low-level signal triggers the interrupt.
The low signal must be held low before the execution
of ISR and must be removed before RETI.
Edge-triggered:
A high-to-low signal triggers the interrupt
Need to set TCON.0(IT0)/TCON.2(IT1)
TCON.1(IE0) and TCON.3(IE1) are set when an
falling edge is detected and cleared by RETI.
11
Use TCON Register to Setup
External Interrupts
IE1/IE0: external interrupt 1 & 0 edge flag. Set by CPU
when the external interrupt edge is detected. Cleared by CPU
when the interrupt is processed.
IT1/IT0: external interrupt 1 & 0 type control bit. Set/cleared
by software to specify falling edge/low-level triggered
interrupts.
D7 D0
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
12
Sampling of External Interrupts
Level-triggered external interrupt: To ensure the
activation of the hardware interrupt at the INTn pin,
the duration of the low-level signal should be
around 4 machine cycles, but not more. This is due
to the fact that the level-triggered interrupt is not
latched.
13
Interrupt-in-service Flag: IEx
Used to keep track of edge-triggered external
interrupt only
The falling edge is latched by interrupt-in-
service flag: IE0/IE1 is set by CPU when
external interrupt is detected.
No other external interrupt on the same pin
will be responded when IE0/IE1 is raised.
These flags are cleared when the ISRs are
finished upon execution of instruction RETI.
14
Interrupt Programming
1. In main: set interrupt mode
Ex: Enable external interrupt 0, set it to be edge
triggered:
IT0=1; // set INT0 to be edge triggered
EX0=1; // enable INT0 The interrupt
EA=1; // enable interrupt keyword tells the
2. Write ISR function: compiler function
bit my_flag; chg_mode is an ISR.
The number tell the
G. compiler the
void chg_mode(void) interrupt 0 interrupt source for
{ the ISR.
my_flag=1;
}
3. Notice: No function prototype is needed for
interrupt service routine.
15
Example: Furnace Controller
Using interrupts, design an 8051 furnace controller
that keeps a building at 20C+/-1C.
Solution:
The furnace ON/OFF solenoid is connected to P1.7
such that: P1.7 = 1 for furnace ON, P1.7=0 for
furnace OFF.
Temperature sensor is connected to external interrupt
0 and 1 to provide HOT and COLD signal.
16
Reading Assignment
17