Application Note
Software UART for the
Z86E02
AN004102-0502
Z
I
LOG W
ORLDWIDE
H
EADQUARTERS
• 910 E. H
AMILTON
A
VENUE
• C
AMPBELL
, CA 95008
T
ELEPHONE
: 408.558.8500 • F
AX
: 408.558.8300 •
WWW
.Z
I
LOG.
COM
Application Note
Software UART for the Z86E02
This publication is subject to replacement by a later edition. To determine whether a later edition
exists, or to request copies of publications, contact:
ZiLOG Worldwide Headquarters
910 E. Hamilton Avenue
Campbell, CA 95008
Telephone: 408.558.8500
Fax: 408.558.8300
www.ZiLOG.com
Windows is a registered trademark of Microsoft Corporation.
Information Integrity
The information contained within this document has been verified according to the general
principles of electrical and mechanical engineering. Any applicable source code illustrated in the
document was either written by an authorized ZiLOG employee or licensed consultant. Permission
to use these codes in any form, besides the intended application, must be approved through a
license agreement between both parties. ZiLOG will not be responsible for any code(s) used
beyond the intended application. Contact the local ZiLOG Sales Office to obtain necessary license
agreements.
Document Disclaimer
© 2000 by ZiLOG, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be
superseded. ZiLOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A
REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY
DESCRIBED IN THIS DOCUMENT. ZiLOG ALSO DOES NOT ASSUME LIABILITY FOR
INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF
INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. Except
with the express written approval ZiLOG, use of information, devices, or technology as critical
components of life support systems is not authorized. No licenses or other rights are conveyed,
implicitly or otherwise, by this document under any intellectual property rights.
AN004102-0502
Application Note
Software UART for the Z86E02
iii
Table of Contents
General Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Theory of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Results of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Reaffirmation of Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Flow Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Test Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Equipment Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
General Test Setup and Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Setup HyperTerminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
OTP Programming Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Acknowledgments
Project Lead Engineer
Mathias Loehr
Application and Support Engineer
Mathias Loehr
System and Code Development
Mathias Loehr
AN004102-0502
Application Note
Software UART for the Z86E02
1
Software UART for the Z86E02
General Overview
This Application Note describes how to implement a software-emulated universal
asynchronous receiver transmitter (UART) function on the Z86 family of low-cost
8-bit microcontrollers. This particular UART function is half-duplex, event-driven,
and supports an 8-N-1 protocol using an RS-232 interface.
Optionally, a ninth data bit can be enabled. Baud rates from 1200 to 57600 are
supported. The software features full initialization and a basic application for both
a receiver and a transmitter. The primary goals for this software UART are speed
and reliability.
Discussion
Theory of Operation
The UART protocol is based on the EIA RS-232C standard, published in 1969.
That standard was popular with the introduction of personal computers and it is
one of the most commonly used serial interfaces. Originally defined as a 25-pin
interface with several modem handshake and control signals, the basic interface
requires only three lines, Receive (RX), Transmit (TX), and GND. In this constella-
tion, a handshake is executed in software by transmitting special XON and XOFF
characters, or by using a ninth data bit as a separator between command and
data. In most MCU applications, the half-duplex communication is sufficient,
meaning that each side is either a receiver or a transmitter at any given time.
While the transmission speed of the RS-232C cable was formerly limited to 19200
baud for a cable length of 50 feet, advanced specifications and line drivers allow
much higher baud rates today. The underlying UART protocol, however, is still the
same. Figure 1 illustrates that protocol.
Figure 1. Basic 8-bit UART Protocol
S tart
0
1
2
3
4
5
6
7
Stop
51 hex
0
RX Sampling
1
AN004102-0502
Application Note
Software UART for the Z86E02
2
The TX idle state of the UART is High. A High-to-Low transition of the Start bit ini-
tiates the transmission. Eight or nine data bits follow before the Stop bit pulls High
again. In the case of 19200 baud, each bit time is approximately 52µs. Asynchro-
nous operation means that the clock is not transmitted. The receiver must operate
with the same baud rate, usually derived from a local oscillator. It synchronizes on
the falling Start edge and samples the incoming data in their bit middle.
Note:
The actual signal levels on a PC serial connector are inverted by line drivers on
both sides and provide symmetrical levels of around ±12V.
Results of Operation
The Software UART supports the basic format 8-N-1. That format is 8 data bits,
no parity and 1 stop bit. Optionally a 9-bit mode can be enabled to receive or
transmit nine data bits. The ninth bit can be used by software as a separator
between command or address and data. The achieved baud rates depend on RX
or TX mode and the clock frequency, as shown in Table 1.
Table 1. Tested Baud Rates for RX and TX Modes vs. Clock Frequencies
RX-4MHz
RX-8MHz
RX-12MHZ
RX-16MHz
TX-4MHz
TX-8MHz
TX-12MHz
TX-16MHz
1200
1200
1200
1200
1200
1200
2400
2400
2400
2400
2400
2400
2400
2400
4800
4800
4800
4800
4800
4800
4800
4800
9600
9600
9600
9600
9600
9600
9600
9600
19200
19200
19200
19200
19200
19200
19200
38400
38400
38400
57600
57600
38400
38400
Communication is half-duplex. In RX mode, the program waits to receive charac-
ters and stores them in a 16-byte RAM buffer. In TX mode, the program continu-
ously sends out an ASCII message string, stored in code memory.
Options
Several options at assembly or runtime must be selected to adapt the program to
the desired operation. Table 2 contains a list of those options.
AN004102-0502