0 ratings0% found this document useful (0 votes) 162 views256 pages8051 Micro Controller Architecture Programming and Applicati
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
The 8051
Microcontroller
So
"
eyekyDe
The 8051 Microcontroller
ARCHITECTURE, PROGRAMMING,
and APPLICATIONS
Kenneth J. Ayala
Western Carolina University
WEST PUBLISHING COMPANY
ST. PAUL = NEW YORK = LOS ANGELES * SAN FRANCISCO.Copyediting: Technical Texts, Inc.
Text and Cover Design: Roslyn Stendahl, Dapper Design
Cover Image: Christopher Springmann, The Stock Market
‘Composition: G&S Typesetters, Inc.
Artwork: George Barile, Accurate Art
COPYRIGHT © 1991 By WEST PUBLISHING COMPANY
50 W. Kellogg Boulevard
PO. Box 64526
St.Paul, MN 55164-0526
All rights reserved
Printed in the United States of America @
98 97 96 95 9493 9291 87654321
Library of Congress Cataloging in-Publication Data
‘Ayala, Kenneth J
The 8051 microcontroller : architecture, programming,
and applications / Kenneth J. Ayala,
poem.
Includes index.
ISBN 0-314-77278-2 (soft)
1, Inte! 8051 (Computer) 2. Digital control systems.
|. Title
QA76.8.127093 1991
004.165—de20 90-12928,
cP=
To John Jamison of VMI and
John Peatman of Georgia Tech,
both of whom made this book possible>
Contents
‘1 MICROPROCESSORS AND MICROCONTROLLERS 1
Introduction 1
Microprocessors and Microcontrollers 2
Microprocessors 2
Microcontrollers 3
Comparing Microprocessors and Microcontrollers 4
The 280 and the 8051 4
A Microcontroller Survey 5
Four-Bit Microcontroller 5
Eight-Bit Microcontrollers 6
Sixteen-Bit Microcontrollers 7
Thirty-Two Bit Microcontrollers 8
Development Systems for Microcontrollers 9
Summary 9
Questions 10
2 =~ THE 8051 ARCHITECTURE 11
Introduction 11
8051 Microcontroller Hardware = 11
The 8051 Oscillator and Clock 16
Program Counter and Data Pointer 17
AandB CPU Registers 17
Flags and the Program Status Word (PSW) 18
internal Memory 19
Internal RAM = 19
The Stack and the Stack Pointer 19
Special Function Registers 21
Internal ROM = 22
Input/Output Pins, Ports, and Circuits 22
PortO = 23
Port1 25
viiviii
CONTENTS
Port2 25
Port3 25
External Memory 26
Connecting External Memory 26
Counter and Timers 28
Timer Counter interrupts 29
Timing 30
Timer Modes of Operation 30
Timer Mode 0 30
Timer Mode 1 30
Timer Mode 231
Timer Mode 3 32
Counting 32
Serial Data Input/Output _ 32
Serial Data Interrupts 32
Data Transmission 34
Data Reception 34
Serial Data Transmission Modes 34
Serial Data Mode 0-Shift Register Mode 34
Serial Data Mode 1-Standard UART 35
Made 1 Baud Rates 36
Serial DataMode 337
Interrupts 37
Timer Flag Interrupt 39
Serial Port Interrupt 39
External Interrupts 39
Reset 40
Interrupt Control 40
Interrupt Enable/Disable 40
Interrupt Priority 41
Interrupt Destinations 41
Software Generated Interrupts 41
Summary 41
Questions 42
3° MOVING DATA 44
introduction 44
Addressing Modes 45
Immediate Addressing Mode 45
Register Addressing Mode 45
Direct Addressing Mode 47
Indirect Addressing Mode 49
External Data Moves 50
‘Code Memory Read-Only Data Moves 51
PUSH and POP Opcodes
Data Exchanges 53
Example Programs 54
Summary 56
Problems 57‘CONTENTS, ix
LOGICAL OPERATIONS 59
Introduction 59
Byte-Level Logical Operations 60
Bit-Level Logical Operations 62
Internal RAM Bit Addresses 62
SFR Bit Addresses 62
Bit-Level Boolean Operations 63
Rotate and Swap Operations 66
Example Programs 68
Summary 69
Problems 70
ARITHMETIC OPERATIONS 71
Introduction = 71
Flags 72
Instructions Affecting Flags 72
incrementing and Decrementing 73
Addition 74
Unsigned and Signed Addition 74
Signed Addition 75
Multiple-Byte Signed Arithmetic 76
Subtraction 77
Unsigned and Signed Subtraction 78
Unsigned Subtraction 78
Signed Subtraction 78
Multiplication and Division 80
Multiplication 80
Division 80
Decimal Arithmetic 81
Example Programs 82
Summary 84
Problems 85
JUMP AND CALL OPCODES 86
Introduction 86
The Jump and Call Program Range 87
Relative Range 87
Short Absolute Range 88
Long Absolute Range 88
Jumps 89
Bit Jumps 89
Byte Jumps 90
Unconditional Jumps 90
Calls and Subroutines 92
Subroutines 92
Calls and the Stack 92CONTENTS
Calls and Returns 93.
Interrupts and Returns 94
Example Problems 95
Summary 97
Problems 98
7 AN 8051 MICROCONTROLLER DESIGN 100
Introduction 100
A Microcontroller Specification 101
A Microcontroller Design 102
External Memory and Memory Space Decoding 102
Reset and Clock Circuits 102
Expanding /O = 103
Memory-Mapped /O0 104
Part Speed 106
Production Concerns 106
Testing the Design 107
Crystal Test 107
ROM Test 107
RAM Test 108
Timing Subroutines 110
Time Delays 110
Pure Software Time Delay 111
Software Polled Timer 112
Pure Hardware Delay 114
Lookup Tables for the 8051 117
PC as aBase Address 118
DPTR as a Base Address 120
Serial Data Transmission 121
Character Transmission Using a Time Delay 123
Character Transmission by Polling 124
Interrupt-Driven Character Transmission 125
Receiving Serial Data 126,
Polling for Received Data 126
Interrupt-Driven Data Reception 127
Summary 128
Problems 129
8 APPLICATIONS = 131
Introduction 131
Keyboards 132
Human Factors 132
Key Switch Factors 132
Key Configurations 133
Programs for Keyboards 134
A Scanning Program for Small Keyboards 136
Interrupt-Driven Programs for Small Keyboards 139CONTENTS. xi
Program for a Large Matrix Keyboard 147
Displays 151
Seven-Segment Numeric Display 151
Intelligent LCD Display 155
Pulse Measurement 158
Measuring Frequency 158
Pulse Width Measurement 161
D/A and A/D Conversions 162
D/A Conversions 163
A/D Conversion 165
Multiple interrupts 166
Hardware Circuits for Multiple Interrupts 173
Putting it all Together 177
Summary 181
Problems 182
Q SERIAL DATA COMMUNICATION 185
Introduction
Network Configurations 186
8051 Data Communication Modes _ 189
Mode 0: Shift Register Mode 189
Mode 1: Standard 8-Bit UART Mode 192
Modes 2 and 3: Multiprocessor 197
Summary 202
Problems 202
Appendix A 8051 Operational Code Mneumonics 203
Appendix B How to Use the Assembler 212
Appendix C How to Use the Simulator 220
Appendix D The 8255 Programmable /O Port 233
Appendix E Control Registers 236
Index 238>
Preface
‘The microprocessor has been with us for some fifteen years now, growing from an awkward
4-bit child to a robust 32-bit adult. Soon, 64- and then 128-bit wizards will appear to
crunch numbers, spreadsheets, and, CAD CAM. The engineering community became
aware of, and enamored with, the &-bit microprocessors of the middle to late 1970's. The
bit size, cost, and power of these early CPUs were particularly useful for specific tasks
involving data gathering, machine control, human interaction, and many other applica-
tions that granted a limited intelligence to machines and appliances.
‘The personal computer that was spawned by the 8-bit units predictably became faster
by increasing data word size and more complex by the addition of operating system hard-
ware. This process evolved complex CPUs that are poorly suited to dedicated applications
and more applicable to the generic realm of the computer scientist and system program-
mer. Engineering applications, however, did not change: these applications continue to
be best served by 8-bit CPUs with limited memory size and 1/0 power. Cost per unit
also continues to dominate processing considerations. Using an expensive 32-bit micro-
processor to perform functions that can be as efficiently served by an inexpensive 8-bit
microcontrotier will doom the 32-bit product to failure in any competitive marketplace.
Many designers continue to use the older families of 8-bit microprocessors. The
8085, 6502, 6800, and Z80 are familiar friends to those of us who had our first successes
with these radical new computers. We know their faults and idiosyncrasies; we have, quite
literally, tons of application software written for them. We are reluctant to abandon this
investment in time and money.
New technology makes possible, however, a better type of small computer—one with
not only the CPU on the chip, but RAM, ROM, Timers, UARTS, Ports, and other com-
mon peripheral 1/0 functions also. The microprocessor has become the microcontroller.
Some manufacturers, hoping to capitalize on our software investment, have brought
‘out families of microcontrollers that are software compatible with the older micro-
processors. Others, wishing to optimize the instruction set and architecture to improve
speed and reduce code size, produced totally new designs that had litle in common with
their earlier microprocessors. Both of these trends continue.This book has been written for a diverse audience. It is meant for use primarily by
those who work in the area of the electronic design and assembly language programming
of small, dedicated computers.
An extensive knowledge of electronics is not required to program the microcontroller.
Many practitioners in disciplines not normally associated with computer electronics —
transportation, HVAC, mechanisms, medicine, and manufacturing processes of all types —
can benefit from a knowledge of how these “smart chips” work and how they can be used
to improve their particular product.
Persons quite skilled in the application of classical microprocessors, as well as novice
users who have a basic understanding of computer operation but little actual experience,
should all find this book useful. The seasoned professional can read Chapter 2 with some
care, glance at the mnemonics in Chapters 3 through 6, and inspect the applications in
Chapters 7. 8, and 9. The student may wish to quickly read Chapter 2, study the mnemonics
and program examples carefully in Chapters 3 through 6, and then exercise the example
programs in Chapters 7, 8, and 9 (0 see how it all works.
The text is suitable for a one- oF two-semester course in microcontrollers. A two
semester course sequence could involve the study of Chapters 1 to 6 in the first semester
and Chapters 7. 8. and 9 in the second semester in conjunction with several involved stu-
dent programs. A one-semester course might stop with Chapter 7 and use many short
student assignments drawn from the problems at the end of each chapter. The only pre-
requisite would be introductory topics concerning the basic organization and operation
of any digital computer and a working knowledge of using a PC compatible personal
computer.
‘No matter what the interest level, I hope all groups will enjoy using the software that
has been included on a floppy disk as part of the text. It is my belief that one should not
have to buy unique hardware evaluation boards, or other hardware-specific items, in order
to “try out” a new microcontrolter. ¥ also believe that it is important to get to the job of
writing code as easily and as quickly as possible. The time spent learning to use the hard-
ware board, board monitor, board communication software, and other boring overhead is
time taken from learning to write code for the microcontroller.
The programs included on the disk, an 8051 assembler named ASI, and a simulator,
named $51. were both written by David Akey of PscudoCorp, Newport News, Virginia,
PseudoCorp has provided us all with a software development environment that is not only
casy to use but one that we can uniquely configure for our own special purposes. Details
on the assembler and simulator are provided in the proper appendixes; use them as early as
possible in your studies. Many points that are awkward to explain verbally become clear
when you see them work in the simulator windows! Further information on products
developed by PseudoCorp follows this Preface.
Thave purposefully not included a great deal of hardware-specific information with
the text. If your studies include building working systems that interface digital logic to the
microcontroller. you will become very aware of the need for precise understanding of
the electrical loading and timing requirements of an operating microcontroller. These
details are best discussed in the manufacturer's data book(s) for the microcontroller and
any associated memories and interface logic. Timing and loading considerations are not
trivial; an experienced designer is required to configure a system that will work reliably.
Hopefully, many readers will be from outside the area of electronic design and are mainly
concerned with the essentials of programming and interfacing a microcontroller. For these
users, I would recommend the purchase of complete boards that have the electrical design
completed and clear directions as to how to interface common 1/0 circuits.Many people have played a part in writing this book. Special thanks go to all of the
following people:
The reviewers of the early, really rough, drafts of the text
Richard Barnett, Purdue University
Richard Castetlucis, Southern College of Technology
Jerry Cockrell, Indiana State University
James Grover, University of Akron
Chris Conant, Broome Community College—New York
Alan Cocchetto, Alfred State College~New York
for their thoughtful criticisms and words of encouragement
Cecil A. Moore, Staff Applications Engineer for Intel Corporation in Chandler,
Arizona, whose meticulous comments have greatly improved the technical accuracy
and readability of the text.
‘Tom Tucker of West Publishing for his willingness to experiment.
Anne, my wife, for many years of patience and understanding.
My students, past and present, who have taught me much more than | have taught
them.
Finally, let me thank you, the reader. I would be very grateful if any errors of omission or
commission are gently pointed out to me by letter or telephone. Thank you for your help.
Kenneth J. Ayala
Western Carolina University
Cullowhee, North CarolinaCHAPTER
ee
Microprocessors
and Microcontrollers
Chapter Outline
Introduction Development Systems
Microprocessors and Microcontrotiers for Microcontrollers
‘The Z80 and the 8051 summary
‘A Microcontroller Survey
Introduction
‘The past two decades have seen the introduction of a technology that has radically changed
the way in which we analyze and control the world around us. Born of parallel develop-
ments in computer architecture and integrated circuit fabrication, the microprocessor, or
“computer on a chip,” first became a commercial reality in 1971 with the introduction of
the 4-bit 4004 by a small, unknown company by the name of Intel Corporation. Other,
more well-established, semiconductor firms soon followed Intel’s pioneering technology
0 that by the late 1970s one could choose from a half dozen or so microprocessor types.
‘The 1970s also saw the growth of the number of personal computer users from a
handful of hobbyists and “hackers” to millions of business, industrial, governmental,
defense, educational, and ite users now enjoying the advantages of inexpensive
‘computing.
A by-product of microprocessor development was the microcontroller. The same fab-
rication techniques and programming concepts that make possible the general-purpose
microprocessor also yielded the microcontroller.
Microcontrollers are not as well known to the general public, or even the technical
‘community, as are the more glamorous microprocessors. The public is, however, very
well aware that “something” is responsible for all of the smart VCRs, clock radios, wash-2 CHAPTER ONE
ers and dryers. video games. telephones, microwaves, TVs, automobiles, toys, vending
machines, copiers, elevators, irons, and a myriad of other artictes that have suddenly be-
come intelligent and “programmable.” Companies are also aware that being competitive
in this age of the microchip requires their products, or the machinery they use to make
those products, to have some “smarts.”
The purpose of this chapter is to introduce the concept of a microcontroller and sur-
vey a representative group. The remainder of the book will study one of the most popular
types, the 8051, in detail,
Microprocessors and Microcontrollers
FIGURE 1.1
Microprocessors and microcontrollers stem from the same basic idea, are made by the
same people, and are sold to the same types of system designers and programmers. What
is the difference between the two?
Microprocessors
A microprocessor, as the term has come to be known, is a general-purpose digital com-
puter central processing unit (CPU). Although popularly known as a “computer on a
chip,” the microprocessor is in no sense a complete digital computer.
Figure 1.1 shows a block diagram of a microprocessor CPU, which contains an arith-
‘metic and logic unit (ALU), a program counter (PC), a Stack pointer (SP), some working
registers, a clock timing circuit, and interrupt circuits
To make a complete microcomputer, one must add memory, usually read-only pro-
gram memory (ROM) and random-access data memory (RAM), memory decoders, an
oscillator, and a number of input/output (1/0) devices, such as paralfel and serial data
ports. Additionally, special-purpose devices, such as interrupt handlers, or counters, may
A Block Diagram of a Microprocessor
Arithmetic
and
Logic Unit
‘Accumulator
Working Register(s)
Program Counter Stack Pointer
Clock Interrupt
Circuit CircuitsFIGURE 1.2
MICROPROCESSORS AND MICROCONTROLLERS. 3
be added to relieve the CPU from time-consuming counting or timing chores. Equipping
the microcomputer with a mass storage device, commonly a floppy disk drive, and VO
peripherals, such as a keyboard and a CRT display, yields a small computer that can be
applied to a range of general-purpose software application
‘The key term in describing the design of the microprocessor is “general-purpose.”
‘The hardware design of a microprocessor CPU is arranged so that a small, or very large.
system can be configured around the CPU as the application demands. The internal CPU
architecture, as well as the resultant machine level code that operates that architecture, is
comprehensive but as flexible as possible.
‘The prime use of a microprocessor is to fetch data, perform extensive calculations on
that data, and store those calculations in a mass storage device or display the results for
human use. The programs used by the microprocessor are stored in the mass storage de-
vice and loaded into RAM as the user directs. A few microprocessor programs are stored
in ROM. The ROM-based programs are primarily small fixed programs that operate pe-
ripherals and other fixed devices that are connected to the system. The design of the mi-
croprocessor is driven by the desire to make it as expandable as possible, in the expecta-
tion of commercial success in the marketplace.
Microcontrollers
Figure 1.2 shows the block diagram of a typical microcontroller, which is a true computer
on a chip. The design incorporates all of the features found in a microprocessor CPU:
ALU, PC, SP, and registers. It also has added the other features needed to make a com-
plete computer: ROM, RAM, parallel! I/O, serial 1/0, counters, and a clock circuit
Like the microprocessor, a microcontroller is a general-purpose device. but one
which is meant to fetch data, perform limited calculations on that data, and control its
A Block Diagram of a Microcontroller
AW Timer/Counter i
Port
‘Accumulator
Register(s) an
Port
Internal
Internal iad Interrupt
RAM Circuits
Clock
‘Stack Pointer Circuit
Program Counter4
(CHAPTER ONE
environment based on those calculations. The prime use of a microcontroller is to control
the operation of a machine using a fixed program that is stored in ROM and that does not
change over the lifetime of the system.
‘The design approach of the microcontroller mirrors that of the microprocessor: make
a single design that can be used in as many applications as possible in order to sell, hope-
fully, as many as possible. The microprocessor design accomplishes this goal by having a
very flexible and extensive repertoire of multi-byte instructions. These instructions work
in a hardware configuration that enables large amounts of memory and 1/0 to be con-
nected to address and data bus pins on the integrated circuit package. Much of the activity
in the microprocessor has to do with moving code and data words to and from external
memory to the CPU. The architecture features working registers that can be programmed
to take part in the memory access process, and the instruction set is aimed at expediting
this activity in order to improve throughput. The pins that connect the microprocessor to
external memory are unique, each having a single function, Data is handled in byte, or
larger, sizes
The microcontroller design uses a much more limited set of single- and double-byte
instructions that are used to move code and data from internal memory to the ALU. Many
instructions are coupled with pins on the integrated circuit package; the pins arc “pro-
grammable”—that is, capable of having several different functions depending upon the
wishes of the programmer.
The microcontroller is concerned with getting data from and to its own pins: the ar-
chitecture and instruction set are optimized to handle data in bit and byte size.
Comparing Microprocessors and Microcontrollers
The contrast between 2 microcontroller and a microprocessor is best exemplified by
the fact that most microprocessors have many operational codes (opcodes) for moving
data from external memory to the CPU; microcontrollers may have one, or two. Micto-
Processors may have one or two types of bit-handling instructions: microcontrollers will
have many.
To summarize, the microprocessor is concerned with rapid movement of cade and
data from external addresses to the chip; the microcontroller is concerned with rapid
movement of bits within the chip. The microcontroller can function as a computer with the
addition of no external digital parts: the microprocessor must have many additional parts
to be operational.
The Z80 and the 8051
To see the differences in concept between a microprocessor and a microcontroller, in the
following table we will examine the pin configurations, architecture, and instruction sets,
for a very popular 8-bit microprocessor. the Zilog Z80. and an equally ubiquitous micro-
controller, the 8-bit Intel 8051:
780 8051
Pin Configurations
Total pins 40 40
Address pins 16 (fixed) 16
Data pins 8 (fixed) 8
Interrupt pins 2 (fixed) 2
VO pins o 32
ContinuedMICROPROCESSORS AND MICROCONTROLLERS 5
z80 8051
Architecture
B-bit registers 20 34
16-bit registers 4 2
Stack size ak 128
Internal ROM 0 4K bytes
Internal RAM ° 128 bytes
External memory 64K 128K bytes
Flags 6 4
Timers ° 2
Parallel port 0 4
Serial port 0 1
Instruction Sets
(types/variations)
External moves 4/14 216
Block moves 214 0
Bit manipulate aia 122
Jump on bit ° 323
Stack 35, 22
Single byte 203 49
Multi-byte 490 62
Note that the point here is not to show that one design is “better than the other; the
two designs are intended to be used for different purposes and in different ways. For ex-
ample, the Z80 has a very rich instruction set. The penalty that is paid for this abundance
is the number of multi-byte instructions needed, some 71 percent of the total number.
Each byte of a multi-byte instruction must be fetched from program memory, and each
fetch takes time; this results in longer program byte counts and slower execution time
versus single-byte instructions. The 8051 has a 62 percent multi-byte instruction content;
the 8051 program is more compact and will run faster to accomplish similar tasks.
The disadvantage of using a “lean” instruction set as in the 8051 is increased pro-
grammer effort (expense) to write code; this disadvantage can be overcome when writing
large programs by the use of high-level languages such as BASIC and C. both of which
are popular with 8051 system developers. The price paid for reducing programmer time
(there is always a price) is the size of the program generated.
A Microcontroller Survey
Markets for microcontrollers can run into milions of units per application. At these vol-
umes the microcontroller is a commodity item and must be optimized so that cost is at a
minimum. Semiconductor manufacturers have produced a mind-numbing array of designs
that would seem to meet almost any need. Some of the chips listed in this section are no
longer in regular production, most are current, and a few are best termed “smokeware":
the dreams of an aggressive marketing department
Four-Bit Microcontrollers
In a commodity chip, expense is represented more by the volume of the package and the
number of pins it has than the amount of silicon inside, To minimize pin count and pack-
age size, it is necessary that the basic data word-bit count be held to a minimum, while
still enabling useful intelligence to be implemented6
CHAPTER ONE
Although 4 bits. in this era of 64-bit “maximicros.” may seem somewhat ludicrous,
‘one must recall that the original 4004 was a 4-bit device, and all else followed. Indeed. in
terms of production numbers. the 4-bit microcontroller is today the most popular micro
made. The following table lists representative models from major manufacturers’ data
hooks. Many of these designs have been licensed to other vendors.
RAM ROM
Manufacturer:Model Pins:1/O Counters (bytes) (bytes) Other Features
Hitachi: HMCS40 28:10 — 32 512 10-bit ROM.
National :COP420 28:23 ' 4 IK Serial bit VO.
OKI:MSM6d 11 16:11 _ 32 1K
T-TMS 1000 2:23 — 64 1K LED display
Toshiba: TLCS47 42:35 2 128 2K Serial bit 0
These 4-bit microcontrollers are generally intended for use in large volumes as true
‘computers; expanding external memory, while possible, would negate the cost ad-
vantage desired. Typical applications consist of appliances and toys: worldwide volumes
tun into the tens of millions.
Eight-Bit Microcontrollers
Eight-bit microcontrollers represent a transition zone between the dedicated. high volume,
4-bit microcontrollers, and the high performance. 16- and 32-bit units that will conclude
this chapter.
Eight bits has proven to be a very useful word size for small computing tasks. Ca-
pable of 256 decimal values, or quarter-percent resolution. the 1-byte word is adequate for
many control and monitoring applications. Serial ASCH data is also stored in byte sizes,
making 8 bits the natural choice for data communications. Most integrated circuit memo-
ries and many logic functions are arranged in an 8-bit configuration that interfaces easily
to data buses of 8 bits.
Application volumes for 8-bit microcontrollers may be as high as the 4-bit models, or
they may be very low. Application sophistication can also range from simple appliance
control to high-speed machine control and data collection. For these reasons, the micro-
controller vendors have established extensive “families” of similar models. All feature
a common language, but differ in the amount of internal ROM, RAM, and other cost-
sensitive features. Often the memory can be expanded to include off-chip ROM and
RAM: in some cases. the microcontroller has no on-board ROM at all, or the ROM is an
Electrically Reprogrammable Read Only Memory (EPROM),
‘The purpose of this diversity is to offer the designer a menu of similar devices that can
solve almost any problem, The ROMIess or EPROM versions can be used by the designer
{© prototype the application, and then the designer can order the ROM version in large
‘quantities from the factory. Many times the ROM version is never used. The designer
makes the ROMIess or EPROM design sufficiently general so that one configuration may
be used many times, or because production volumes never justify the cost of a factory
ROM implementation. As a further enticement for the buyer, some families have members
with fewer external pins to shrink the package and the cost: others have special features
such as analog-to-digital (A/D) and digital-to-analog (D/A) converters on the chip.
The 8-bit arena is crowded with capable and cleverly designed contenders; this is the
‘growth segment of the market and the manufacturers are responding vigorously to the
marketplace. ‘The following table lists the generic family name for each chip, but keepMICROPROCESSORS AND MICROCONTROLLERS 7
in mind that ROMless, EPROM, and reduced pin-count members of the family are also
available, Each entry in the table has many variations; the total number of configurations
available exceeds a total of eighty types for the cleven model numbers listed.
RAM ROM
Manufacturer: Model Pins:1/O Counters (bytes) (bytes) Other Features
Intel: 8048 40:27 1 64 1K External memory
8k
Intel: 8051 40:32 2 128 4K External memory to
128K; serial port
National:COP820 28: 1 64 1K Serial bit 1/0
Motorola: 6805 28: 1 64 IK
Motorola:68HCI1 52: 2 256 8K Serial ports; A/D;
watch dog timer
wot)
Rockwell: 6500/1 40:32 1 64 2K
Signetics:87C552 68:48 3 256 8K Serial port; A/D: WDT
T1:TMS7500 40:32 1 128 2K External memory
10 64K
TI:TMS370C050 68:55 2 256 4K External memory to
112K; A/D: serial
ports; WDT
Zilog:Z8 40:32 2 128 2K External memory to
124K; serial port
Zilog :28820 44:40 2 272 8K External memory to
+f CAUTION
Not all of the pins can be used for general-purpose I/O and addressing external memory at the
same time, The sales literature should be read with some care to see how many of the pins have
more than one function. Inspection of the table shows that the designers made tradeoffs: ex-
ternal memory addressing for extra on-chip functions. Generally, the ability to expand memory
off of the chip implies that a ROMless family member is available for use in limited production
numbers where the expense of factory programming can be avoided. Lack of this feature
implies that the chip is meant for high production volumes where the expense of factory-
programmed parts can be amortized over a large number of devices.
Sixteen-Bit Microcontrollers
Eight-bit microcontrollers can be used in a variety of applications that involve limited cal-
culations and relatively simple control strategies. As the requirement for faster response
and more sophisticated calculations grows, the 8-bit designs begin to hit a limit inherent
with byte-wide data words. One solution is to increase clock speeds; another is to increase
the size of the data word. Sixteen-bit microcontrollers have evolved to solve high-speed
control problems of the type that might typically be confronted in the control of ser-
vomechanisms, such as robot arms, or for digital signal processing (DSP) applications.
The designs become much more focused on these types of real-time problems; some
generality is lost, but the vendors still try to hit as many marketing targets as they can. The
following table lists only three contenders. Intel has recently begun vigorously marketingthe $0% Lamy Other vendors are expected to appear as this market segment grows in
inportanee.
RAM ROM
Manufacturer: Model Pins:1/O Counters (bytes) (bytes) Other Features
Hitachi: H8/532 84:65 5 1K 32K External memory to
1 megabyte; serial
port; A/D; pulse
width modulation
Intel :8096 68:40 2 232 8K —_ External memory to
64K; serial port;
A/D; WDT; pulse
width modulation
National: HPCI6164 68:52 4 $12 16K External memory to
64K; serial port:
AID; WDT; pulse
width modutation
The pulse width modulation (PWM) output is useful for controlling motor speed: it
can be done using software in the 8-bit units with the usual loss of time for other tasks.
‘The 16- (and 32-) bit controllers have also been designed to take advantage of high-
level programming languages in the expectation that very little assembly language pro-
gramming will be done when employing these controlters in sophisticated applications.
Thirty-Two Bit Microcontrollers
Crossing the boundary from 16 to 32 bits involves more than merely doubling the word
size of the computer. Software boundaries that separate dedicated programs from super
visory programs are also breached. Thirty two bit designs target robotics, highly intell
‘gent instrumentation, avionics, image processing, telecommunications, automobiles, and
other environments that feature application programs running under an operating system.
‘The line between microcomputers and microcontrollers becomes very fine here,
‘The design emphasis now switches from on-chip features, such as RAM, ROM,
timers, and serial ports, to high-speed computation features. The following table provides
a general list of the capability of the Inte! 80960:
HARDWARE FEATURES SOFTWARE FEATURES
132-pin ceramic package Efficient procedure calls
20 megahertz clack Fault-handling capability
32-bit bus Trace events
Floating-point unit Global registers
§12-byte instruction cache Efficient interrupt vectors
Interrupt control Versatile addressing
All of the functions needed for 1/0, data communications, and timing and counting are
done by adding other specialized chips.
This manufacturer has dubbed all of its microcontrollers “embedded controllers,”
a term that seems to describe the function of the 32-bit 80960 very well.MICROPROCESSORS AND MICROCONTROLLERS, 9
Development Systems
for Microcontrollers
Summary
What is needed to be able to apply a microcontroller to your product? That is, what pack-
age of hardware and software will allow the microcontroller to be programmed and con-
nected to your application? A package commonly called a “development system” is
required
First, trained personnel must be available either on your technical staff or as consul
tants. One person who is versed in digital hardware and computer software is the mini-
mum number.
Second, a device capable of programming EPROMs must be available to test the
prototype device. Many of the microcontroller families discussed have a ROMIess ver-
sion, an EPROM version, or an Electrically Erasable and Programmable Read Only Mem-
ory (EEPROM) version that lets the designer debug the hardware and software prototype
before committing to full-scale production. Many inexpensive EPROM programmers are
sold that plug into a slot of most popular personal computers. More expensive, and more
versatile, dedicated programmers are also available. An alternative to EPROMs are vendor-
supplied prototype cards that allow code to be down loaded from a host computer, and the
program run from RAM for debugging purposes. An EPROM will eventually have to be
‘Programmed for the production version of the microcontroller.
Finally, software is needed, along with a personal computer to host it. The minimum
software package consists of a machine language assembler. which can be supplied by the
microcontroller vendor or bought from independent developers. More expensive software
mainly consisting of high-level language compilers and debuggers is also available.
‘A minimum development system, then, consists of a personal computer, a plug-in
EPROM programmer, and a public-brand assembler. A more extensive system would con-
sist of vendor-supplied dedicated computer systems with attendant high-level software
packages and in-circuit emulators for hardware and software debugging. In 1990 dollars,
the cost for the range of solutions outlined here is from $1000 to $10,000.
‘The fundamental differences between microprocessors and microcontrollers are:
© Microprocessors are intended to be general-purpose digital computers while micro-
controllers are intended to be special-purpose digital controllers,
© Microprocessors contain a CPU, memory addressing circuits, and interrupt han-
dling circuits. Microcontrotiers have these features as well as timers. parallel and
serial 1/O, and internal RAM and ROM.
© Microcontroller models vary in data size from 4 to 32 bits. Four-bit units are pro-
duced in huge volumes for very simple applications, and 8-bit units are the most
versatile. Sixteen- and 32-bit units are used in high-speed control and signal pro-
cessing applications.
© Many models feature programmable pins that allow external memory to be added
with the loss of 1/0 capability. :10 CHAPTER ONE
Questions
1, Name four major differences between a microprocessor and a microcontroller.
2. The 8051 has 40 pins on a Dual Inline Package (DIP) package. yet the comparison with
the Z80 microprocessor totals 58 pins. Explain this difference,
3. Name 20 items that have a built-in microcontroller.
microcontroller,
4, Name 10 items that should have a built
5. Name the most unusual application of a microcontroller that you have seen actually
for sale
6. Name the most likely bit size for each of the following products.
Modem
Printer
Toaster
Automobile engine control
Robot arm
Small ASCH data terminat
Chess player
House thermostat
7. Explain why ROMIess versions of microcontrollers exist
8. Name wo ways to speed up digital data processing
9. List three essential items needed to make up a development system for programming
microcontroller.
10. Search the literature and determine whether any manufacturer has announced a 64-bit
microcontroller.