Hi
The
following example, in Z80
assembly language,
shows
how
to
read
the
Sense
Switches. Combine this
with
the
latch
bits desired,
load
the UART
Control Register
and
Handshake Latch,
and
save the
current state of these
control
bits for later
updates
if necessary.
IN A, (0E9H)
;
READ SENSE SWITCHES
AND 0F8H
;
ZERC
LOWER
3
BITS
OR 05H
;
SETS
REQUEST
TO
SEND,
RESET DATA
TERM
READY, AND SETS
BREAK
OUT
(0EAH)
;
LOADS UART
CONTROL REGISTER
&
HANDSHAKE
LATCH
LD (IMAGE), A
;
SAVES BIT PATTERN
FOR UPDATES
The label IMAGE in the last line above refers to memory location
which is used to save the current state of the UART Control Register
and
the Handshake Latch. Suppose you want to change the logic state
of
Request-tc-Send. The following
example shows how to
do this
without changing the
UART
Control
Register
or
the other Handshake
bits.
LD A, (IMAGE!
;
LOAD CURRENT
STATE
OF
UART
CONTROL
REGISTER
AND
HANDSHAKE
LATCH
RES 0,A
;
RESETS BIT
ZERO IN
A (REQUEST
TO SEND)
OUT (0EAH),A
;
LOADS
NEW BIT PATTERN
LD (IMAGE),
A
:SAVE
NEW PATTERN
FOR UPDATES
An input
operation to Port
Address EAH
reads the UART
Status
Register. Bits D7-D3
convey information
about the
current status
of the UART (Receive
Data ready
for input,
Transmitter
Holding
Register empty, overrun
error,
framing error,
and parity error).
The remaining
bits D2-D0
are unused. You
can read
this register
by
executing
the following
Assembly
Language instruction.
IN A,
(0EAH)
;
READ UART STATUS REGISTER
Execution
of
this
instruction
loads the "A" register
with the
contents
of the UART Status Registers.
Additional
software instructions
can
interpret
this
status
information
and determine if
a new character
can
be loaded for transmission,
if
a
new
character has
been received
or
if received errors have occurred.
An output
operation
to Port
Address EBH
loads the
UART
Trans-
mitter Holding
Register with
a new
character
to be
transmitted
by
the UART.
You
should not
do this until
the holding
register
is found
to be empty (meaning
that the previous
character
has
been
transferred
to
the
transmitter
register for
transmission).
Do
this
by reading the
UART
Status Register
and
checking the
proper
bit for
a logic
one
(1).
The following
Assembly
Language
instructions
illustrate
how
this is
done.
18