Micro Processor
Micro Processor
Micro Processor
Dear student,
You
are
welcome
to
the
M.Sc.Electronics
and
Communications
(Non-semester)
course
through
Distance
mode
have
and
We
request
you
to
go
prepared
by
experts
in
the
study
materials
opportunities
to
you
have
acquire
further
CONTENTS
UNITS
Title
UNIT
MICROPROCESSOR
1:
ARCHITECTURE
UNIT
8085
2:
PERIPHERALS
UNIT
8086
SYSTEM COMPONENTS
UNIT
ARCHITECTURE
UNIT
8051
PROGRAMMING.
8085
INTERRUPTS
AND
ARCHITECTURE
AND
SYSTEM
DESIGN
AND
Science
Instrumentation Centre
Madurai Kamaraj University
Madurai 625021.
Syllabus
M.Sc.(Electronics and
Communications) Non Semester
Paper 4 Microprocessors and
Microcontroller
Architecture:
8085
architecture,
instruction
format,
of
execution
times.
interfacing,
memory
decoding
mapped
I/O,
circuits,
I/O
Data
UNIT II
Interrupt
Interrupt
structure
driven
in
I/O,
8085,
DMA
blocks,
operation,
pins
signals,
interfacing,
and
keyboard,
DAC.
Serial
concepts,
communcation,
switches,
I/O
LED,
Basic
Asychronous
communication
UNIT
III
8086
Microprocessor
8086
family,
Architecture,
8086
Internal
Addressing
modes,
cycles,
mode
minimum/Maximum
operation,
8086
based
decoding,
bus
demultiplexing,
memory
memory interfacing.
buffering
Memory
controller,
UNIT IV
I/O
interfacing,
Interfaing
types,
response,
UART
interfacing,
NS16550D
programming
and
applications.
Advanced microprocessors
Protected mode operation. Virtual
memory,
Mulitasking,
Special
Pentium,
Pro,
Pentium
Pentium
Pentium IV processors.
MMX,
II
and
I/O
ports,
external
UNIT V
8051
Programming
set,
addressing
transfer,
Instruction
modes,
logical,
data
arithmetic
generating
software
and
Serial
configurations,
communication
modes
programs.
Interrupt
Programming
interrupts,
interrupts,
External
serial
Timer
hardware
communication
Text books :
1.
Ramesh
S.
Gaonkar,
Microprocessor
Programming
Architecture,
and
Applications
N. Mathivanan, Microprocessors,
PC
Hardware
and
Interfacing
PHI, 2005.
3.
Muhammad
Gillispie
All
2001.
Janice
The
8051
Mazidi,
microcontroller
systems,
Mazidi,
and
Pearson
embedded
education,
4.
Kenneth
J.
Ayala,
The
8051
Microcontroller Archietecture,
Programming & Applications, II
Ed., Penram International, 1996.
5.
P.S.
Manoharan, P.S.
Microcontroller
design,
based
SClTECH,
Kannan,
systen
Hyderabad,
(2005).
Reference books :
1.
Programming
and
Bary
B.
Brey,
Microprocessors
The
INTEL
8086/8088,
80186/80188,
80486,
80286,
pentium,
and
80386,
Pentium
Kenneth
J.
Ayala,
8086
the
PC,
International, 1995.
Penram
UNIT I
MICROPROCESSOR 8085
ARCHITECTURE
A microprocessor is a multipurpose,
programmable,
clock
driven,
binary
storage
instructions,
device
called
from
memory,
divided
categories:
into
three
main
1.
Microprocessor
initiated
operations,
2.
3.
microprocessor
following functions,
performs
the
1.
2.
3.
4.
microprocessor
8085
has
16
binary
number
called
the
for
transferring
data
from
bi-directional
data
bus
are
synchronizing
used
the
for
carrying
microprocessor
Registers of 8085
The
microprocessor,
various
operations
temporary
to
perform
requires
programmable
some
storage
These
inside
the
registers
are
microprocessor
microprocessor
has
six
8-bit
Apart
from
these
general
purpose
counter,
and
Stack
pointer.
Accumulator
The accumulator is an 8-bit register,
which is also a part of the Arithmetic
and Logic Unit (ALU). Most of the
arithmetic
and
logical
operations
Flag
There are five flip-flops, which are
used to indicate the status of the
result and collectively called as the
Flag register. The flip-flops are set
or reset according to the result. The
accumulator
and
flag
register
D7
D6
D5
D4
AC
D3
D2
D1
D0
CY
program
counter
is
16-bit
is
to
be
fetched
and
etc.,
the
programmer
can
first
stack
will
Out
called
as
memory
i.e.,
last
the
of
instructions
is
called
viz.,
arithmetic,
logical,
data
transfer,
branching,
and
Each instruction
the operation
has
code
two
and
parts,
operand.
data
address.
instructions,
the
In
some
opcode
itself
the
by
operand
second
is
byte
or
The
data
instructions
are
divided
transfer
into
four
between
register
and
memory
ruction
Copies the data from the source
CPU
register
Rs
to
destination
register Rd.
MOV
R, M
MOV
M, R
LDAX
Accumulator
Rp
instruction
Direct:
one
byte
pair
Rp.
Register
pair
STAX
Rp
to
the
memory
MVI
Move
R,
instruction
8-bit
Immediate:
two
byte
OUT
Output
8-bit
instruction
Sends
to
the
port:
two
contents
byte
of
the
IN
Input
8-bit
instruction
Reads
from
from
port:
two
byte
the
input
port
LXI
Load
register
pair
Immediate:
Rp,
16-bit
LDA
16-bit
byte instruction
Copies the data byte from the
memory location specified by the
16-bit
address
to
the
accumulator.
STA
16-bit
byte instruction
to
the
memory
Arithmetic Instructions
The 8085 microprocessor is capable of
performing
various
arithmetic
subtraction,
decrement.
increment,
For
the
and
addition
and
ADD
R
the
contents
of
the
ADI
Add
8-bit
instruction
Adds
Immediate:
the
two
contents
byte
of
the
result
is
stored
in
the
accumulator
SUB
R
the
contents
of
the
SUI
Subtract
Immediate:
8-bit
instruction
two
byte
result
is
stored
in
the
accumulator.
ADD
M
pointed
to
register
pair
Rp
to
the
the
result
is
accumulator
and
by
the
HL
SUB
Subtract
instruction
Subtracts
memory:
the
one
contents
byte
of
the
register
pair
Rp
from
the
accumulator.
INR R
the
contents
register R by one.
of
the
DCR
R
the
contents
of
the
register R by one.
INX
Rp
instruction
Increases
the
contents
of
the
DCX
Rp
instruction
Decreases
the
contents
of
the
INR
Increment
instruction
Increases
memory:
the
one
contents
byte
of
the
DCRM
Decrement
memory:
one
byte
instruction
Decreases
the
contents
of
the
To
write
program
an
to
assembly
add
two
result
in
the
accumulator
is
The
program
with
the
MVI A,
A0H
3E
AO
MVI B,
4FH
06
4F
ADD B
OUT
10H
HLT
80
D3
Adds B to A
stores
the
result
accumulator in port
10
10H
76
Stop
in
Logical instructions
The
microprocessor
8085
can
EX-OR,
NOT
(complement),
ANA
R/M
or
memory
location
ANI
AND
Immediate:
8-bit
instruction
two
byte
ORA
R/M
or
memory
location
ORI
OR
Immediate:
8-bit
instruction
two
byte
XRA
R/M
Exclusive-OR
the
the
contents
of
the
accumulator.
XRI
8-bit
instruction
Logically
immediate
Exclusive-OR
data
byte
the
with
8-bit
the
CMA
Complement
Accumulator:
one
byte instruction
Complement the contents of the
accumulator
and
the
result
is
RLC
Rotate
Left
without
Carry:
one
byte instruction
Rotates each bit of the contents of
the accumulator to the left without
carry.
RAL
Rotate
Accumulator
Left
with
RRC
RAR
Rotate
Accumulator
Right
with
Compares
R/M
register
the
contents
or
memory
of
the
location
CPI
8-bit
the
accumulator
for
less
than,
microprocessor
and
is
ORed
logically
accumulator
ORI.
The
output
with
resultis
port
as
other
the
number
with
the
instruction
moved
to
in the example 1.
3E
45
ORI B,
10H
F6
10
OUT
88H
D3
88
HLT
76
stores
the
result
accumulator in port
88H
the
in
In
this
program,
the
II
data
is
Branch Instructions
The microprocessor is a sequential
machine i.e., it executes instructions
from one location to the next. The
branch
instructions
changes
the
microprocessor.
The
branch
The
branch
JMP
16-bit
instruction
address
The
microprocessor
jumps
JZ
16-bit
e byte instruction
The
microprocessor
jumps
to
JNZ
16-bit
microprocessor
jumps
to
JC
16-bit
ee byte instruction
The
microprocessor
jumps
to
JNC 16-bit
microprocessor
jumps
to
CALL
16-bit
ee byte instruction
The
program
sequence
is
specified
by
the
instruction,
microprocessor
the
stores
the
RET
from
gets
the
back
stack
the
and
instruction
These instructions are software
reset
operations.
instruction
the
On
reading
microprocessor
Programming example1.3
Statement: To write an assembly
language
program
to
add
two
eight
bits,
01H
must
be
data
is
stored
to
the
MEMORY
ADDRESS
8000
LABEL
MNEMONICS
OPCODE
COMMENTS
MVI A, 22H
3E
Loads
8001
8002
22
ADI 99H
8003
8004
C6
accumulator
with I data
Adds the II
data
99
JNC LOOP
D2
Jumps
to
loop if carry
8005
0C
is
set
by
addition
or
next
instruction
8006
80
will
be
executed
Stores
8007
MOV C, A
4F
result
the
in
temporarily
8008
8009
MVI A, 01H
3E
Moves
to A
01H
800A
01
Outputs the
800B
OUT 56
D3
data to port
56H
800C
56
Gets
800D
MOV A, C
79
the
back
result
form C
800E
LOOP:
OUT 55H
D3
Stores
the
result
in
accumulator
in port 88H
800F
55
8010
The
HLT
example
complete
76
program
format
language program.
of
an
Stop
shows
the
assembly
HLT
NOP
microprocessor
does
not
addressing
instruction
set
modes.
has
addressing modes,
the
The
8085
following
1.
2.
data
transfer
is
between
registers.
3.
location's
address
is
specified directly.
4.
address
of
the
memory
location M is represented by HL
register pair.
8QOLNH
WKH
RWKHU
VWDFN
PHPRU\
SRLQWHU
FDQ
maximum
possible
address
to
PUSH
Rp
POP
Rp
least
significant
byte
LSB
is
On
instruction
PUSH
reading
the
B,
the
9FFFH.
Then
SP
is
of
the
program
before
Subroutine
A
subroutine
instructions
is
that
group
are
of
written
function
that
occurs
multiplying
program,
which
occurs
required.
CALL
and
RET
instruction
is
the
microprocessor
program
to
add
two
at
20H
and
21H.
The
by
ADI
and
RRC
subroutine
ended
by
RET
MEMORY
ADDRESS
8100
LABEL
MNEMONICS
OPCODE
COMMENTS
MVI A, 02H
3E
Loads
the
accumulator
with
8101
8102
02
CALL SUB
CD
8103
00
8104
82
the
data
Calls
the
subroutine
After
8105
OUT 20H
D3
returning
form
subroutine,
8106
20
outputs
data to port
20H
8107
MVI A, 03H
8108
3E
Loads the II
data
03
Calls
8109
CALL SUB
CD
the
subroutine
again
810A
00
810B
82
After
810C
OUT 21H
D3
returning,
outputs
data to 21H
810D
21
810E
8200
SUB:
HLT
76
Stop
ADI 30H
C6
Subroutine
30
starts: adds
30H
to
accumulator
Rotates
8202
RRC
0F
accumulator
without
carry
Return
8203
RET
C9
main
program
to
it
is
essential
to
of
communication
in
signals.
these
microprocessor
8085A-2
signals
of
the
8085
Address bus,
2.
Data bus,
3.
4.
5.
6.
Address Bus
The
8085
microprocessor
has
16
at
the
first
part
of
the
Data Bus
The 8085 have 8 data lines (D0 to
D7) and are multiplexed with the low
order address lines. The data bus is a
bi-directional bus and it can move
multiplexed
address
and
data
control
signals
are
used
to
There
are
two
the
chip
peripheral devices.
select
for
the
WR (Write): This signal indicates that
the microprocessor is writing a data
to the memory or an output device.
This is also an active low signal. The
microprocessor places the data on
to
indicate
the
peripheral
IO/M :
This
between
signal
memory
differentiates
and
an
I/O
the
generate
RD and WR
IO
and
signals
memory
to
control
read,
acknowledge, etc.,
Interrupt
ALE
(Address
signal
Latch
indicates
Enable):
This
whether
the
the
signals.
indicates
address
The
signals
positive
that
the
or
going
lines
data
pulse
hold
the
Table 1.1
Status
Machine
cycle
Control
I/
signals
S1
S0
RD = 0
RD = 0
WR = 0
I/O Read
RD = 0
I/O Write
RD = 0
WR = 0
O/
M#
Opcode
Fetch
Memory
Read
Memory
Write
Interrupt
Acknowledge
RD,WR = Z and
Halt
Hold
RD,WR = Z and
Reset
INTA = 1
Power
Supply
And
INTA = 1
Clock
Frequency
Vcc: + 5V power supply
Vss: Ground reference
X1,
X2:
crystal
of
MHz
is
INTR
RST
Restart
7.5
Vectored
receiving
interrupts:
These
are
and
on
interrupts
the
interrupts
these
RST
6.5
location.
RST
5.5
TRAP
viz.,
RESET,
HOLD
and
READY.
peripheral
devices
that
the
On receiving
the
the
HOLD
microprocessor
HLDA
(HOLD
gives
the
activates
Acknowledge)
the control
device. This
Direct
signal
of
the
mode
Memory Access
and
buses
is
to
called
(DMA)
and
slow
responding
device
is
device
activates
the
READY
signal.
Serial Ports
The
microprocessor
has
two
pins,
signals,
which
are
discussed
the
bus
communication
fetch
is
important.
The
of
memory
device.
The
In
the
microprocessor
first
places
T-state
the
the
higher
and
activates
the
control
RD enables
the
memory
and
the
on
the
data
bus,
the
4:
Then
the
microprocessor
Demultiplexing
The
Address
Data Bus
The multiplexed address data bus
(AD 7 to AD 0 ) holds the address for
the first T-state and data bus for the
rest.
So
it
is
necessary
to
de-
the
Address
data
the
read
and
write
IO
RD and WR
signals
goes
low
for
signals.
are
signal
to
MEMR
and
The
OR-ed
generate
memory
RD and WR
the
IO/M
memory
read
with
write
MEMW
required
for
completing
one
The
microprocessor
communication
functions
2.
3.
Request Acknowledge
in
this
machine
cycle.
The
status
signal
IO/M#
remains
high.
The opcode fetch machine cycle is
discussed
already
in
the
bus
machine
Read
machine cycles.
and
cycles
Memory
are
Write
the
opcode
fetch
A,
54H).
It
is
two
byte
2000
LABEL
MNEMONICS
MVI A, 32H
OPCODE
3E
COMMENTS
Loads
the
accumulator
2001
32
with 32H
The
next
location
is
data
bus
and
stores
in
the
accumulator.
the
no
of
T-states
can
be
estimated
as
follows.
For example, the instruction MVI A,
32H
requires
two
machine
cycles
&-/17.3&1'"$*.(
7KHPHPRU\LVDQLQWHJUDOSDUWRIWKH
PLFURFRPSXWHU V\VWHP ,QWHUIDFLQJ D
PHPRU\ WR WKH PLFURSURFHVVRU LV
LPSRUWDQW
EHFDXVH
WKH
IUHTXHQWO\
WR
JHW
WKH
various
instants.
The
memory
The
memory
device
three
The
figure
(b)
shows
an
EPROM
is
because
the
data
in
the
EPROM
will
store
the
data
and
passing
UV
rays.
The
2.
CS
signal
only
to
specific
combination.
Suppose
the
locations.
Whenever
the
4.
outputs
the
data
on
the
is
inputted
into
the
microprocessor
places
the
The IO
/M
in
the
microprocessor
data
disables
bus.
The
the
WR
CE signal. The address lines A11 to
A0 can vary from all zeros to all ones
covering 4K memory.
The figure 1.9a shows a 4 input OR
gate which can be used to generate
and
the CE
signal
will
generated.
be
Another
method
programmed
is
using
decoder
pre-
such
as
device.
microprocessor
is
Suppose
the
reading
the
microprocessor
places
the
chip
decoder
in
decodes
the
and
the
the
internal
memory
address
chip
and
the
by
the
8-bit
address
The
OUT instruction
data
in
output
outputs
the accumulator
to
the
an
address.
The executions of the OUT and IN
instruction are described below.
OUT instruction:
This is a two byte instruction, which
copies the data in the accumulator
and transfer the data to the output
port specified by the 8-bit address
following the opcode. Suppose for an
example,
assume
an
output
port
01H
is
interfaced
microprocessor.
If
the
to
the
output port
2050
LABEL
MNEMONICS
OPCODE
COMMENTS
OUT 01H
D3
Copies
2051
contents
01
the
of
the
accumulator
and
stores
in
the
output port
01H.
Read
(to
read
the
port
Like
every
instruction,
the
first
the
first
microprocessor
machine
places
cycle,
the
the
address
IO
the
MEMR
signal
is
once
again
In
the
third
machine
microprocessor
address
01H
places
on
both
cycle,
the
the
same
higher
and
Thus
the
content
of
the
IN Instruction:
This is a two-byte instruction, which
copies the data from an input device
and stores in the accumulator. The
input device may be a keyboard, a
switch,
or
an
Analog
to
Digital
The
address
of
an
I/O
2065
2066
LABEL
MNEMONICS
OPCODE
COMMENTS
IN 84H
DB
Copies
the
84
data
the
in
input
and
the
port
stores
data
in
the
accumulator.
cycles
are
as
same
as
the
OUT
the
microprocessor.
Since
the
the
lower
order
address
gives low IOADR signal 01H. The
Input Interfacing
The address lines are decoded using
and
are
identified
as
and
from
the
I/O
devices
using
mapped
I/O,
the
memory
location,
the
STA
to
the
I/O
device
instruction
loads
the
connected
specified
by
should
be
while
instructions
the
have
IN
8-bit
and
OUT
immediate
require
machine
cycles
to
the
Opcode
microprocessor
Fetch.
reads
Then
the
the
address
MEMW signal.
UNIT II
8085 INTERRUPTS AND
PERI PHERALS
8085
has
non
maskable
at
any
time
by
setting
or
to
respond
to
the
INTR
interrupt
is
set,
microprocessor
interrupt
connected
devices
to
the
to
the
routines.
Slow
jumps
service
responding
then
the
like
ADC
are
microprocessor
interrupt
interrupt
will
service
have
routine.
its
own
in
the
vectored
locations.
connected
to
the
the
interrupt
lines.
The
by
the
user
by
the
by
using
El
or
Dl
instruction.
E1 (Enable Interrupt): One byte
instruction
The instruction sets the interrupt
enable flip-flop and enables the
interrupt process.
instruction
interrupt
enable
resets
the
flip-flop
thus
line
INTR
each
and
is
enabled
microprocessor
and
finishes
the
the
enable
enabled again.
flip-flop
is
4.
delivers
instruction
so
microprocessor
the
RST
that
the
can
jump
to
the
microprocessor
the
page
microprocessor
0
and
of
the
starts
The
program
to
satisfy
the
This
subroutine
is
Since
the
microprocessor
when
interrupt,
it
the
receives
service
the
routine
8085
have
eight
restart
are
instructions,
one-byte
which
CALL
transfer
the
in
the
page
00H.
The
microprocessor
stores
the
in
the
stack
execution
is
vectored
address.
microprocessor
instruction
at
transferred
the
to
the
When
the
the
RET
reads
the
and
end
of
the
stack.
So
one
of
these
Hex
Call Location
Code
Address
RST 0
C7
0000
RST 1
CF
0008
RST 2
D7
0010
RST 3
DF
0018
RST 4
E7
0020
Mnemonics
RST 5
EF
0028
RST 6
F7
0030
RST 7
FF
0038
The
buffer
puts
EFH,
the
machine
Memory
Write
cycles
will
machine
be
the
cycle
for
data
bus
and
enables
the
places
the
higher
the
address
bus.
These
SP-1
two
in
the
machine
Interrupts
Call Locations
TRAP
0024H
RST 7.5
003CH
RST 6.5
0034H
RST 5.5
002CH
Trap
The TRAP is a non-maskable interrupt
(NMI) that is it cannot be masked
by
the
DI
(Disable
Interrupt)
or
disabled
by
program
interrupts
SIM
can
be
instruction.
masked
SIM:
Set
Interrupt Mask
This is a one-byte instruction and it
uses the contents of the accumulator
for
its
operation.
multipurpose
mask
or
This
instruction,
unmask
the
is
used
to
restart
D7
D6
D5
D4
D3
D2
D1
SOD
SDE
XXX
R7.5
MSE
M7.5
M6.5
D0
M5.5
The
same
serial
instruction
data
is
used
for
Bit
D7
transmission.
faster
data
transfers
are
for
communication:
has
this
two
type
HOLD
pins
of
I/O
(Hold)
and
the
HOLD
signal.
On
signal
the
microprocessor
control
requesting
of
the
through
buses
HOLD
by
signal.
8237
have
four
independent
are
accessed
by
the
with
the
microprocessor;
2.
communicating
with
the
peripherals.
DREQ0 DREQ3 DMA Request:
These are four independent input
signals generated by the peripheral
devices such as floppy disks and hard
the
DREQ
line
of
the
channel.
DACK0
DACK3
Acknowledge:
acknowledge
These
signals
DMA
are
the
generated
by
Write:
These
are
output
to
write
and
read
from
memory.
A 3 A 0 and A 7 A 4 Address: A 3
A 0 are bi-directional address lines.
They are used as inputs to access
control
registers,
when
the
DMA
completes
the
bus
DMA Execution
The process of DMA transfer from the
peripheral to the system memory
under the DMA controller can be
classified under two modes: the slave
mode and the master mode.
The
MPU
selects
the
DMA
the
channel
registers,
DMA
controller
works
in
the
master mode.
1.
2.
controller
enables
the
4.
which
disconnects
the
data
buses.
The
ADSTB
from
the
multiplexed
After
getting
the
complete
6.
The
DMA
uses
the
signals
IOR, IOW, MEMR, MEMW
to
After
the
complete,
asserts
data
the
the
transfer
DMA
EOP#
is
controller
(End
Of
complete.
After
the
data
releases
signal,
and
microprocessor
the
HOLD
then
the
regains
the
8255A
is
widely
used,
while
the
port
can
be
Control Logic
The control section has six lines.
Their functions are as follows.
and
is
normally
connected
to
CS
A1
A0
Selected
Port A
Port B
Port C
Control Register
Control Word
The control register can be used to
program the ports in four different
modes. The Bit D7 of the control
register is used to program the port
C in BSR mode. If D7 is set, the
ports are programmed in I/O mode
and if the bit is reset, the ports are
programmed in BSR mode. In the I/
O mode, the other 7 bits are used
for programming the ports in Mode 0,
1, and 2. The content of the control
register is shown in the figure.
D7
1/O=1
BSR=0
D6
D5
Port
Port
mode
mode
D4
Port
D3
Port
C
(upper)
D2
Mode
Selection
D1
D0
Port
Port
mode
(lower)
D6 D5:
00H = Mode 0
01 H = Mode1
1XH= Mode 2
D4
= 1 Port A is input
= 0 Port A in output
D3
= 0 output
D2:
0 = Mode 0
1 = Mode 1
D1
= 1 Port B input
= 0 output
D0
= 0 output
D7
D6
D5
D4
D3
D2
D1
D0
S/R
000 = Bit
001= Bit
010 = Bit
011= Bit
100 = Bit
101 = Bit
110 = Bit
111 = Bit
D0
= 1: Set
0: Reset
Mode
0:
Simple
Input
or
ports
are
Output
In
this
mode,
the
2.
3.
peripherals
while
transferring
1.
as
either
input
or
output ports.
2.
3.
4.
discuss
the
input
and
output
operation separately.
Port
uses
the
three
by
the
the
peripheral
8255A
that
it
to
has
to
the
STB
signal
by
peripheral
that
the
8255A
has
data.
The
peripheral
will
not
valid
data
and
the
is
reset
when
the
it
reads
the
data
from
the
8255A.
INTE (Interrupt Enable): This is an
internal flip-flop used to enable or
disable the INTR request generation.
and
disabled
INTE B
through
are
PC4
enabled
and
or
PC2
respectively.
Mode
1:
Output
Control
Signals
an ACK signal.
INTR
(Interrupt
Request):
This
This
mode
is
used
in
Procedure
The rows are grounded by sending
00H to the port C. When a key is
pressed, the column connected to
port B is grounded and will be read as
0.
The procedure of finding the key
pressed is given below.
1.
port
will
be
read
for
example 00001110B.
3.
key
by
scanning
each
column.
4.
counter
is
incremented
initialized
for
every
and
column
Then
row
it
and
grounds
checks
the
the
key
is
found
the
loading zero in A
initialing the key code counter
ground all the rows
get the values from port B
masking the higher order 4 bits
check whether port B is all one
If not, execute again
call 10 ms delay (key debounce)
input from port B
mask higher order 4 bits
check any bit of port B gone zero
if not, execute again
give a 10ms delay
load value to ground one row at a time
row counter
rotate A to ground one row
save the value in D
output to port C
input from port B
mask higher 4 bits
column counter
get the D 0 bit to carry
if carry not set, go to code
increment key counter
decrement column counter
JNZ NXTCOLMN
; if any column left, go to next column
MOV A, D
; get back the scan code
DCR B
; decrement the row counter
JNZ NXTROW
; if any row left, go to next row
JMP KEYCHEK
; if no key pressed go to fresh key check
CODE:
MOV A, E
; get the code from E to A
POP D
; get back the values from stack to D, B
POP B
RET
; return to main program
DBONCE:
PUSH B
; store values of B, PSW to stack
PUSH PSW
LXI B, COUNT
; initialize B with delay count for 10ms
LOOP:
DCXB
; decrement B
MOV A, C
; get C value to A
ORAB
; OR A with B, if both B and C zero
JNZ LOOP
; jump if not zero, to loop
POP PSW
; get back values from stack to PSW, B
POP B
RET
; return to main program
connected
to
microprocessor
OUT
signal
from
the
MVI A, 83H
STA8003H
LDA 8001H
STA8002H
LDA 8002H
;
;
;
;
;
ANI OFH
RLC
RLC
RLC
RLC
STA 8002H
HLT
Interfacing an ADC
8-bit,
compatible
ADC.
microprocessor
The
start
of
this
signal
goes
low,
it
LXI
MVI
MOV
MVI
H,
A,
M,
A,
MOV M, A
; store in control port
CALL DELAY ; wait or some time
MVI A, OOH
; reset PC 0 to give the pulse to B/C#
READ:
MOV M, A
DCX H
MOV A, M
RAL
JC READ
LDA 8000H
HLT
Interfacing a DAC
DAC
connected
to
it.
The
The
address
consists
gate
of
and
decoding
an
eight
an
OR
circuit
input NAND
gate.
The
to
generate
triangular
MVI A, 00H
OUT FFH
NOP
NOP
NR A
CPI, OFFH
JNZ UPRAMF
DWNRAMP: OUT FFH
NOP
NOP
DCRA
JNZ DWNRAMP
JMP UPRAMF
increment A
compare whether DAC o/p reached full scale
if no, go to up ramp
output at port FFH
give delay for settling time of DAC
; decrement A
; check DAC o/p zero, if not go to down ramp
; repeat the whole process continuously
2.4 TThe
he
h e 825
8
8254
Counter
The
timer/
time
8254
programmable
counter
delays
and
generates
can
be
interval
accurate
used
for
wave
generator
waveform
includes
and
generator.
three
counters
The
identical
that
complex
can
8254
16-bit
operate
supply.
16-bit
value
is
tri-state,
8-bit,
bi-directional
Control Logic
of
the
counters
and
Control
A1
A0
Selection
Counter
Counter
Counter
Control
Reg.
Control Register
This
register
is
used
to
write
D7
D6
SC1
SC0
D5
D4
RW1
RW0
D2
D2
M2
M1
SC Select Counter
SC1: SCO
Select Counter 0
Select Counter 1
Select Counter 2
D1
M0
D0
BCD
RW Read/Write
RW1: RW0
Read/Write
least
significant
byte
only
M Mode
M2: M1: M0
Mode 0
Mode 1
Mode 2
Mode 3
Mode 4
Mode 5
BCD
Mode
The 8254 can operate in six modes
and the GATE signal is used to enable
or disable the counting.
Mode 0: in this mode, initially the
OUT is low. The count value in the
counter will be decremented every
clock
cycle
and
when
the
count
value
automatically,
is
generating
reloaded
train
of
pulses.
Mode 3: When the count is loaded
the OUT is high, the count value is
decremented by two and when it
reaches
zero
the
OUT
signal
is
Write Operations
The counter is initialized as follows.
1.
2.
3.
To
start
Clock
and
enabled.
the
counter
Gate
signal
appropriate
should
be
Read Operations
The count value in the counter is read
in two methods. One in which the
counter is stopped by disabling the
GATE signal or the CLOCK input. The
count value is read two I/O read
operations for LSB and MSB of the
counter. In the second method, the
counter is read while it was running.
This method is made possible by
writing appropriate control word in
the control register.
8259A
is
programmable
1.
Manage
eight
according
to
interrupts
the
instructions
Vector
any
interrupt
to
any
spaced
locations
at
and
four
must
or
eight
be
in
3.
the
eight
interrupts
in
and
specific
rotation
interrupt
request
mode.
4.
Mask
each
individually.
5.
Read
the
status
of
pending
7.
and
64
interrupts
ISR,
Logic,
and
three
registers
IMR),
priority
Control Logic
This block have two pins: INT and
INTR
the
pin
of
8259
the
detect
MPU.
an
which
microprocessor
has
informs
the
accepted
the
interrupt.
Read/Write Logic
This line have four pins: CS, RD, WR
and A 0 . The A 0 signal is used to
select write or read the command or
Interrupt
Registers
and
Priority Resolver
The interrupt Request Register (IRR)
registers
all
the
eight
interrupt
Interrupt Operation
The 8259 must be initialized before
starting an interrupt operation. The
8259A requires two types of control
words: Initialization Command words
(ICW)
and
Operational
Command
are
used
to
set
priority,
2.
The
8085
acknowledges
by
opcode
for
the
CALL
it
gives
two
INTA
7.
two
lines
to
transfer
data:
enable
the
microprocessor
device.
selects
First
the
the
device
capital
letters
to
are
Synchronous
and
Asynchronous Transmission
Serial communication can be done in
two
ways:
either
Asynchronous
Synchronous
or
modes.
In
receiver
are
synchronized
by
Asynchronous
mode,
the
data
is
The
bit
time
the
delay
will
also
work
on
the
the
data
when
it
has
for
two
and
different
interrupt.
purposes:
The
two
RAR
SIM
; output D 7
SIM
instruction
transmits
the
The
8251a
Programmable
Communication Interface
for
asynchronous
synchronous
serial
and
data
Control
Receiver,
Logic,
Data
Bus
Buffer,
and
Modem
Control.
The
used
to
communication
establish
through
data
modem
register,
The
and
functions
the
of
status
various
Read/
Write
Control
Logic
And Registers
Input Signals
connected
to
decoded
address bus.
RD Read: This is an active low
signal used to read the data from the
data buffer or the status from the
status register.
RESET This is active high signal and
a high in this line resets the chip.
CLK Clock: This is a clock input.
The
clock
is
communication
necessary
with
for
the
microprocessor.
Control Register This is a 16-bit
register
bytes:
having
one
is
two
called
independent
as
mode
same
address
and
are
Transmitter Section
The transmitter section accepts the
parallel data from the MPU and
converts into serial data.
The transmitter
section
two
registers:
and
register
is
contains
used
buffer
for
register
holding
the
parallel
data
data
output
whenever
of
data,
buffer. Whenever
register
it
is
empty
to
the
i.e.,
the
data
buffer transfers
The
the
output
register will
necessary
start
and
and
respectively.
end
of
the
data
has
finished
the
Transmitter
indicates
that
Empty:
the
This
output
RECEIVER SECTION
has
two
registers:
the
serially
and
converts
to
the
parallel data.
UNIT III
8086 ARCHITECTURE AND
SYSTEM COMPONENTS
and
it
can
perform
bus.
Being
a16-bit
20
= 1 MB memory locations.
The
EU
contains
an
instruction
Arithmetic
and
Logic
Unit
registers.
These
BIU
controls
all
the
bus
The Queue
The BIU contains six registers used
as
temporary
storage.
These
while
BIU
fetches
the
and
Extra
segments.
Each
the
offset
address.
Each
will
be
calculated
by
Segment registers
The BIU has four segment registers
viz: Code, Stack, Data, and Extra
segment registers.
Code segment CS: The instructions
are loaded into the Code segment
and the segment is identified by the
register
holds
the
segment
of
the
data
segment
is
data
segment
used
for
some
of
the
general-purpose
registers.
Advantages
of
the
segmentation scheme
The memory of the 8086 is 20-bit
wide
and
with
the
help
of
the
be
registers.
pointed
by
two
16-bit
jump
instructions
uses
the
So
the
program
can
be
changing
the
segment
registers.
2.
3.
4.
5.
Register
mode
Indirect
addressing
6.
7.
8.
9.
MOV
CX,
AX
copies
the
the
BH
register
to
the
DL
register.
the
memory
location
can
be
16-bit
memory
represented
offset
location
as
address
is
part
of
directly
of
the
instruction.
E.g. MOV AX, [1234] copies the
contents of memory location 1234H
to the AX
MOV
contents
AX,
of
[SI]
the
Copies
memory
the
location
this
mode,
the
address
is
MOV
AX,
[SI].
Copies
the
Based
indexed
addressing
mode
The memory location is calculated by
adding an 8-bit or 16-bit, the content
of the base register and the content
of index register.
E.g.
MOV
AX,
d8[SI][DI].
The
the
address
and
the
of
02H
content
is
is
manipulation,
string,
branch
data
transfer
transfer
data
instructions
between
registers,
of
the
data
transfer
Copies
data
from
destination,
destination to source
source
PUSH
source
source
stack
in
the
stack,
pointer
decremented by 2.
the
is
POP
Retrieves
destination
the
the
word
data
destination
XCHG
destination,
source
XLAT
table.
This
instruction
Computes
the
effective
register,
source
LDS
Copies
two
consecutive
register,
words
memory
from
the
memory
in
register
the
specified
and
the
most
LES
Copies
two
register,
words
memory
from
consecutive
memory
and
the ES register.
IN AL, dd
the
address
ddH
and
stores it in AL.
OUT DX, AX
to
the
output
Arithmetic instructions
The
arithmetic
perform
instructions
addition,
multiplication,
and
can
subtraction,
division.
These
flag
register.
The
arithmetic
ADD
destination,
and
source
destination
stored
in
the
registers
destination
register.
ADC
destination,
source
stored
in
register.
the
destination
INC
The
content
destination
destination
of
register
the
is
is
stored
in
the
destination register.
AAA
DAA
SUB
destination,
source
SBB
destination,
is
source
subtracted
from
the
DEC
The
content
of
the
destination
destination
register
decremented
by
one
is
and
AAS
DAS
NEG
Computes
destination
the
stored
the
destination
in
the
2's
and
is
destination
register.
MUL source
multiplication.
multiplication,
of
the
source
For
the
is
IMUL
This
performs
the
signed
multiplication.
AAM
ASCII
adjust
after
multiplication.
instruction
This
perform
the
DIV source
and
stores
the
IDIV
AAD
bit
manipulation
instructions
test,
rotate,
and
shift
functions.
NOT
destination
in
destination
register
AND
destination,
source
OR
destination,
of
source
the
results
in
source
the
and
destination
register.
XOR
destination,
of
source
the
results
in
source
the
and
destination
register.
TEST
destination,
of
source
destination
the
source
and
and
registers
SHL
The
content
of
destination,
destination
count
register
the
is
SAL
The
content
of
the
destination,
destination
count
register
is
SHR
The
destination,
destination
count
shifted
count
content
to
of
the
register
right
times.
is
side
Puts
by
0s
in
MSB
SAR
The
content
destination,
destination
count
shifted
to
of
the
register
right
is
side
by
ROL
The
content
destination,
destination
count
rotated
register
through
count times.
of
left
the
is
by
RCL
The
destination,
destination
count
rotated
count
content
of
register
through
times
the
is
left
by
through
the
carry flag.
ROR
The
content
destination,
destination
count
rotated
of
register
through
right
the
is
by
count times.
RCR
The
destination,
destination
count
rotated
count
content
of
register
through
times
the
is
left
by
through
the
carry flag.
String Instructions
String is a series of ASCII codes in
the memory. The String instructions
perform string operations like copy,
compare, load, and store functions.
MOVS/
MOVSB/
MOVSW
CMPS/
Compares
the
CX
CMPSB/
bytes/words
CMPSW
from
number
DS:SI
of
into
LODS/
LODSB/
location pointed to by SI in DS
LODSW
to AL
STOS/
STOSB/
a location pointed to by SI in
STOSW
DS.
SCAS/
SCASB/
SCASW
various
instructions
locations.
are
The
branch
classified
into
JMP addr
Unconditional
jump
16-bit
displacement
or
segment.offset.
JA/JNBE
JAE/JNB/
JNC
JB/JC/
JNAE
JBE/JNA
JCXZ
Jump if CX is zero.
JE/JZ
JG/JNLE
JGE/JNL
JL/JNGE
JLE/JNG
JNE/JNZ
JNO
JNP/JPO
JNS
JO
Jump if overflow
JP/JPE
JS
Jump if signed
CALL
procedure
specified by procedure.
RET
the
microprocessor
pointer
SP
is
updated.
Then
the
iteration
control
instructions
LOOP
Decrements
CX
register
and
label
LOQPZ
Decrements
CX
register
and
label
IOOPNE/
Decrements
CX
register
and
LOOPNZ
label
JCXZ
label
Interrupt Instructions
The interrupt instructions branch the
execution to some subroutines in the
memory. These instructions provide
software interrupts.
INT
Executes
the
interrupt
service
type
INTO
Executes
the
interrupt
service
IRET
Return
from
interrupt
service
routine.
reset
the
carry,
direction
Set CF
CLC
Clear CF
CMC
Complement CF
STI
Set IF
CLI
Clear IF
and
22&-#,&1
7R
H[HFXWH
SURJUDP
WKH
0DQXDO
FRQYHUVLRQ
RI
GHYHORSHG
WR
FRYHUW
WKH
DVVHPEOHU
GHYHORSHG
E\
0LFURVRIW&RUS
3URJUDPGHYHORSPHQWWRROV
7KH
SURJUDP
LQFOXGH
HGLWRU
GHYHORSPHQW
DVVHPEOHU
ORFDWRUDQGGHEXJJHU
WRROV
OLQNHU
Editor
Editor is used to type the assembly
language
programs
and
the
file
Assembler
The assembler reads the text form
typed
programs
and
coverts
into
Linker
The linker produces the .EXE file with
the help of .OBJ files. The executable
files can be loaded into the memory
and executed.
Debugger
The debugger program enables the
program
to
be
loaded
into
the
Assembler Directives
The
MAS
assembler
instructions,
needs
excluding
some
the
to
the
program.
These
The
simply
example
program
loading
the
Example 1.
DATA
VALUE
DATA
CODE
START:
CODE
SEGMENT
DB 1AH
ENDS
SEGMENT
ASSUME
MOV AX,
MOV DS,
MOV AL,
INT 03H
ENDS
ENDS
START
of
statements
contained
DATA
create
SEGMENT
one
and
DATA
ENDS
and
CODE
segment
CODE
segment
contains
instructions.
DB, DW, DD
The define byte DS, define word
DVV and define double word DD
directives are used to assign names
to variables of 8-bit, 16-bit, and
32-bit
data.
For
example
DB
directive
is
used
to
This
directive
stops
the
The
procedure
EXTERN,
PUBLIC,
and
GLOBAL:
OFFSET
informs
the
the
type
of
the
pointer
Programming example 2:
The program to find the largest in a
string of numbers is given below.
DATA
SEGMENT
LENGTH
DW 0005H
VALUES
DB 00H, 07H, 02H, 03H, 09H
LARGE
DB 1 DUP (0)
DATA ENDS
CODE SEGMENT
ASSUME DS: DATA, CS: CODE
START:
MOV AX, DATA
; transferring the segment address to AX
MOV DS, AX
; transferring from AX to DS
MOV CX, LENGTH
;initializing CX register with length
MOV SI, OFFSET VALUES;loading the starting address of
;string to SI
MOV AL, BYTE PTR [SI]; getting I value to AL
LOOP1:
INC SI
; incrementing the pointer
CMP AL, BYTE PTR [SI]; compares I value with II value
JNC LOOP2
; if 1 value > II value go to LOOP2
MOV AL, BYTE PTR [SI]; or replace the 1 value with II value
LOOP 2:
LOOP LOOP1
; stay in loop until CX = 0
MOV LARGE, AL ; when the loop is over, transfer the ;value in AL in LARGE
INT 03
; break
CODE ENDS
END START
Programming example 3:
The program to find whether two
strings are matching is given below.
be
loaded
to
the
location
DATA
SEGMENT
STRING1
STRING2
LENGTH
RESULT
ENDS
DB
DB
DB
DB
CODE
SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
; stores the segment address in AX and
MOV DS, AX
; then to DS
MOV SI, OFFSET STRING1 ; loading address of the I string
MOV DI, OFFSET STRING2 ; loading address of the II string
MOV CL, LENGTH
REPE CMPSB
JNZ
MOV
INT
LOOP1:
INT
CODE ENDS
END
;
;
;
LOOP1
;
RESULT, 0FFH
;
03H
;
MOV RESULT, 00H;
03H
;
START
Programming example 4:
The program for reversing the bits of
a byte is given below.
DATA
SEGMENT
VAL
DB0A3H
DB 1 DUP (0)
REV
DATA ENDS
CODE SEGMENT
CS: CODE, DS: DATA
ASSUME
START:
MOV AX, DATA
MOV DS, AX
MOV CX, 0008H
SUB BL, BL
MOV AL, VALUE
LOOP1:
ROR AL, 01H
RCL BL,01H
LOOP LOOP1
MOV REV, BL
INT 03H
CODE ENDS
END
START
parameters
registers:
Program
square
of
number
through
to
by
compute
passing
Programming example 5:
DATA
SEGMENT
VALUE DW 0123H
SQUARE
DW 2 DUP (0)
DATA ENDS
STACKSEGMENT STACK
DW
20 DUP (0)
TOP_OF_STACK
LABEL WORD
STACKENDS
CODE SEGMENT
ASSUME
the
microprocessor
subroutine
the
can
the
store
Programming example 6:
CODE SEGMENT
ASSUME
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV SP, OFFSET TOP_OF_STACK
CALL SQUARE
INT 03H
SQUARE
PROC
NEAR
PUSHF
PUSH AX
MOV AX, VALUE
MUL AX
MOV SI, OFFSET SQUARE
MOV WORD PTR [SI], AX
INC SI
INC SI
MOV WORD PTR [SI], DX
POP AX
POPF
RET
SQUARE
ENDP
CODE ENDS
END
START
The
values
memory.
values
In
are
are
passed
the
subroutine,
retrieved
through
from
the
the
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV SP, OFFSET TOP_OF_STACK
MOV SI, OFFSET VALUE
MOV DI, OFFSET SQUARE
CALL SQUARE
INT 03H
SQUARE
PROC
NEAR
PUSHF
PUSH AX
MOV AX, WORD PTR [SI]
MUL AX
MOV WORD PTR [DI], AX
INC DI
NC DI
MOV WORD PTR [DI], DX
POP AX
POPF
RET
SQUARE
ENDP
CODE ENDS
END
START
SEGMENT
ASSUME CS: CODE, DS: DATA, SS: STACK
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV SP, OFFSET TOP_OF_STACK
MOV AX, VALUE
DEC SP
DEC SP
PUSH AX
CALL SQUARE
POP AX
POP DX
MOV SQUARE, AX
MOV SQUARE + 2, DX
INT 03H
SQUARE
PROC
NEAR
PUSHF
PUSH AX
PUSH BP
MOV BP, SP
MOV AX, [BP+8]
MUL AX
MOV WORD PTR [BP+8], AX
MOV WORD PTR [BP+10], DX
POP BP
POP AX
POPF
RET
SQUARE
ENDP
CODE ENDS
END
START
are
retrieved
from
the
subroutine.
microprocessor
8086
has
20
mode.
Among
the
20
multiprocessor
single
systems
processor
microprocessor
is
and
systems,
operated
in
the
in
MN/MX:
Logic
high
selects
the
/S6
A 19 /S3:
Multiplexed
BHE/S7:
Multiplexed
Bus
High
accesses
the
high
RD:
This
line
goes
low,
if
the
The
communicates
responding
microprocessor
with
external
the
devices
slow
using
this signal.
NMI, and INTR: The Non-Maskable
Interrupt and interrupt request. On
receiving the interrupts from these
lines the microprocessor jumps to
specific location. The NMI cannot be
masked and INTR can be masked
using program.
TEST: When this line is high the
microprocessor
reads
the
WAIT
the
clock
required
for
microprocessor operation.
V cc , and GND: The supply +5V and
ground lines.
Minimum mode signals
DT/R::
This
signal
indicates
the
DEN: This signal enables the external
data bus buffers for data activity on
AD15 to AD0.
to
the
INTR
the
microprocessor
will
RQ/GT1,RQ/GT0: In multiprocessor
systems, the other processors sends
their requests for the bus control
through this request lines and the
microprocessor gives granted signals
through the same lines.
QS1
QS0:
The
microprocessor
BUS CYCLE
000
Interrupt acknowledge
001
I/O read
010
I/O write
011
Halt
100
Opcode Fetch
101
Memory Read
110
Memory Write
111
Inactive
Bus cycles
The
microprocessor
instruction
and
fetches
executes
it,
an
the
microprocessor
places
the
bus
and
enables
the
ALE
as
it
is
memory
read
microprocessor
places
the
high
since
the
data
microprocessor
based
system
buffers,
latches,
bus
Clock Generators
The
clock
generator
provides
the
figure
shows
the
clock
generator
and
Address
Enable
control
READY
output.
CLK and PCLK are the clocks used
for microprocessor and peripherals
respectively.
EFI permits the usage of external
frequency inputs.
F/C selects the crystal or external
frequency input.
CSYNC
is
used
to
provide
Bus
buffering
and
de-
multiplexing circuits
The
bus
buffering
and
de-
(74LS245).
These
buffers
are
WR and RD
buffer
using
(74LS244)
decoder (74LS138).
unidirectional
and
an
octal
Bus controller
Inthe maximum mode, the control
signals
such
as
INTA , ALE , DEN, DT/R, M/IO, WR and
HOLD
are
not
available.
bus
S2, S1, S0
.The
8288
command
signals
and
control
signals
(DT/R,DEN,ALE, MCE/PDEN) using the
AEN, CLK, CEN, and IOB inputs from
the
MPU.
The
bus
controller
is
Address Decoding
The
address
decoding
in
PROM Decoder
The
PROM
is
programmable
lines.
to
The
chip
outputs
enable
memory devices.
256 x 4 PROM
of
are
the
PAL Decoder
PAL
is
programmable
array
logic,
outputs.
The
chip
can
be
memory
devices
are
broadly
EPROM interfacing
The ROM devices can be programmed
in the factory while manufacturing
and
it
again.
cannot
be
EPROM
is
Electrically
reprogrammed
a
one-time
Programmable
ROM
generate
HMEMR and
two
LMEMR,
signals,
using
the
SRAM interfacing
The RAM is divided into two types,
static and dynamic RAM (SRAM and
DRAM). The SRAM uses a flip-flop to
store a bit of binary data. The SRAM
is speed as compared to the DRAM
but it is very costly and bulky. The
figure
shows
type
of
SRAM
The
signalnes
are
MEMR
and
connected
MEMW
to
the
the data bus. The signals BHE and AO
are used along with the remainis are
DRAM interfacing
The DRAM uses a tiny capacitor to
store a bit of binary data and needs
to be refreshed periodically. DRAM
interfacing needs a DRAM controller
to read, write, and refresh. Intel
82C08 is a DRAM controller, that can
control two banks of 256K x 16 wide
DRAM chips. It contains a refresh
counter, refresh timer, and address
multiplexer to select the rows and
columns and refresh address. The
DRAM is connected as shown in the
figure.
UNIT IV
8086 - INTERPACING AND
8051 - ARCHITECTURE
which
is
called
as
I/O
the
connection
of
I/O
latch,
R-2R
ladder
network,
an
internal
op-amp.
It
is
CE
terminals. When these terminals go
low, the DAC is selected and the
analog
voltage.
The
range
of
device
selection
signal
at
its
Y0
Y0=A7A6A5A4A3A2A1A0
The decoder output is connected to
to
the
CE
signal.
The
Example program 1:
Assume
the
initialization
segment
registers
has
already.
L00P1:
MOV
OUT
INC
CMP
AL, 00H
0FEH, AL
AL
AL, 0FFH
of
been
the
done
L00P2:
JNZ
OUT
DEC
JNZ
JMP
LOOP1
0FEH, AL
AL
LOOP2
LOOP1
AD574A
is
microprocessor
configuration,
if
the
Stand-alone configuration
The figure shows the connection of
the ADC to the MPU in the stand
alone mode. The CE and 12/8 are
conversion.
remains
in
through
out
conversion
full
the
starts
So
the
operating
process.
when
the
chip
mode
The
12/8
the
conversion
is
over,
the
Y0=A 7A6A5A4A3A 2A 1A0 BHE
Y1=A 7A6A5A4A 3A2A 1A0 IOR
Direct configuration
The figure shows the connection of
the
ADC
connection.
to
the
MPU
The
PAL
in
direct
decoder
Example program 2:
Program to input a converted data
from the ADC is given below.
DATA
DATA
CODE
SEGMENT
ADC
DATA_PORT
STATUS_PORT
DIGI_DATA
ENDS
SEGMENT
EQU 40H
EQU 40H
EQU 42H
DW DUP (0)
ASSUME
used
here
consists
of
two
by
the
magnetic
fields
each
coil
to
protect
the
The
condition
is
given
Y0 = A7 x A6 x A5 x A4 x A3 x A2 x
A1 x AO x IOW
Example program 3:
The program to control the
stepper motor is given below.
L1:
L2:
MOV
MOV
ROL
OUT
CX, 2000
AL, 0CCH
AL, 01H
0F0H, AL
;
;
;
;
CALL DELAY
; wait for some time
DEC CX
; decrement the count value
JNZL1
; if count is not zero repeat from L1
MOV CX, 2000
; re-initialise counter for counter clockwise
ROR AL, 01H
; rotate AL to right
OUT 0F0H, AL
; output AL to motor
CALL DELAY
; wait
DEC CX
; decrement counter
JNZL2
; if counter is not zero repeat L2
INT03H
This
program
rotates
the
stepper
Procedure:
The keyboard has twenty keys from
0 to F and other functional four keys
(store, execute, etc) arranged in five
rows and four columns. The rows are
connected to the port C and the
columns are connected to the port B
of the 8255A. The rows are grounded
by sending 00H to port C. If any
of the keys is pressed, then the
corresponding column of port B will
be read 0.
The steps involved in the program
are given below.
1.
and
whether
checks
any
of
the
keyboard,
the
keys
is
waits
until
key
is
pressed.
2.
time
and
reads
the
sends zero
counter
the
will be
total
counted.
counter
to
no
The
next
row.
initialized
of
value
corresponds
and
loops
is
in
the
to
the
Program
DATA SEGMENT
CNTRLPORT DB 86H
PORTA
PORTB
; port A
; port B
PORTC
DB 84H
; port C
CNTRWRD DB 82H
; control word for port C-O/P port B-I/P
KEY
DB 1 DUP (0); key code (result)
DATA ENDS
STACK SEGMENT STACK
DW
20 DUP (0)
TOP_OF_STACK LABEL WORD
STACK ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV SP, OFFSET TOP_OF_STACK
MOV AL, CNTRLWRD
OUT CNTRLPORT, AL
; configuring 8255A
OUT PORTC, AL
; send to port C
MOV DL, AL
OUT PORTC
IN PORTB
AND AL, #00001111B
MVI CL, 04H
NXTCOLMN:ROR AL, 1
JNC CODE
CODE:
;
;
;
;
;
INC BH
LOOP NXTCOLMN
MOV AL, DL
DEC BL
JNZ NXTROW
JMP KYNTPRES
MOV KEY, BH
INT 03H
HERE:
4.2 INTERRUPTS
The
microprocessor
interrupted
in
the
may
middle
be
of
completes
the
to
hold
the
starting
interrupt
service
procedure
is
vectors.
Each
interrupt
interrupt
service
procedure.
The
Response
of
to
8086
Interrupts
The microprocessor will check if any
interrupt is active at every the end
of
every
instruction.
When
the
following
sequence
of
events
occurs.
1.
2.
any
further
interrupt
through INTR.
3.
4.
5.
procedure
the
vector
is
obtained
table
and
Interrupt
service
procedure
is
executed.
7.
the
procedure,
microprocessor
retrieves
the
the
Predefined interrupts
Software interrupts
Hardware interrupts
Predefined Interrupts
Interrupt types 0 to 31 have been
defined as predefined interrupts and
only the interrupt types 0 to 4 are
used in 8086. The rest are reserved
for
future
applications.
The
first
interrupt
(type
3),
Software Interrupts
The
microprocessor
can
be
type.
This
is
instruction
and
on
reading
instruction,
the
two
byte
this
microprocessor
Hardware interrupts
The microprocessor has two interrupt
lines, Non-Maskable Interrupt (NMI)
and
Interrupt
Request
(INTR).
the
microprocessor
executes
the
INTR
The external devices, which require
immediate
attention
of
the
Example program 5:
as
shown
in
the
inputs
of
the
interrupt
Y0=A 7A 6A 5A 4 A 3A 2A 1A 0 BHE
Y0=A 7A 6A 5A 4 A 3A 2A 1A 0
The program is given below.
; Data segment
ADC
DATA_PORT
EQU
40H
EQU 40H
----------------DIGI_DATA
DW DUP (0)
FLAG
DB 00
; Initialising 8259A
--------------------------------; Saving the interrupt vector in the vector table, interrupt type 08H
MOV AX, 0000H
MOV ES, AX
MOV WORD PTR ES: 0022H
MOV WORD PTR ES: 0020H
; Enable INTR interrupt
STI
; Start of Conversion
OUT ADC, AX
; Do nothing but branch to ISR on interrupt
HERE:
CMP FLAG, 00H
JNZ HERE
CLI
INT 03H
ACQUIRE:
PUSH AX
PUSH CX
IN AX, DATA_PORT
MOV CL, 04H
SHR AX, CL
MOV DIGI_DATA, AX
MOV FLAG, 01H
POP CX
POP AX
IRET
microprocessor,
the
data
is
HOLD
microprocessor
signal
every
receiving
signal.
checks
clock
The
the
cycle
HOLD
and
on
the
HOLD
signal,
the
microprocessor
gives
away
the
sends
signal,
which
on
receiving
the
HLDA
is
complete,
the
DMA
Universal
Asynchronous
independent
receiver
transmitter
divisions
for
and
serial
to
1.5MB.
parallel
to
The
serial
UART
performs
conversion
and
40-pin
DIP
or
44-pin
plastic
chip
the
UART
and
the
microprocessor.
ADS: the positive edge in the line
latches the address lines and chip
select signals. MR: (Master reset)
high in this line resets al registers in
the UART.
WR,
WR
and
These
signals
are
to
transfer
these
data
lines
by
are
DMA
techniques.
XIN, and XOUT: the External crystal
input and External crystal output are
used for providing clock to the chip.
SIN, and SOUT: the Serial input and
Serial output lines used for sending
and receiving serial data.
RTS: When
this
signal
is
low,
it
data
it
sends
low
signal
communication
link,
this
DSR : When the modem is ready to
establish
communication
link,
it
has
been
received
by
the
Internal registers
The
internal
registers
are
listed
below.
Table 4.1
Address
Register
Function
DLAB
A2
A1
A0
(Read)
RBR
Holds
the
byte
received in
(Write)
THR
holds
the byte to be
transmitted
Enables
lER
five
types of UART
interrupts
IIR
(Read)
Indicates
the
pending
interrupts
(Write) Enables
FCR
clears
sets
FIFO,
trigger
Format
LCR
of
asynchronous
communication,
MSB = DLAB
MCR
Controls
the
interface
with
modem
Holds
the
status
LSR
information
concerning
data transfer
MSR
Provides
status
the
of
control
lines
form modem
Holds
SCR
temporary
data, does not
control UART
Holds
DLL
of
LS
divisor
baud
byte
for
rate
generator
Holds MS byte
DLM
of
divisor
baud
for
rate
generator
Example program 6:
Suppose the UART is connected at
the address from 80H to 8EH. The
device has a clock input of 3.072MHz.
EQU 80H
latch-MSB
LCR
LSR
EQU 80H
EQU 80H
THR
RBR
EQU 80H
EQU 80H
MOV AL, 20
OUT LSB_DL, AL
MOV AL, 00
OUT MSB_DL, AL
MOV AL, 00001010B
OUT LCR, AL
; load the control word for the required ;format into LCR
Transmitting data
The line status register is checked
before transmitting a data through
the PC16550D. The data is loaded in
the THR to start transmit the data.
CHECK:
IN AL, LSR
AND AL, 20H
JZ CHECK
MOV AL, AH
OUT THR, AL
INT 03H
IN AL, LSR
AND AL, 01H
JZ CHECK
AND AL, 00001110B
JNZ ERROR
IN AL, RBR
INT03H
ERROR: -------
;
;
;
;
----------INT 03H
advanced
processors
After
that,
80386,
80486,
Pentium-Ill,
Pentium-IV
Advanced
microprocessors
can
Limitations
of
real
mode
operations
The
8088
operate
and
only
in
8086
real
processors
mode.
The
of
memory.
The
1MB
unitasking
operating
80286
follow
real
and
above
and
processors
protected
mode
MB
memory
space
catted
extended memory.
2.
3.
It allows multitasking
Memory
addressing
in
Protected mode
In real mode, a logical address has a
segment address and an offset
an
offset
address.
The
segment
descriptor.
The
the
segment
selector.
It
of
descriptor
tables
in
its
registers,
which
are
not
Multitasking
The
protected
mode
supports
programs
to
execute
Then
the
execution
will
Overview
Of
The
Advanced
Microprocessors
80286
The features of the 80286 processor
are as follows.
1.
2.
3.
4.
80386
The features of the 80386 processor
are as follows.
1.
2.
3.
It supports multitasking
4.
multiple
real
mode
applications work
simultaneously
under
multitasking
system.
80486
The features of the 80486 processor
are as follows.
1.
2.
It
has
parity
checker/
generator.
3.
4.
It
has
reduced
instruction
execution time.
5.
Built-In-Self-Test is present
Pentium processor
The
features
of
the
Pentium
2.
3.
It
allows
two
pipelines
for
supports
applications,
video,
audio,
graphics information.
and
and
address
bus
and
can
address up to 64 GB memory
locations.
microprocessor
purpose
digital
processing
is
computer
unit.
generalcentral
Normally
logic
unit
(ALU),
program
clock
source,
and
parallel
counters,
clock
microcontrollers
I/O,
Serial
circuits,
can
etc.,
be
I/O,
The
called
microcontrollers
read
data,
output
to
control
specific
peripherals.
But
the
microprocessor
needs
all
the
Microcontroller 8051
The 8051 is a 8-bit microcontroller,
having an internal ROM and RAM, I/
ports
with
programmable
pins,
The
architecture
Thirty
two
input/output
lines
CPU Registers
The 8051 contains an accumulator A
and
general
purpose
register
B,
register
and
Program
status
register.
Program
counter
and
pointer
The 8051 contain two 16-bit
registers:
Data
the
program
data
counter
pointer
(PC)
(DPTR).
and
The
The
program
counter
counter
incremented
instruction.
made
up
is
after
The
of
automatically
fetching
DPTR
two
8-bit
register
an
is
registers,
Registers A and B
The
8051
contain
34
general
many
math
and
instructions,
logical
particularly
operations.
The
for
multiplication
and
Flags
and
Program
Status
Word (PSW)
Flags are 1-bit registers provided to
store the results of arithmetic or a
logical operation. The content of the
flags
can
be
altered
by
some
four
indicate
math
the
flags
result
which
of
can
math
(C),
Auxiliary
Carry
(AC),
the
math
flags,
user
CY
AC
FO
RS1
RS0
OV
Internal memory
Every computer must have a memory
to store the instruction and data that
are to be manipulated. Unlike the
microprocessor, the microcontrollers
may
have
some
internal
memory
may
vary
with
the
Internal RAM
The
common
8051
microcontroller
1.
2.
occupies
RAM
byte
3.
the
microcontroller
Special
Function
Registers
The
128-byte
RAM
addresses
Name
Function
Internal RAM
address (HEX)
Accumulator
0E0
Arithmetic
0F0
Addressing
DPH
external
83
memory
Addressing
DPL
external
memory
82
IE
IP
P0
PI
P2
P3
PCON
PSW
interrupt enable
control
0B8
priority
Input/output
port latch
input/output
port latch
input/output
port latch
input/output
port latch
Power control
Program
word
Interrupt
0A8
status
80
90
0A0
0B0
87
0D0
SCON
SSUF
SP
TMOD
TCON
TL0
TH0
TL1
TLO
Serial
port
control
Stack pointer
Timer/counter
mode control
Timer/counter
control
Timer
high
byte
Timer
byte
high
98
99
81
89
88
8A
8C
8B
8D
INTERNAL ROM
the
internal
addresses
memory
exceed
capacity,
the
the
I/O Ports
The microcontroller has four 8-bit
ports,
which
can
be
used
for
Port 0
Port 0 pins may serve as Inputs,
outputs, or when used together, as
a bidirectional low order address and
data bus for external memory. When
a pin is to be used as an input, logic
1 must be written to the port 0 latch,
thus
switching
off
the
output
registers
are
needed
to
Port 1
This
port
functions.
does
So
the
not
have
output
dual
latch
is
Port 2
The port 2 may be used as an input
or output port similar as the port
1. But the port 2 has an alternate
function of providing higher order
address byte in conjunction with the
port 0.
Port 3
The port 3 can be used as input or
output port. Additionally, the port 3
has some special functions like serial
input and output, external interrupts,
timer
inputs
etc.
The
additional
Table 43
Pin
P3.0
Alternate use
RXD
P3.0
TXD
P3.0
INT0
P3.0
INT1
P3.0 T0
P3.0 T1
P3.0
WR
P3.0
RD
SBUF
SBUF
External interrupt 0
TCON.1
External interrupt 1
TCON.3
External
memory
writpulse
SFR
External
reapulse
memory
TMOD
TMOD
--
--
important
pins
and
their
inputs
XTAL1
and
XTAL2.The
activities.
such
cases,
the
EA
pin
is
Upon
reset,
port
is
extremely
important
signals
is
not
sufficient
to
load
memory
instead
of
the
The
address
and
data
lines
are
microcontroller
has
16-bit
data
multiplexed
lines
as
in
D7
D0
are
8085
and
are
latching.
provide
the
The
pin
WRand
16
RD
and
17
signals
TH1).
The
counters
are
control
register
(TCON).
The
bit
definitions
of
the
two
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
from
FFFFH
to
0000H.
Gate
C/
T
M1
MO
Gate
C/
T
M1
M0
Timing
If a counter is programmed to be a
timer, it will count the internal clock
of
the
twelve.
microprocessor
Suppose
divided
if
by
the
Timer modes
The timers can be programmed to
operate in four modes: mode 0,1,2,
3.
timer
mode
1,
the
timer
low
timer
mode
2,
the
timer
is
the
count
value
will
be
Counting
In timing, the clock source is derived
from the system oscillator through
divide by 12 circuit. When the timer/
counter is used in counting mode,
the clock is derived from the external
cycle.
high
to
low
for
atleast
one
machine
takes
oscillator.
24
With
pulses
6
MHz
from
the
oscillator
SCON register
7
SM0
SM1
SM2
REN
TB8
RB8
TI
RI
multiprocessor
TCON register
SMOD
GF1
GF0
PD
IDL
Data Transmission
Transmission
of
the
data
through
Data Reception
Reception of data wilt be enabled by
setting the REN bit to one. When the
UART receives a data, it sets the Rl.
The Rl bit must be reset before the
UNIT V
8051 - SYSTEM DESIGN
AND PROGRAMMING
to
destination,
which
are
modes:
immediate,
to
specify
instruction
the
itself.
microprocessor
data
When
executes
in
the
the
an
immediate
mode
instruction,
it
the
data.
The
immediate
to
indicate
immediate
symbol
data
is
not
that
it
transfer.
is
If
a
the
included,
the
or
register
and
some
MOV
A,
#8-bit
MOV A, Rr
MOV Rr, A
MOV Rr,
#8-bit
MOV
DPTR,
#16-bit
Content of A is stored in Rr
16-bit
DPTR
data
is
stored
in
SFRs
are
representing
The
the
addresses
specified
by
the
address
directly.
should
not
be
MOV
A,
Content
of
the
location
8-bit
add
is transferred to A
MOV
Content of A is transferred to
8-bit
add, A
8-bit address
MOV Rr,
Content
8-bit
add
is transferred to Rr
MOV
Content of Rr is transferred to
8-bit
add, Rr
8-bit address
MOV
8-bit
the
location
8-bit
add,
of
in
the
address
specified
by
8-bit address
MOV
8-bit
add1,
8-bit
8-bit
add2
add2
is
transferred
to
the
data
is
transferred
to
only
and
if
external
data
MOV
@Rp,
#8-bit
MOV
@Rp,
8-bit
add
MOV
@Rp,
A
MOV
8-bit
add,
@Rp
MOV
A,
@Rp
is
stored
in
the
location
Logical Instructions
The 8051 performs various logical
operations like OR, AND, EX-OR, and
NOT and rotate, swap, clear, and
complement.
ANL
A,
#8-bit
ANL
A,
8-bit
add
ANL
A, Rr
with content of Rr
ANL
A,
@Rp
ANL
8-bit
location
add, A
specified
by
8-bit
ANL
AND
8-bit
location
add,
address
#8-bit
value
ORL
A,
#8-bit
ORL
A,
8-bit
add
each
bit
of
content
specified
with
8-bit
by
of
8-bit
immediate
ORL
A, Rr
with content of Rr
ORL
A,
@Rp
ORL
8-bit
location
add, A
specified
by
8-bit
ORL
8-bit
add,
#8-bit
XRL
A,
#8-bit
XRL
A,
8-bit
add
the
content
of
location
XRL
A, Rr
A with content of Rr
XRL
A,
@Rp
XRL
8-bit
of
add, A
location
specified
by
8-bit
XRL
EX-OR
8-bit
location
add,
address
#8-bit
value
CLR A
each
of
specified
with
8-bit
content
by
of
8-bit
immediate
Complement
CPL A
bit
the
content
of
rotate
and
swap
instructions
The
SWAP
A
nibble
positions
of
are
nibble
goes
to
lower
Arithmetic Instructions
The arithmetic instructions perform
operations
like,
increment,
decrement,
addition,
subtraction,
INC A
INC Rr
INC
8-bit
the
add
incremented by one.
INC
DPTR
by one.
INC
@Rp
Rp is incremented by one.
DEC A
8-bit
address
is
DEC Rr
DEC
8-bit
the
add
decremented by one.
DEC
@Rp
Rp is decremented by one.
ADD
A,
#8-bit
ADD
8-bit
add
address
is
A,
Rr
ADD
8-bit
Content
of
is
added
with
A,
Content
of
is
added
with
Content
ADD
A,
@Rp
of
is
added
with
Content
of
and
is
added
8-bit
with
ADDC A,
carry
immediate
#8-bit
ADDC A,
Content
8-bit
add
result is stored in A.
Content
AD
DC
A, Rr
of
of
is
is
added
added
with
with
Content of A is subtracted by
ADDC A,
@Rp
SUBB
A,#8-bit
add
Content of A is subtracted by
carry
and
8-bit
immediate
SUBB A,
Content of A is subtracted by
8-bit
add
result is stored in A.
Content of A is subtracted by
SUBB A,
Rr
Content of A is subtracted by
SUBB A,
@Rp
Content of A is multiplied by
content
MUL AB
order
of
byte
B
of
and
the
the
lower
result
is
Content
of
is
divided
by
DIV AB
DA A
numbers
register;
leave
found
the
in
adjusted
number in A.
jump
directly
and
alter
the
call
instructions
content
of
the
Relative
range,
Short
bytes
backward.
In
short
into
32
occurs
within
pages
the
and
page.
jump
In
long
Unconditional jumps
@A+DPTR
AJMP
sadd
Jump
address
to
short
within
absolute
the
represented by sadd
page
Jump
LJMP Iadd
to
long
absolute
SJMP add
Jump
short
relative
address
Do
NOP
to
nothing.
Just
wait
and
Conditional jumps
JC
radd
carry is set
JNC
radd
carry is reset
JB
radd
b,
JNB b,
radd
JBC b,
radd
CJNE
A,
8-bit
add,
radd
CJNE
A,
#8-bit,
radd
CJNE
Rn,
#8-bit,
not
radd
address.
CJNE
@Rp,
equal,
jump
to
relative
#8-bit,
radd
relative address.
DJNZ
Rn,
is
radd
address
DJNZ
8-bit
location
add,
radd
JZ
radd
relative address
JNZ
radd
not
zero,
jump
specified
to
by
relative
8-bit
ACALL
sadd
LCALL
ladd
RET
5.2 Interrupts
Interrupts
may
be
generated
by
an
subroutine
interrupt-handling
located
predetermined
absolute
at
address,
Tl).
The
other
two
are
from
have
interrupt
three
enable
registers:
(IE)
an
register,
control
controlling
(TCON)
the
register
operations
for
of
the
interrupt.
The bit-definition of Interrupt Enable
(IE) register is given below
EA
ET2
ES
ET1
EX1
ET0
EX0
The
bit
definition
for
Interrupt
PT2
PS
PT1
PX1
PT0
PX0
Interrupt types
Timer interrupt: The timer interrupt
occurs as a result of timer overflow
(from all ones to all zeros). The
processor
is
directed
to
the
vector location.
Serial port interrupt: The serial
interrupt occurs when a byte has
been received or transmitted. When
a byte has been received, the Rl flag
will be set and when a byte has been
successfully transmitted, the Tl flag
will be set. But both these events
cause
single
interrupt
and
the
interrupt:
external
interrupts
different
interrupts.
The
two
causes
two
The
interrupts
the
CPU
registers
to
be
counter
is
not
stored
anywhere.
Interrupt priority
The register IP gives the high or low
priority
to
interrupts
the
occur
interrupts.
at
same
If
instant,
IE0
2.
TF0
3.
1E1
4.
TF1
5.
Serial RI or TI
two
Interrupt destinations
If an interrupt occurs the program
sequence will be transferred to a
vector location. The interrupt types
and their jump locations are given
below.
Table 5.1
Interrupt
Address
type
(HEX)
IE0
0003
TF0
000B
SIE1
0013
TF1
001B
SERIAL
0023
128
bytes
of
RAM.
If
the
by
interfacing
external
typical
expansion
of
and
the
following
components.
8031
(ROM
microcontroller
which
Jess
is
equivalent to 8051)
general
programmable
purpose
I/O
lines
or
(port
External
Memory
and
Memory-Decoding circuit
External memory is interfaced to the
microcontroller via the ports 0 and 2.
The port 0 is an open drain output,
and
the
ALE
signal
is
CE
signal
to
the
EPROM
is
supplied
through
the
OR
gate
Table 5.2
Memory Size
EPROM
RAM
8K
None
None
16K
J1
NA
32K
J1, J2
J4, J5
64K
J1, J2, J3
NA
stay
low
for
atleast
two
Expanded I/O
The ports 1 and 3 are used as I/
O ports. Two pins of port 3 (P3.6
and P3.7) are used for supplying
like
8255
Programmable
programs,
discussed here.
which
will
be
the
oscillator
is
working,
the
ROM Test
The ROM must be tested to ensure
that the programs entered into them
will
be
executed
by
the
If
there
interfacing
the
is
any
trouble
microcontroller
in
will
Address
START:
Mnemonics
Comment
.ORG
start
OOOOH
program
LJMP ADD2
; test A1 and A0
.ORG
0004H
ADD2:
LJMP ADD3
; test A2
.ORG
0008H
ADD3:
LJMP ADD4
.ORG
; test A3
001
OH
ADD4:
LJMP ADD5
; test A4
.ORG
0020H
ADD5:
LJMP ADD6
.ORG
0040H
; test A5
of
the
ADD6:
LJMP ADD7
; test A6
.ORG
0080H
ADD7:
LJMP ADD8
; test A7
.ORG
0100H
ADD8:
LJMP ADD9
; test A8
.ORG
0200H
ADD9:
LJMP
; test A9
ADD10
.ORG
0400H
ADD10:
LJMP
11
.ORG
0800H
ADD
; test A10
ADD11:
LJMP
ADD
; test A11
ADD
; test A12
ADD
;test A13
12
.ORG
1000H
ADD12:
LJMP
13
.ORG
2000H
ADD13:
LJMP
14
.ORG
4000H
ADD14:
LJMP
; test A14
ADD15
.ORG
8000H
ADD15:
LJMP
ADD15
.END
; test A15
delays
can
be
done
using
timer
can
be
used
either
in
software
method,
the
timer
is
time
delay
is
generated
by
having
Cnumber
of
DELAY:
LOOP:
method
uses
the
timer
to
is
continuously
polled
and
WAIT:
OVER:
SJMP OVER
END
method
generate
discussed
the
uses
the
delay.
later
in
timers
This
the
will
to
be
interrupt
programming.
Mnemonics
Comments
.ORG
Starting
1030H
table
address
of
lookup
.DB 00H
.DB 01H
.DB 02H
.DB 03H
.DB 04H
.DB 05H
.DB 06H
.DB 07H
.DB 08H
.DB 09H
the
location
specified
by
the
PC as a base address
Whenever the lookup table is very
nearer to the program within 256
bytes and small, the PC can be used
as a base address for the lookup
table. The offset can be supplied by
the
Accumulator
program
A.
illustrates
the
following
finding
the
ADD A, #02H
; compensate 2 bytes for last
MOVC A, instruction
@A+PC ; copy from lookup table
OVER:
SJMP OVER
.DB
OOH
01H
04H
09H
.DB
.DB
.DB
; 00^2 = 00
;
01^2
=
01 ; 02^2 =
04 ; 03^2 =
09
sjmp
.DB 10H
.DB 19H
.DB 24H
.DB 31H
.DB 40H
.DB 51H
.DB 64H
.DB 79H
.DB 90H
.DB 0A9H
.DB 0C4H
.DB 0E1H
.END
;
;
;
;
;
;
;
;
;
;
;
;
04^2
05^2
06^2
07^2
08^2
09^2
0A^2
0B^2
0C^2
0D^2
0E^2
0F^2
=
=
=
=
=
=
=
=
=
=
=
=
16
25
36
49
64
81
100
121
144
169
196
255
address.
illustrates
such
The
method
program
is
listed
.ORG 000H
LJMP MAIN
.ORG 0030H
MAIN: MOV A, #21H
; load value to A
MOV R1, A
MOVC A, @A+DPTR
MOV R0, A
MOV A,R1
; load value to A
MOV A, @A+DPTR
MOV R1, A
.DB 04H
...
...
.DB OFEH
.END
Serial communication
The
8051
contain
serial
transmission/reception
data
circuitry,
Receiver
mode.
mode,
and
In
the
the
data
is
baud
required
for
data
transmitting
character,
the
previous
transmission
is
The
crystal
frequency
times.
The
program
is
listed
below.
; The clock frequency is 11.0592 MHz and the baud rate is 2400
.EQU BAUDNUM, 0F4H
.EQU COUNT, 0AH
.ORG 0000H
ANL PCON, #7FH
; set SMOD bit 0 for baud x 32
ANL TMOD, #30H
;
ORLTMOD, #20H
; set timer mode 2
MOV TH1, #BAUDNUM
; load the baud number to timer
SETB TR1
; start timer 1
TRNS:
XTIM:
DELAY:
LOOP:
Serial
;
; return to the main program
Reception
through
Polling
The serial reception is controlled by
polling the specified data bit in the
So
the
program
must
The
program
monitors
the
; The clock frequency is 11.0592 MHz and the baud rate is 2400
.EQU BAUDNUM, 0F4H
.ORG 0000H
ANL PCON, #7FH
; set SMOD bit 0 for baud x 32
ANL TMOD, #30H
HERE:
RECEIVE:
XMIT:
HERE:
interrupt
system
follows
the
If
of
any
the interrupts is
will
be
discarded. So
programmer
interrupt
the
enable
bits
in
the
CPU
finishes
the
current
of
interrupts
the
routine,
are
all
the
disabled
to
3.
4.
returns
to
the
main
program.
An interrupt service program is
also called as real-time program
because it does not wait for any
software polling action and the
transfer of the program is very
quick.
Subroutines
that
are
registers
to
control
the
The
Interrupt
Enable
(IE)
register
The
IE
register
controls
alt
the
interrupts
are
individually
The
Interrupt
Priority
(IP)
control register
The IP SFR may be used by the
programmer to determine which
The
interrupt
priority
the
8051
itself
preference as follows
1.
2.
Timer 0 Overflow
3.
4.
Timer 1 Overflow
5.
Serial Port
give
Interrupt Handler
The interrupts have vector addresses
in the page starting from 0003H. The
interrupts
and
addresses
of
the
Interrupt source
Vector address
External interrupt 0
0003H
Timer 0 Overflow
0000BH
External interrupt 1
0013H
Timer 1 Overflow
001 BH
Serial Port
0023H
should
be
written
at
the
interrupt
microprocessor
address
and
is
generated,
goes
the
the
vector
executes
the
vector
address,
the
machine
generate
250
microseconds
at
timer 0
to timer high byte
to timer low byte
timer
go to loop
.ORG 00D0H
ISRT;ORL IE, #7FH ; disable all interrupts
DEC R7
; decrement interrupt counter
ORLIE,#80H
; enable all other interrupt
RETI
; return from interrupt
.END
Serial
Reception
and
the
polling
and
delay
methods.
The
Whenever
the
and
sequence
jumps
the
to
program
the
interrupt
is
written
The
RETI
at
service
instruction
the vector
routine must
at
the end
service
routine
reads the
; The clock frequency is 11.0592 MHz and the baud rate is 2400
.EQU
BAUDNUM, 0F4H
.ORG 0000H
LJMP MAIN
.ORG 0023H
CLR RI
MOV P1, SBUF
RETI
.ORG 0100H
MAIN:
ANL PCON, #7FH
; set
; start timer 1
; select serial mode 1
also.
is
When
complete,
the
serial
microprocessor
jumps
to
the
; The clock frequency is 11.0592 MHz and the baud rate is 2400
.EQU BAUDNUM, 0F4H
.ORG 0000H
LJMP MAIN
.ORG 0023H
CLR TI
; clear Tl
.ORG 0100H
ANL PCON, #7FH
; start timer 1
; select serial mode 1
Data
acquisition
using
External Interrupt
The external interrupts can be used
by slow responding external devices
to
communicate
with
the
microcontroller.
The
1
external interrupts
has
and
vector
0013H.
example,
addresses
In
the
this
and
0003H
following
external interrupt 0
of
an
ADC0804
is
ADC.
of
The
successive
to
the
ADC
must
be
converted
data
is
inputted
via
the
port
1.
The