8051 Microcontroller Interrupts
8051 Microcontroller Interrupts
MICROCONT-
ROLLER
INTERRUPTS
Submitted by:
Preet Komal
Singh
010714
Ece-E1
8051 Interrupts
As the name implies, an interrupt is some event which
interrupts normal program execution.
As stated earlier, program flow is always sequential, being
altered only by those instructions which expressly cause
program flow to deviate in some way. However, interrupts
give us a mechanism to "put on hold" the normal program
flow, execute a subroutine, and then resume normal
program flow as if we had never left it. This subroutine,
called an interrupt handler, is only executed when a
certain event (interrupt) occurs. The event may be one of
the timers "overflowing," receiving a character via the
serial port, transmitting a character via the serial port, or
one of two "external events." The 8051 may be configured
so that when any of these events occur the main program
is temporarily suspended and control passed to a special
section of code which presumably would execute some
function related to the event that occurred. Once
complete, control would be returned to the original
program. The main program never even knows it was
interrupted.
(LSB)
- IE.6 (Reserved)
O n
N o
t
L
E z
D e
r
L o
o
a r
d e
p
c e
o a
u t
n T
t u
r
D n
e O
c F
r F
e L
m E
e D
n R
t e
t
c u
o r
u n
n t
t o
m
a ai
n
;
;
Serial
Commu
nication
Interru
pts and
Progra
mming
The
Serial port
Interrupt
is
generated
by the
logical OR
of RI and
TI. Neither
of these
flags is
cleared by
hardware
when the
service
routine is
vectored
to. In fact,
the
service
routine
will
normally
have to
determine
whether it
was RI or
TI that
generated
the
interrupt,
and the
bit will
have to be
cleared in
software.
In this
case, the
8051 can
perform
other
tasks in
addition
to serial
communic
ation, i.e.
sending
and
receiving
data from
serial
communic
ation port.
We
know that
transmit
interrupt
(TI) flag is
set (=1)
when the
last bit of
the
framed
data (stop
bit) is
transmitte
d. This
indicates
that the
SBUF
register
is ready
to
transmit
the next
byte. The
receive
interrupt
(RI) flag
is set
(=1)
when the
complete
frame of
data
(with
stop bit)
is
received.
RI
indicates
that the
received
byte
needs to
be picked
up before
it is lost
by new
incoming
serial
data.
All the
above
concepts
are
applied
equally
using
polling or
an
interrupt.
Only
differenc
e is in
serving
the serial
communi
cation
needs. In
polling
method,
the flag
(TI or RI)
is
monitore
d. The
8051
cannot
do
anything
else until
this flag
is set to
high. This
problem
is solved
using
interrupt
method.
When
8051 has
received
a byte or
is ready
to send
the next
byte, the
RI or TI
flag
respectiv
ely is set.
Any other
work can
be
performe
d while
the serial
communi
cation
needs
are
served.
There is a
single
interrupt
set aside
for serial
communi
cation. If
IE
register
(IE.4) is
enabled,
when RI
or TI is
set (= 1),
the 8051
is
interrupt
ed. When
interrupt
ed, the
ISR
written at
0023h is
executed
by 8051.
In ISR,
the TI
and RI
flags
must be
examined
to check
which
one
caused
the
interrupt
and
according
to flag
the
response
is given.
Interru
pt
priority
Each
interrupt
source
can also
be
individuall
y
programm
ed to one
of two
priority
levels by
setting or
clearing a
bit in
Special
Function
Register
IP. A low-
priority
interrupt
can itself
be
interrupte
d by a
high-
priority
interrupt,
but not by
another
low
priority
interrupt.
A high-
priority
interrupt
can’t be
interrupte
d by
another
interrupt
source.
If two
requests
of
different
priority
levels are
received
simultane
ously, the
request of
higher
priority
level is
served. If
requests
of the
same
priority
level are
received
simultane
ously, an
internal
polling
sequence
determine
s which
request is
serviced.
Thus
within
each
priority
level there
is a
second
priority
structure
determine
d by the
polling
sequence,
as follows:
Note that
the
"priority
within
level"
structure
is only
used to
resolve
simultane
ous
requests
of the
same
priority
level.
The IP
register
contains a
number of
unimplem
ented bits.
1P.7 and
IP.6 are
vacant in
the 8052s,
and in the
8051s
these and
IP.5 are
vacant.
User
software
should not
write Is to
these bit
positions,
since they
User
software
should not
write Is to
these bit
positions,
since they
may be
used in
future
MCS-51
products.
Nested
Interru
pts
Consid
er a case,
the 8051
is
executing
an ISR for
servicing
an
interrupt
and
another
interrupt
is
occurred.
In such a
case, if
the new
coming
interrupt
is high
priority
interrupt
then only
it can
interrupt
the
previously
occurred
low-
priority
interrupt.
These are
called
nested
interrupts
". Thus, in
8051 a
low-
priority
interrupt
can be
interrupte
d by high-
priority
interrupt
but not by
another
low-
priority
interrupt.
In 8051,
all the
interrupts
are
latched
and kept
internally.
But the
low-
priority
interrupt
is serviced
only after
finishing
the
servicing
of the
high-
priority
interrupts.
Softwar
e
Triggeri
ng of
Interru
pt
Softwa
re
triggering
of the
interrupts
is possible
in 8051.
This
means the
interrupt
can be
caused by
setting an
interrupt
flag with
an
instruction
. For
example,
if the IE
bit for
timer 1 is
set, an
instruction
'SETB TFV
will
interrupt
the 8051
and 8051
will start
executing
ISR. Thus,
it is not
needed to
wait for
timer 1 to
roll over
to have an
interrupt.
Since we
are using
instruction
to create
an
interrupt,
it is called
software
triggering
.This is
useful for
testing an
ISR by
way of
simulation
.