Professional Documents
Culture Documents
Interrupt Requested
p normal Program
Execution
Normal Program
execution
For a microprocessor
having n
interrupts.
XX1, XX2---------XXn
address of ISR in memory.
ISR-n
XXn
ISR-2
XX2
ISR-1
XX1
ES
ET1
EX1
ET0
EX0
X
X
PS
PT1
PX1
PT0
PX0
IP X
- PX0 Priority External Interrupt 0
PT0 Priority Timer 0 overflow
PX1 Priority External Interrupt 1
PT1 Priority Timer 1 overflow
PS - Priority Serial port Interrupt
Example To place Timer 0, external interrupt
1 at high priority and other interrupts at low
priority.
SETB IP.1
IP = 0000 0110 = 06H
or
SETB IP.2
MOV IP, # 06H
Programming
External Interrupts :- In a plant when
there is gas leakage, the gas detector
sends a high to low interrupt on INT0. The
8051 (12MHz clock) starts water spray by
sending control signal (5V) to P0.1 and
sends alarm signal by blinking LED
connected to P2.0(Common Anode)
Main Program :ORG
00
SJMP
030H
ORG
030H
; Enable Interrupt INT0
IE
EA
ES
ET1
EX1
ET0
EX0
0003H
NXINT0
SETB
P0.1
R3, # 100
CLR P2.0
DEL1S
P2.0
R3, REPET
Delay of 1second
END
Timer 0
TMOD =
= 01H
GATE
MOV
TMOD,
MOV
R3,
MOV
R4,
JNB
P0.2,
MOV
TL0,
MOV
TH0,
; Enable Interrupt
SETBIE.7[ MOV
SETBIE.1
C/
T
M1
M0
# 01H
# 229
#2
$
# 00
# 00
IE, # 82H]
CJNE
R4,# 00 , KK2
JNB
P1.2 , KK3
; Station master has activated P1.2
SJMP
KK4
KK2:
MOV
R3, # 229
SJMP
KK1
KK3:
SETB
P1.7
SJMP
KK4
KK1:
MOV
TL0, # 00
MOV
TH0, # 00
CLR
TF0 ; clear flag
SETB
TR0 initiate timer 0
MOV
IE, # 82H; Enable Interrupt
KK4:
RETI
1 clock period
= 10-3 sec = 1 msec.
UP time = 0.5 milli sec.
DN time= 0.5 milli sec.
;
;
MOV
TMOD , # 01H
Load preset value
MOV
TL0, # 0CH
MOV
TH0, # FEH
Clear Timer 0 control interrupt bit TF0
CLR
TF0 [ CLR TCON.5]
Enable Timer 0 interrupt
EA
ET0 EX0
1
0
IE =1 0 0
= 82H
MOV
IE, # 82H
Set priority for Timer 0 interrupt
PTO
IP =0
1
0
PXO
= 02H
;
;
;
TMR0:
CPL
P1.0
Enable Timer 0 interrupt
MOV
IE, #82H
Clear TF0
CLR
TF0[TCON.5]
Reload value
MOV
TL0, # 0CH
MOV
TH0,# FEH
Initiate Timer 0
SETB
TR0[TCON.4]
RETI
T1
R1
Example
Send 10 bytes of data stored at
location 0030H onwards serially in mode1
(8 bits start- stop) at baud rate
4800.8051 has clock frequency of
11.0592MHz
Main Program
ORG
00H
SJMP
030H
ORG
030H
MOV
R2, # 00H for count
; Set mode, =01, SM0, SM1 =01
REN = 1
7
6
5
4
3
2
1
0
SCON =SM0 SM1 SM2 REN TB8 RB8 T1 RI
0
=50H
MOV
SCON, #50H
IE = EA
1
ES
ET1
EX1
ET0
EX0
= 90H
MOV
; Set Priority as High
IP =
IE, # 90H
PS
PT1
Px1
PT0
PX0
=10H
MOV
IP, # 10H
Gat
e
0
C/T
M1
M0
Timer 0
R0, A
ADD
A, #30H
MOV
A, @R0
INC
R2
MOV
SBUF, A
; transmission is complete
[ ACALL DEL 2MS ]
JNB
TI, $
CLR
TI
; Load next byte.
INC
R2
CJNE R2, # 9, Loop1
SJMP $
SJMP
LOOP1
XY1:
NOP
END