CHAPTER 1
THE 8051
MICROCONTROLLERS
OBJECTTVES
Upon completion of this chapter, you will be able to:
Compare and contrast microprocessors and microcontrollers
Describe the advantages of microcontrollers for some applications
Explain the concept of embedded systems
Discuss criteria for considering a microcontroller
Explain the variations of speed, packaging, memory, and cost per unit and how these affect
choosinga microcontroller
Compare and contrast the various members of the 8051 family
Compare 8051 microcontrollers offered by various manufacturers
19
This chapter begins with a discussion of the role and importance of microcontrollers in everyday life. In Section 1.1 we
alsodiscuss criteria to consider in choosing a microcontroller, as well as the use of microcontrollers in the embedded
market. Section 1.2 covers various members of the 8051 family such as the 8052 and 8031, and their features. In addition,
we discusSS various versions of the 8051 such as the 8751, AT89C51, and DS5000
SECTION 1.1: MICROcONTROLLERS AND EMBEDDED PROCESSORS
In this section we discuss the need for microcontrollers and contrast them with general-purpose microprocessors
such as the Pentium and other x86 microprocessors. We also look at the role of microcontrollers in the embedded mar-
ket. In addition, we provide some criteria on how to choose a microcontroller.
Microcontroller versus general-purpose microprocessor
What
is the difference between a microprocessor and microcontroller? By microprocessor is meant the general
purpose microprocessors such as Intel's x86family (8086, 80286, 80386, 80486, and the Pentium) or Motorola's 680x0
family (6s000, 68010,68020, 68030, 68040, etc). These microprocessors contain no RAM, no ROM, and no I/O ports on
the chip itselt. For this reason, they are commonly referred to as general-purpose microprocessors.
A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM,
/O ports, and timersextemally to make them functional, Although the addition of external RAM, ROM, and 1/O ports
makes these systems bulkier and much more expensive, they have the
advantage of versatility such that the designer
can decide on the amount of RAM, ROM, and 1/O ports needed to fit the task at hand. This is not the case with micro-
controllers. A microcontroller has a CPU (a microprocessor) in addition to a fixed amount of RAM, ROM, I/O ports, and
a timer all on a
single chip. In other words, the processor, RAM, ROM, I/O ports, and timer are all embedded together
on one
chip; therefore, the designer cannot àdd any external memory, I/O, or timer to it. The fixed amount of on-chip
ROM, RAM, and number of 1/O ports in microcontrollers makes them ideal for many applications in which cost and
space are critical. In many applications, for example a TV remote control, there is no need for the computing power of
a 486 or even an 8086
microprocessor. In many applications, the space it takes, the power it consumes, and the price
per unit are much more critical considerations than the computing power. These applications most often require some
1/O operations to read signals and turn on and off certain bits. For this reason some call these
processors "itty-bitty IBP,
processors" (see "Good Things in Small Packages Are Generating Big Product Opportunities" by Rick Grehan, BYTE
magazine, September 1994; www.byte.com, for an excellent discussion of microcontrollers).
It is interesting to note that some microcontroller manufacturers have
gone as far as
integrating an ADC
digital converter) and other peripherals into the microcontroller. (analog-to
Microcontrollers for embedded systems
In the literature discussing
microprocessors, we often see the term embedded system. Microprocessors and microcon-
trollers are widely used in embedded system products. An embedded
product uses a microprocessor (or microcontroller)
Data bus
CPU
CPU RAM ROM
General
Purpose 1/0 Serial
RAM ROM Timer COM
Micro Port
1/O
processor Port Timer Serial
COM
Port
Address bus
(a) General-l'urpose Microprocessor System (b) Microcontroller
Figure 1-1. Microprocessor System Contrasted With Microcontroller System
20 THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEMS
to do one task and one task only. A printer is an example of embedded system since Table 1-1: Some
the processor inside it performs only one task; namely, getting the data and printing Embedded Products
tt. Contrast this with a Pentium-based PC (or any x861BM-compatible PC). APC can
Deused tor any number of applications such as word processor, print server, bank Using Microcontrollers
teterterminal, video game player, network server, or internet terminal. Software for Home
a varety of applications can be loaded and run. Of course the reason a PC can per-
torm myriad tasks is that it has RAM memory and an operating system that loads
Appliances
Intercom
the application software into RAM and lets the CPU run it. In an embedded system,
there is only one application software that is typically burned into ROM. An x86 PC Telephones
contains or is connected to various embedded products such as the keyboard, printer, Security systems
Garage door openers
modem, disk controller, sound card, CD-ROM driver, mouse, and so on. Each one Answering machines
ot these peripherals has a microcontroller inside it that performs only one task. For
Fax machines
example, inside every mouse there is a microcontroller that performs the task of
Home computers
tndingthe mouse position and sending it to the PC. Table 1-1 lists some embedded
TVs
products. Cable TV tuner
VCR
Camcorder
X86 PC embedded applications Remote controls
Video games
Although microcontrollers are the preferred choice for many embedded sys-
tems, there are times that a microcontroller is inadequate for the task. For this
Cellular phones
Musical instruments
reason, in recent years many manufacturers of general-purpose microprocessors
Sewing machines
SuchasIntel, Freescale Semiconductor Inc. (formerly Motorola), AMD (Advanced
Lighting control
Micro Devices, Inc.), and Cyrix (now a division of National Semiconductor, Inc.)
have targeted their microprocessor for the high end of the embedded market. Paging
Camera
While Intel and AMD push their x86 processors for both the embedded and desk-
Pinball machines
top PC markets, Freescale is determined to keep the 68000 family alive by target-
ing it mainly for the high end of embedded systems now that Apple no longer Toys
uses the 680x0 in their Macintosh. In the early 1990s Apple computer began
Exercise equipment
using Power PC microprocessors (604, 603, 620, etc.) in place of the 680x0 for the
Office
Macintosh. The Power PC microprocessor is a joint venture between IBM and
Freescale, and is targeted for the high end of the embedded market as well as the Telephones
PC market. It must be noted that when a company targets a general-purpose micro- Computers
processor for the embedded market it optimizes the processor used for embed- Security systems
Fax machine
ded systems. For this reason these processors are often called high-end embedded
processors. Very often the terms embedded processor and microcontroller are used Microwave
interchangeably. Copier
One of the most critical needs of an embedded system is to decrease power con- Laser printer
Sumption and space. This can be achieved by integrating more functions into the Color printer
CPU chip. All the embedded processors based on the x86 and 680x0 have low power Paging
consumption in addition to some forms of I/O, COM port, and ROM all on a single
Auto
chip. In high-performance embedded processors, the trend is to integrate more and
more functions on the CPU chip and let the designer decide which features he/she Trip computer
wants to use. This trend is invading PC system design as well. Normally, in design- Engine control
ing the PC motherboard we need a CPU plus a chip-set containing I/0, a cache Air bag
controller, a flash ROM containing BlOS, and finally a secondary cache memory. ABS
New designs are enmerging in industry, For example, Cyrix has announced that it Instrumentation
is working on a chip that contains the entire PC, except for DRAM. In other words, Security system
we are about to see an entire computer on a chip. Transmission control
Currently, because of MS-DOS and Windows standardization many embedded Entertainment
systems are using x86 PCs. In many cases using x86 PCs for the high-end embedded Climate control
applications nof only saves money but also shortens development time since there
Cellular phone
1s a vast library of software already written for the DOS and Windows platforms.
The fact that Windows is a widely used and well understood platform means that
Keyless entry
developing a Windows-based embedded product reduces the cost and shortens the
development time considerably,
THE 8051 MICROCONTROLLERS
21
Choosing a microcontroller
Thereare four major 8-bit microcontrollers. They are: Freescale's 6811, Intel's 8051, Zilog's Z8, and PIC 16X from
Microchip Technology. Each of these microcontrollers has a unique instruction set and register set; therefore, they are
not compatible with each other. Programs written for one will not run on the others. There are also 16-bit and 32-bit
microcontrollers made by various chip makers. With all these different microcontrollers, what criteria do designers
considerin choosing one? Three criteria in choosing microcontrollers are as follows: (1) meeting the computing needs
ofthe task at hand efficiently and cost effectively, (2) availability of software development tools such as compilers,
assemblers, and debuggers, and (3) wide availability and reliable sources of the microcontroller. Next we elaborate
further on each of the above criteria.
Criteria for choosing a microcontroller
The first and foremost criterion in choosing a microcontroller is that it must meet the task athand efficiently and
costeffectively. In analyzing the needs of a microcontroller-based project, we must first see whether an 8-bit, 16-bit,
or 32-bit microcontroller can best handle the computing needs of the task most effectively. Among other considera-
tions in this category are:
(a) Speed. What is the highest speed that the microcontroller supports?
(b) Packaging. Does it come in a 40-pin DIP (dual inline package) or a QFP (quad flat package), or some other
packaging format? This is important in terms of space, assembling, and prototyping the end product.
( Power consumption. This is especially critical for battery-powered products.
(d) The amount of RAM and ROM on chip.
(e) The number of I/O pins and the timer on the chip.
(0 How easy it is to upgrade to higher-performance or lower power-consumption versions.
(g) Cost per unit. This is important in terms of the final cost of the product in which a microcontroller is used. For
example, there are microcontrollers that cost 50 cents per unit when purchased 100,000 units at a time.
The second criterion in choosing a microcontroller is how easy it is to develop products around it. Key considera-
tions includethe availability of an assembler, debugger, a code-efficient C language compiler, emulator. technical
Support,and both in-house and outside expertise. In many cases, third-party vendor (that is, a supplier other thar
the
chip manufacturer) support for the chip is as good as, if not better than, support from the chip manufacturer
The third criterion in choosing a microcontroller is its ready availability in needed quantities both now and in the
future. For some designers this is even more important than the first two criteria. Currently, of the leading 8-bit
microcontrolers, the 8051 family has the largest number of diversified (multiple source) suppliers. By supplier
is meant a producer besides the originator of the microcontroller. In the case of the 8051, which was originated
by Intel, several companies also currently
produce (or have produced in the past) the
B051. These companiesinclude: Intel, Atmel Table 1-2: Some of the Companies Producing a
Philips/Signetics, AMD, Infineon (formerly Member of the 8051 Family
Siemens), Matra, and Dallas Semiconductor.
See Table 1-2. Company Web Site
Intel www.intel.com/design/mcs5l
It should be noted that Freescale, Zilog,
Atmel www.atmel.com
and Microchip Technology have all dedicated
massive resources to ensure wide and timely Philips/Signetics www.semiconductors.phiips.com
availability of their product since their product Infineon www.intineon.com
is stable, mature, and single sourced. In recent
Dallas Semi/Maxim
years they also have begun to sell the ASIC www.maxim-ic.com
library cell of the microcontroller
Review Questions
1 True or false. Microcontrol ers are normally less expensive than microproces ors.
When comparing a system board based on a microcontrol er and a general-purpose microproces or, which one is
cheaper?
22 THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEMS
3. Amicrocontroller normally has which of the
(a) RAM following devices on-chipP
(b) ROM (c) 1/0 (d) all of the above
Ageneral-purpose
(a) RAM microprocessor normally needs which of the following devices to be attached
to it2
(b) ROM (c) 1/0 (d) all of the above
5. An embedded
system
6. What does the term
is also called dedicated system. Why?
a
embedded system mean?
7. Why does having multiple sources of a
given product matter?
SECTION 1.2: OVERVIEW OF THE 8051
FAMILY
in this section we first look at the various members of
the 8051 family of microcontrollers and their internal
Plus we see who are the different
manufacturers of the 8051 and what kind of features.
products they offer.
A brief history of the 8051
n 1981, ntel
of RAM, 4K bytes of
Corporation
introduced an 8-bit microcontroller called the 8051. This
microcontroller had 128 bytes
on-chip
ROM, two timers, one serial port, and four ports (each 8-bits wide) all on a
At the time it was also referred to as a
"system on a chip." The 8051 is an 8-bit single chip.
time. Data larger than 8 bits has to be broken processor, meaning
work on only 8 bits of data at a that the CPU can
CPU. The S051 has a total of four into 8-bit pieces to be
I/O ports, each 8 bits wide. See processed by the
of 64K bytes of Figure 1-2.
on-chip ROM, many manufacturers have put only 4K bytes on the Although
the 8051 can have a maximum
detail later. chip.This will be discussed in more
The 8051 became widely popular after Intel allowed other
8051 they please with the condition that manufacturers to make and market any flavors of the
the 8051 with different
they remain code-compatible with the 8051)
This has led to many versions of
speeds
we review some of them. It
and amounts of on-chip RCOM marketed
by more than half a dozen manufacturers.
is important to note that Next
although there are different flavors of the 8051 in terms of speed
EXTERNAL
INTERRUPTS
ON-CHIP
ROM
INTERRUPT for
program ON-CHIP ETC.
CONTROL
code RAM TIMER 0
TIMER 1
CPU
BUS 41/0
OSC SERIAL
CONTROL PORTS PORT
PO P2 PI P3
TXD RXD
ADDRESS/DATA
gure 1-2. Inside the 8051
Microcontroller Block Diagram
THE B051 MICROCONTROLLERS
and amount of on-chip ROM, they are all compatible with the original 8051
Table 1-3: Features of the 8051
as far as the instructions are concerned. Thisthat if you write your
means
program for one, it will run on any of them regardless of the manufacturer Feature Quantity
ROM 4K bytes
8051 microcontroller RAM 128 bytes
TheS051 isthe original member of the 8051 family, Intel refers to it as Timer
MCS 51. Table 1-3 shows the main features of the 8051. I/O pins
Serial port
Other members of the 8051 family Interrupt sources
There are two other members in the 8051 family of microcontrollers Note: ROM amount indicates on-chip program
They are the 8052 and the 8031. space.
8052 microcontroller
The S052 is another member of the 8051 family. The 8052 has all the standard features of the 8051 as well as an extra
128 bytes of RAM and an extra timer. In other words, the 8052 has 256 bytes of RAM and 3 timers. It also has 8K bytes
of on-chip program ROM instead of 4K bytes. See Table 1-4.
As can be seen from Table 1-4, the 8051 is a subset of the 8052; therefore, all programs written for the 8051 will run
on the 8052, but the reverse is not true.
8031 microcontroller
(Another member of the 8051 family is the 8031 chip. This chip is often referred to as a ROM-less 8051 since it has 0K
bytes of on-chip ROM. To use this chip you must add external ROM to it. This external ROM must contain the program
that the 8031 will fetch and execute.1Contrast that to the 8051 in which the on-chip ROM contains the program to be
fetched and executed but is limited to only 4K bytes of code. The ROM containing the program attached to the 8031 can
be as large as 64K bytes. In the process of adding external ROM to the 8031,
you lose two ports. That leaves only 2
(of the 4 ports) for 1/O operations. To solve this problem, you can add external 1/O to the 8031. nterfacing the ports
8031
with memory and I/O ports such as the 8255
chip is discussed in Chapter 14. There are also various speed versions of
the 8031 available from different
companies.
Various 8051 microcontrollers
Although the 8051 is the most popular member of the 8051 family, you will not see "8051" in the part number.
This is because the 8051 is available in different memory
types, such as UV-EPROM, flash, and NV-RAM, all of which
have different part numbers. A discussion of the various
types of ROM will be given in Chapter 14. The UV-EPROM
version of the 8051 is the 8751. The flash ROM version is marketed by many companies including Atmel Corp. and
Dallas Semiconductor. The Atmel Flash 8051 is called AT89C51, while Dallas Semiconductor calls theirs
(DS89C420/430/440). The NV-RAM version of the 8051 made by Dallas Semiconductor is called DS5000. There is also
DS89C4x0
an OTP (one-time programmable) version of the 8051 made by various manufacturers. Next we discuss briefly each ot
the above chips and describe applications where they are used.
Table 1-4: Comparison of 8051 Family Members
Feature 8051 8052 8031
ROM (on-chip program space in bytes) 4K 8K OK
RAM (bytes) 128 56 128
Timers
1/O pins 32
Serial port
Interrupt sources
24 THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEMS
8751 microcontroller
This 8751 chip has only 4K bytes of on-chip UV-EPROM. Using this chip for development requires access to a
PROM burner, as well as a UV-EPROM eraser to erase the contents of UV-EPROM inside the 8751 chip beforeyou can
program it again. Because the on-chip ROM for the 8751 is UV-EPROM, it takes around 20 minutes to erase the 8751
before it can be programmed again. This has led many manufacturers to introduce flash and NV-RAM versions ofthe
8051, as we will discuss next. There are also various speed versions of the 8751 available from different companies
DS89C4x0 from Dallas Semiconductor (Maxim)
Many popular 8051 chips have on-chip ROM in the form of flash memory. The AT89C51 from Atmel Corp. is one
example of an 8051 with flash ROM. This is ideal for fast development since flash memory can be erased in seconds
compared to the twenty minutes or more needed for the 8751. For this reason the AT89C51 is used in place of the8761
to eliminate the waiting time needed to erase the chip and thereby speed up the development time. Using theATE9C51
to develop a microcontroller-based system requires a ROM burner that supports flash memoryy however, a ROM eraser
is not needed. Notice that in flash memory you must erase the entire contents of ROM in order to program it again. This
erasing of fash is done by the PROM burmer itself, which is why a separate eraser is not needed.Toeliminatethe need
for a PROM burner, Dallas Semiconductor, now part of the Maxim Corp., has a version of the 8051/52 called D559C40
(DS89C420/430/...) that can be programmed via the serial COM port of an IBM PC.
Notice that the on-chip ROM for the Ds89C4x0 is in the form of flash. The DS89C4x0 (420/430/440/450) comes
with an on-chip loader, which allows the program to be loaded into the on-chip flash ROM while it is in the system
This can be done via the serial COM port of an IBM PC. This in-system program loading of theDS89Cix0 via a P
serial COM port makes it an ideal home development system. Dallas Semiconductor also has an NV-RAM version of
the 8051 called DS5000. The advantage of NV-RAM is the ability to change the ROM contents one byte at a time. The
DS5O00 also comes with a loader, allowing it to be programmed via the PC's COM port. See Table 1-5. From Table 1-5
notice that the DS89C4x0 is a really an 8052 chip since it has 256 bytes of RAM and 3 timers. More details of this chip
are given throughout the book.
DS89C4x0 Trainer
In Chapter 8, we discuss the design of DS89C4x0 Trainer extensively. The MDE8051 Trainer is available from www.
MicroDigitalEd.com. This Trainer allows you to program the DS89C4x0 chip from the cOM port of the x86 IBM PC,
with no need for a ROM burner.
For a DS89C4x0-based trainer see www.MicroDigitalEd.com
AT89C51 from Atmel Corporation
The Atmel Corp. has a wide selection of 8051 chips, as shown in Tables 1-6 and 1-7. For example, the ATS9C51 is
a popular and inexpensive chip used in many small projects, It has 4K bytes of flash ROM. Notice the ATS9C51-12PC,
where "C" before the 51 standsfor CMOS, which has a low power consumption, "12" indicates 12 MHz, "P" is for plastic
DIP package, "C" is for commercial.
Table 1-5: Versions of 8051/52 Microcontroller From Dallas Semiconductor (Maxim)
Part Number ROM RAM I/O pins Timers Interrupts
DS89C420 /30 16K (Flash) 256 32 5V
DS89C440 32K (Flash) 256 32
DS89C450 64K (Flash) 256 32 SV
DS5000 8K (NVRAM) 128 32 SV
DSBOC320 OK 256 5V
DS87520 16K (UVROM) 256 32 5V
Ource www.mnaxdn-ic.com/products/microcontrollers/8051 drop in cm
THE 8051 MICROCONTROLLERS 5
Table 1-6: Versions of 8051 From Atmel (All ROM Flash)
Part Number ROM RAM /O pins Timer Interrupt Vcc Packaging
AT89C51 4K 128 32 6 5V 40
128 32 6 3V 40
AT89LV51 AK
AT89C1051 64 3V 20
AT89C2051 128 15 3V 20
AT89C52 128 32 5V 40
AT89LV52 8K 128 34 3V 40
Note: "C in the part number indicates CMOS.
Table 1-7: Various Speeds of 8051 From Atmel
Use
Part Number Speed Pins Packaging
AT89C51-12PC 12 MHz 40 DIP plastic commercial
AT89C51-16PC 16 MHz 40 DIP plastic Commercial
AT89C51-20PC 20 MHz 40 DIP plastic Commercial
OTP version of the 8051
There are also OTP (one-time-programmable) versions of the 8051 available from different sources. Flash and NV
RAM versions are typically used for product development. When a product is designed and absolutely finalized, the
P version of the B051 is used for mass production since it is much cheaper in terms of price per unit.
8051 family from Philips
Another major producer of the 8051 family is Philips Corporation. Indeed, they have one of the largest selections of
8051 microcontrollers. Many of their products include features such as A-to-D
converters, D-to-A converters, extended
1/0, and both OTP and flash. For the list of companies producing the 8051
family see the Web sites in the box below.
See the following Web sites for 8051
products and
their features from various companies:
www.8052.com/chips.phtml
www.MicroDigitalEd.com
Review Questions
1. Name fthree features of the
8051
2. What is the major difference between the 8051 and 8052
microcontrollers?
3. Give the size of RAM in each of the following: (a) 8051 (b) 8052 (c) 8031
4. Give the size of the on-chip ROM in each of the
5. The 8051 is a(n)
following: (a) 8051 (b) 8052 (c) 8031
bit microprocessor
6. State a major difference between the 8751, the
7. True or false. The DS89C420/30 is
AT89C51, and the DS89C420/30.
really an 8052 chip.
26 THE 8051
MICROCONTROLLER AND EMBEDDED SYSTEM5