Interrupt 8051
Interrupt 8051
Rom An
gO51 Itemapts theovg (ocali'on
n tenzupt P3:2l1)
)INT O /Externol harelare ilerpt 0)
Auto
Auto(2) Timer o ürterrupt (TFo)
6o13P(13)
Exfernal hardoare inkanpt 1)
Auts(3) TNTT ( OoIB
1. ntmpt (TE)
|Auto () Tier
Auto (5) Reset
(RI ond TI) Oo
2.3
Serial Com Latempt
Progan6)
cleas
it
go51.
Intempt vs Poling RxD
(mohad. Mazidi ):
T3-0
TAD
P- 222 P31
P32
P3
ISR
executing an intenup
Steps in Maziti)
Mohd
5 (P- R2,
that js Suyposed to cause an ihtept
h g051, ohen r any nent ocCs
beComas 1
fist of all, some flag Satus of thetnnybs
this Flag to detmine the pexcding
We nec oceund,
Ohe aups hav
Ohile mbre Hha
evey intempt.Rst tho flag eooms 1 (Set).
Then are flags formpt occus
an inte
hanewa
tho 15R, this fog coill be
ohenever, t prozasso goes to forgetthase
Nos ppoasor thatdor't
Cleared. Jhis remihds the ard not cad ",
yet get sevi
jnde up hasre ocuTIAd
exfernal
hardwar inarut JNTo ond lNT1 tha
For the two, 61.
am called as |ED and
In this chapter we explore the concept of the interrupt and interrupt
interrupts are discussed. In Section 11.2 interrupts belonging to Timersprogramming.
In Section 11.1
the basics of 808
0 and 1are discussed. External hardware inter
rupts are discussed in Section 11.3, while the interrupt related to serial communication is presented in Section 114
In Section 11.5, we cover interrupt priority in the 8051/52. Finally, C programming of 8051 interrupts is covered in
Section 11.6.
the 8051
Six interrupts in
reality, only five interrupts are available to the user in the 8051, but many manufacturers' data sheets state that
.are six interrupts since they include reset. The six interrupts in the 8051 are allocated as follows.
.Ret. When the reset pin is activated,the 8051 jumps to address location 0000. This is the power-up reset discussed
in Chapter 4.
TÚo interrupts are set aside for the timers: one for Timer0 and one for Timer 1. Memory locations 000BH and
01BH in the interrupt vector table belong to Timer Oand Timer 1, respectively.
a.wo interrupts are set aside for hardware external hardwareinterrupts.Pin numbers 12(P3.2)and 13 (P3.3) inport
3are for theexternal hardwareinterrupts INTO and INTI, respectively. These external interrupts arealso refered
to as EXl and EX2. Memory locations 0003H and 0013H intheinterrupt vector table are assigned to INTO and INTI,
respectively.
4. Serial communication has a single interrupt that belongs to both receive and transmit. The interrupt vector table
Jocation 0023H belongs to this interrupt.
Notice in Table 11-1 that a limited number of bytes is set aside forr
For example, a total of 8 bytes
each
from location 0003 to 0000A is set aside for INTO, external hardware interruptO
tion 000BH to 0012His reserved for TFO, Timer0interrupt.vector
If the table:
to fit in the memory space aliocated to it, it is placed in the
serviceotherwise, intelarly, topt
routine for a given
a
is
an LJMP instruction is shor
Bbytes from loca
enough
placed in the
In
vector table to point to the address of the ISR. In that case, the rest of the bytes allocated to that interrupt are unused.
the next three sections we will see many examples of interrupt programming that clarify these concepts.
From Table 11-1, also notice that only three bytes of ROM space are assigned to the reset pin. They are ROM address
locations 0, 1, and12. Address location 3 belongs to external hardware ínterrupt 0. For this reason, in our program we put
in 11-1.
the LJMPas the first instruction and redirect the processor away from the interrupt vector table, as shown Figure
In the next section we will see how this works in the con some examples.
MAIN:
END
Interrupt Vector Table at Power-up
Figure 11-1. Redirecting the 8051 from the
Timers Intupts
TCoN
IE1
TI TO
= EetInteupt occummd
rofo
(Auto Cleared) CAucto cjkand)
and
s That Theans
qoto the SR Sored .
Supendo the
pregam
at bcalion 6003H.
0NT1 is stoed at oDBt
TSR of
Similay/PII
Litsdisabled
PC-
stoek
rtn
oddYess(RA
Po?Ints PCEre natlsethdck RETI
P3
Trts having fxed 5e addrss an calle d vectornd
interupts.
ane vectoed .
eAl intamptr Of &051
Times1.are called Timer overfoo intemyb.
Timey 0 and
orerffo D, it coil Serd as
times iill
w The moment the
inteupt to th proaso.
the tmerofbo intent, tha flgs
wt also naeds a tlag.(fo TF)
are TÈD and
in brder that tha indpt
forget about the pending
procesr does n
thá timer overfloos, thes
TFL = 1 /indicates thot an jnteupt,
cq&qre.
thatlay oill be auto
0o18H
and: Rocaiv Tht-)
intenupt LTransrit Int
SerialCom
ScON
T Ri
trnsm;ted, T; becomes !
is
hen whole dat (8-bi ) is recenved Ri L(Cleand
-Comnoh 1SR
(Ri=1)
Ri aud for
nside ISR, wel check the flag T; and
tee to flas shod still be I.
thal
tor other intert (like TFI, TFO, IE, IED) ts
o
is not Yeqird.
INTO
AL O003H, he SR stored oas writen fr
MTo, So you. co ned that
that was only fr
flag Eo fo be 1 C IE=1) amre.
(P5
0003
(This is t spae for
Oo0 B
Thoseare
nof-
tha
aclual
locochisws
8 byks
RETI
Back t
Main Codi
th RA that t has
the go5l wans,, stack
Storad in the osm
oill pop th RA pe
cHora, it put it back into inotnet.
t stack , the ne<t
back
and come tha
in almostferpt twill di sabls all
I`R,
cohile oingts the
rinterrut g051 -is
terestd in daing y
mans
er Th at ahime..
a t
ne IsR
TSR is oer, notonly it oill Teterm
K ano the Ye -enable7 ale the ntemuph.
buf also
Subroutine) Ps
t sland fron
frsm a Subrouthne It jist simPly
RET: rtun refu'n.
al retum statemen t. Ohen tks
RETI: It is a Speci
ISR is ovr, not snly it coill petunny
ISR) butalso r-enabd the intmpt1.
tis SFR decidog tOhich interup
(Irt.Enaba 2egiste) oill be enabled Gr disablod .
D2 DI
EAXET2 Es ErL B1ETO EXO |= Enable
DDiSabu
J= Enable A| ,
(eachintupt sswce
led
enab Enablu/Disakle ext-jnt 1
vidually seting i-a.) NTLi
írck
is disatledby
or Enab le/dis cbla
Enae dsnbl extenal interyto
the seria
6= Plsableall
bit) port inkmpt CINTO)
interis EnabledisabJe Tiner o
EA fag is Dwrfloa imferpt
usd toslobally
enasles rdisable,
Ena bladisab b Timarl
ihternyp
Overflo is interup t
futfure timer,
(Thuy have plom:d aDverlo inhno
This bit is Enabla/disabls. Timer2. sny)
Tesenvadfor interpt(8o52
2052 or captre next
This btis dont sud processor:
t nce we
case
dicablud
Main PuSHP C -s’i a c k
INT.(EA)
fo the
Ai
ln t 5
PCe1sK
adds.
ohi e g has to
disable le tha iterupt
Cmaka EA =0)
gesal
pof PCE Stack RETI
iterrupts inchose
Youl Can
Iots -enablod ehable d , nDo nd
H into E g.
IPCharag
bled . Tf pngommerloado
heppen ? Explain.
(Interupt Priority ) hhoccumedsimultoneouy,
E0
iterip interup cOould be
too sr mae cohich
r When okcidep
mechanison
sprioriy
rviced f t . owar priaiy
cd fst
be pervithghitoill remain
Higher printy one toill
Cooutd not be lost
-inderptt nuspective lag bita)
in the
pding Dy DsD PL Do
D Do Ds
IP Pxd
xPT2 PS PT1 PX1PT
pricty bit priortty bid for
Resenved prorty bit fr Etemal Trierupt o
for Seri al Ext. Tnt1.
port interupl pioity bd fm
Timer o inknupt
inteupl
prioit
bit fr Timer 2 'intenupt
no} sed for 2051)
rsurvd for go52 only
(P-)
all o's.
Opon pobier- up reset, the IP eg: contei priority
makig the pmority saquonce baszd n the defaut
toble as folloos;
the
Now, to gie a highr prion
correap sning bit in the
interpts) we make the
IP rgi sto high has tha value = 11#,
i-e.
No, Supp
Henca,
EA nust be 1
Tmop
mode-1
as a timu°,
tis cowrting the
nterna elock freq
(P-15
Here:
M6v
A, PI
P2, A coill
cgntsor)
prgmn,
rmain hes fo
Here the rest of span
imeo
ba an Sntemupt;
Owrflows, thesa l
defouutt oi ! teka th program
the intmypt by to location 000BH.
ContofC procegso) to the actua/
Il gump
locatin (ooo BH), 051
bom that hee)
îSR lbcatio CTO ISR
labal ohich will get assignsd t
La
address by th asemblery
CLR TRO
stops, you haato mae runbit o,
when inmer run bit 0.
imr oDht Take the
nexk tie hen gou want to start
SETB TRÝ, it on' t
the times by using Henee e shauld mate ito
becaue it was aready 1. beforhal;
f-16
6)7TOISR: CAL
Lomp MAIN CLR TRD
TLo, #oCH
ORG 000BH mov
2 (nov THO, #OFEH
LJMP TO ISR
D030 H SETB TRO
ORG
PI, #oFAH RETI
MAIN:
mo IE, #82t
nov TmO D,#OIH
THO,#OFEH DSRadass
gotothe o00BH
tt oillJunp
(Mov TLO,#ocH T h aISK
SETB TRO
fon
and to tra
PD.0
HERE: A, PI
mov P2., A
TFO HERE