This chapter begins with a discussion of the role and importance of micro-
controllers in everyday life. In Section 1.1 we also discuss 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 PICl8 family and their fea-
tures. In addition, we provide a brief discussion of alternatives to the PIC chip such
as the 8051, AVR, and 68HCI I microcontrollers.
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 micro-
processors. We also look at the role of microcontrollers in the embedded market.
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 x86
family (8086, 80286, 80386, 80486, and the Pentium) or Motorola's PowerPC
family. These microprocessors contain no RAM, no ROM, and no 1/0 ports on the
chip itself. For this reason, they are commonly referred to as general-purpose
microprocessors. See Figure 1-1.
CPU RAM ROM
1/0 Timer Serial
COM
Port
(a) General-Purpose Microprocessor System (b) Microcontroller
Figure 1-1. Microprocessor System Contruttd With Microcontroller System
A system designer using a general-purpose microprocessor such as the
Pentium or the PowerPC must add RAM, ROM, 1/0 ports, and timers externally
to make them functional. Although the addition of external RAM, ROM, and 1/0
ports makes these systems bulkier and much more expensive, they have the advan-
tage of versatility, enabling the designer to decide on the amount of RAM, ROM,
and I/0 ports needed to fit the task at hand. This is not the case with microcon-
trollers. A microcontroller has a CPU (a microprocessor) in addition to a fixed
amount of RAM, ROM, I/0 ports, and a timer all on a single chip. In other words,
the processor, RAM, ROM, I/0 ports, and timer are all embedded together on one
chip; therefore, 1he designer cannot add any external memory, 1/0, or timer to it.
The fixed amount of on-chip ROM, RAM, and number of VO ports in microcon-
trollers makes them ideal for many applications in which cost and space are criti-
cal. In many applications, for example a TV remote control, there is no need for
24
Home the computing power of a 486 or even an 8086 microprocessor. In
~A"'pp"'1;"".,-eo-,- - - - I many applications, the space used, the power consumed, and the
Intercom price per unit are much more critical considerations than the com-
Telephones puling power. These applications most often require some I/O
Security systems operations to read signals and tum on and off certain bits. For this
Garage door openers reason some call these processors IBP, "itty-bitty processors."
Answering machines (See "Good Things in Small Packages Are Generating Big
Fax machines Product Opportunities" by Rick Grehan, BYTE magazine,
~~;e computm September 1994 (http://www.byte.com) for an excellent discus-
Cable TV tuner sion ofmicrocontrollers.)
VCR It is interesting to note that some microcontroller manu-
Camcorder facturers have gone as far as integrating an AOC (analog-to-digi-
Remote controls tat converter) and other peripherals into the microcontroller.
Microcontrollers for embedded systems
Musical instruments In the literature discussing microprocessors, we often see
Sewing machines the term embedded system. Microprocessors and microcontrollers
~!!~!i;g control are widely used in embedded system products. An embedded
Camera product is controlled by its own internal microprocessor (or
Pinball machines microcontroller) as opposed to an external controller. Typically, in
Toys an embedded system, the microcontroller's ROM is burned with
Exercise equipment a purpose for specific functions needed for the system. A printer
Office is an example of an embedded system because the processor
1;11"',,p"'h•-•-.,----I
1"' inside it perfonns one task only; namely, getting the data and
Computers printing it. Contrast this with a Pentium-based PC (or any x86
Security systems IBM-compatible PC), which can be used for any number of appli-
Fax machine cations such as word processor, print-server, bank teller tenninal,
Microwave video game player, network server, or Internet tenninal. A PC can
~=~;~rioter also load and run software for a variety of applications. Of course,
Color printer the reason a PC can perform myriad tasks is that it has RAM
Paging memory and an operating system that loads the application soft-
Auto ware into RAM and lets the CPU run it. In an embedded system,
Trip computer typically only one application software is burned into ROM. An
Engine control x86 PC contains or is connected to various embedded products
Air bag such as the keyboard, printer, modem, disk controller, sound card,
ABS CD-ROM driver, mouse, and so on. Each one of these peripherals
Instrumentation has a microcontroller inside it that performs only one task. For
Security system example, inside every mouse a microcontroller perfonns the task
Transmission control of finding the mouse's position and sending it to the PC. Table 1-1
Entertainment lists some embedded products.
Climate control
Cellular phone x86 PC embedded applications
Keyless entry
Although microcontrollers are the preferred choice for
Table 1-1: Some many embedded systems, sometimes a microcontroller is inade-
Embedded Products quate for the task. For this reason, in recent years many manufac-
Usinz Microcontrollen turers of general-purpose microprocessors such as Intel, Freescale
Semiconductor (fonnerly Motorola), and AMD (Advanced Micro
CHAPTER I: THE PIC MICROCONTROLLERS: HISTORY AND FEATURES 25
8051 VARIANTS FROM INTIL
mi
l liii(-----..,,t;..,
,_
I/IH IIWI)
.. ••
121
· 8052
:,
· 256, ,, •
QK
128
-
8051 VARIANTS FROM ATMIL
..., _ _ RAM I/OF 1.atunpt
AT'iidt .. ,K 128 J
• A119LV5I 4K 128 •. J2 ]V ' . ,40
An9C105I IIC 64 · 15 JV 20
A119C2Q5I 2K • 128 U ]V 20
ATIIICSl' · .. "' - ~ 128 n
. 5V 40
A'l'M.V5l 111t 128 · • · · J2 JV • 40
-:.-~•·.xr--iT~
8051 VARIANTS FROM DALLAS SIMI
I 11:1:1.1 I~~:@··
electrical engineering show an increasing integration of mechanics with electron-
ics and infonnation processing. This integration is between the components (hard-
ware) and the infonnation-driven functions (software), resulting in integrated sys-
tems called mechatronic systems.
The development of mechatronic systems involves finding an optimal bal-
ance between the basic mechanical structure, sensor and actuator implementation,
automatic digital infonnation processing and overall control, and this synergy
results in innovative solutions. The practice of mechatronics requires multidisci-
plinary expertise across a range of disciplines, such as: mechanical engineering,
electronics, infonnation technology, and decision making theories."
Review Questions
I. True or false. Microcontrollers are nonnally less expensive than microproces-
sors.
2. When comparing a system board based on a microcontroller and a general-
purpose microprocessor, which one is cheaper?
3. A microcontroller nonnally has which of the following devices on-chip?
(a) RAM (b) ROM (c) 110 (d) all of the above
4. A general-purpose microprocessor nonnally needs which of the following
devices to be attached to it?
(a) RAM (b) ROM (c) 110 (d) all of the above
5. An embedded system is also called a dedicated system. Why?
6. What does the term embedded system mean?
7. Why does having multiple sources of a given product matter?
SECTION 1.2: OVERVIEW OF THE PIC18 FAMILY
In this section, we first look at the PIC family of microcontrollers and then
examine the PIC18 family in more detail.
A brief history of the PIC mlcrocontroller
In 1989, Microchip Technology Corporation introduced an 8-bit micro-
controller called the PIC, which stands for Peripheral Interface Controller. This
microcontroller had small amounts of data RAM, a few hundred bytes of on-chip
ROM for the program, one timer, and a few pins for 1/0 ports, all on a single chip
with only 8 pins. (Sec Figure 1-2.) It is amazing that a company thal began with
such a humble product became one of the leading suppliers of 8-bit microcon-
trollers in less than a decade. At the time of this writing, Microchip is the number-
one supplier of 8-bit microcontrollers in the world. Since the introduction of the
PIC16xxx, they have introduced an array of8-bit microcontrollers too numerous
to list here. They include the PIC families of IOxxx, 12xxx, 14xxx, 16xxx, 17xxx,
and 18xxx. They are all 8-bit processors, meaning that the CPU can work on only
8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to
be processed by the CPU. One of the problems with the PIC family is that they are
not all 100% upwardly compatible in tenns of software when going from one fam-
ily to another family. For example, while the 12xxx/16xxx have 12-bit and 14-bit
wide instructions, the PICl8xxx instruction is 16 bits wide with many new instruc-
28
tions. To run programs written for the PICl2xxx on a PIC18, we must recompile
the program and possibly change some register locations before loading it into the
PICl8. At the time of this writing, the PIC18xxx family has the highest perform-
ance of all the families of 8-bit PIC microcontrollers. The fact that PIC l 8xxx is
available in 18- to 80-pin packages makes it an ideal choice for new designs
because it allows an easy migration to more powerful versions of the chip without
losing software compatibility. At this time, no 8-pin version of the PICl8xxx
exists, and that is the main reason to choose other family members of the
10xxx-16xxx if your design calls for a small package. Because this book is about
the PIC18 family, we describe some of the main features of this family and refer
the reader to the Microchip web site for other families of PICI0xxx-16xxx. for
those who have mastered the PIC18 family, understanding the other families is
very easy and straightforward. The following is a brief description of the PIC18
series.
PIC18 features
The PICI 8 has a RISC architecture that comes with some standard features
such as on-chip program (code) ROM, data RAM, data EEPROM, timers, ADC,
and USART and 1/0 ports. See Figure 1-2. Although the size of the program ROM,
data RAM, data EEPROM, and l/0 ports varies among the family members, they
all have peripherals such as timers, ADC, and USART. See figures 1-3 and 1-4.
Due to the importance of these peripherals, we have dedicated an entire chapter to
each one of them. The details of the RAM/ROM memory and UO features of the
PIC 18 are given in the next few chapters.
moo=w
STACK
PC
RAM EEPROM
Program
Bus
CPU
Data
Bus t
llnrerruptl
't°;~
I I
I osc I \ri=~\ IPorts I
l
\Pen°:ra1s\
m,1,1,1,1,1,
~I I~ 110
PINS
Fl&ure 1-2. Slmpllfted View of a PJC
CHAPTER 1: THE PIC MICROCONTROLLERS: HISTORY AND FEATURES 29
PIC microcontroller program ROM
In microcontrollers, the ROM is used to store programs and for that reason
it is called program or code ROM. Although the PICl8 has 2M (megabytes) of
program (code) ROM space, not all family members come with that much ROM
installed. The program ROM size can vary from 4K to 128K at the time of this
writing, depending on the family member. The PIC 18 program ROM is available
in different memory types, such as flash, OTP, and masked, all of which have dif-
ferent part numbers. A discussion of the various types of ROM is given in Chapter
14, if you need to refresh your memory on these important memory technologies.
Note that although different flavors of the PJCl8 exist in tenns of speed and
amount of on-chip RAM/ROM, they are all compatible with each other as far as
the instructions are concerned. This means that if you write your program for one,
it will run on any of them regardless of the chip number. Next, we discuss briefly
the program ROM type for the PIC 18 family.
PIC mlcrocontroller with UV-EPROM
Some of the PIC microcontrollers use UV-EPROM, for on-chip program
ROM. To use these kinds of chips for development requires access to a PROM
burner, as well as a UV-EPROM eraser to erase the contents of ROM. The window
on the UV-EPROM chip allows the UV light to erase the ROM. The problem with
the UV-EPROM is that it takes around 20 minutes to erase the chip before it can
be programmed again. This has led Microchip to introduce a flash version of the
PIC family. At this time flash is replacing the UV-EPROM altogether. Table 1-2
shows some members of the PIC18 family,
PIC18Fxxx with flash
Many PTC!8 chips have on-chip program ROM in the fonn of flash mem-
ory. The flash version uses the letter F in the part number to indicate that the on-
chip ROM is flash. PIC18F458 is an exampleofPICl8 with flash ROM. The flash
version is ideal for fast development because flash memory can be erased in sec•
onds compared to the 20 minutes or more needed for the UV-EPROM version. For
this reason, the PIC18F has been used in place of the UV-EPROM to eliminate
the waiting time needed to erase the chip, thereby speeding up the development
time. To use the PICl 8F to develop a microcontroller-based system requires a
ROM burner that supports flash memory; however, a ROM eraser is not needed,
because flash is an EEPROM (electrically erasable PROM). Notice that in flash
memory, you must erase the entire contents of ROM in order to program it again.
This erasing of flash is done by the ROM programmer itself, and so a separate
eraser is not needed. We can also program the PIC18F via the PICkit 2 from
MicroChip using the USB port ofan IBM PC.
OTP version of the PIC
OTP (one-time-programmable) versions of the PIC are also available from
Microchip. PICl6C432 chip uses OTP for program ROM. Contrast the
PIC16C432 and PICl8F252. The letter C indicates the OTP ROM, while the let-
ter F is for the flash. The flash version is typically used for product development.
When a product is designed and absolutely finalized, the OTP version of the PIC
32
is used for mass production because it is cheaper than flash in terms of price per
unit. lbe problem with the OTP is that you cannot reprogram it if you want to
modify your program.
Masked version of PIC
Microchip Corporation provides a service in which you can send in your
program and they will bum the program into the PIC chip during the fabrication
process of the chip. This chip is commonly referred to as masked PIC, which is
one of the stages of IC fabrication. Masked PIC is the cheapest of all types, if the
unit numbers are high enough. This is because there is a minimum order for the
masked version of the PIC microcontrollers.
PIC microcontroller data RAM and EEPROM
While ROM is used to store program (code), the RAM space is for data
storage. The PICl8 has a maximum of4096 bytes (4K) of data RAM space. Not
all of the family members come with that much RAM . The data RAM size for the
PIC 18 varies from 256 bytes to 4096 bytes. As we will see in the next chapter, the
data RAM space has two components: General-Purpose RAM (GPR) and Special
Function Registers (SFRs). Because the SFRs are fixed and every microcontroller
must have them, it is the GPR's size that varies from chip to chip. For this reason,
the Microchip web site gives only the GPR size. The RAM GPR space is used for
read/write scratch pad and data manipulation and is divided into banks of 256
bytes each, as we will see in Chapter 6. The GPR size given for the PIC18 is
always a multiple of 256 bytes. In some of the PIC 18 family members, we also
have a small amount of EEPROM to store critical data that does not need to be
changed very often. While every PIC 18 must have some data RAM for scratch
pad, the EEPROM is optional, so not all versions of the PICI8 come with EEP-
ROM. EEPROM is used mainly for storage of critical data, as we will see in
Chapter 14.
Table 1-2: Some Members of the PICl8 Family (http:llwww.microcbip.com)
PartNum Code Data Data 1/0pins ADC Timers Pin numben
ROM RAM EEPROM pins & Package
PICl8Fl220 4K (flash) 256 256 16 IO-bit 4 18 DIP
PICl8F2420 16K (flash) 768 0 25 10-bit 28 DIP
PICl8F2220 4K (flash) 512 256 25 IO-bit 28 DIP
PICl8F452 32K (flash) 1536 256 34 10-bit 40D!P
PICl8F4520 32K (flash) 1536 256 36 10-bit 40 DIP
PICl8F458 32K (flash) 1536 256 34 10-bit 40 DIP
PICl8F4580 32K (flash) 1536 256 36 IO-bit 4 40D!P
PICI8F8722 128K (flash) 3936 1024 70 10-bit S 80TOFP
Notes:
I. All ROM, RAM, and EEPROM memories are in bytes.
2. Data RAM (General-Purpose RAM) is the amount of RAM available for data manipulation (scratch
pad) in addition to the Special Function Registers (SFRs) space.
3. All the above chips have USART for serial data transfer.
CHAPTER I : THE PIC MICROCONTROLLERS: HISTORY AND FEATURES 33
Other Microcontrollers
There are many other popular 8-bit microcontrollers besides the PIC chip.
Among them are the 8051 , 68HC 11 , AVR, and 28. Besides Intel, a number of other 53
companies make the 8051 family, as seen in Table 1-4. TheAVR is made by Atmel
Corp. Freescale (Motorola) makes the 68HCI I and many of its variations. Zilog
produces the Z8 microcontroller. To contrast the PIC18 family with the 8051 /52
chip, examine Table 1-3. For a comprehensive treatment of the 8051 microcon-
troller, see "The 8051 Microcontroller and Embedded Systems" by Mazidi, et. al.
Table 1-3: Comparison of 8051 and PICl8 Family (40-pln package)
Feature 8051/52 PIC18xxx
Program ROM (maximum space) 64K 2M
Data RAM (maximum space) 256 bytes 4K
Timers 3 4
110 ins 32 33
Serial ort 1
34
Table 14: Some of the Companies that Produce Widely Used 8-bit Microcontrollers
Company Web Site Architecture
Microchip httpJ/www.microchip.com PIC16XJOUl8xxx
Intel http://www.intel.com/designlmcs51 8051
Atmel http://www.atmel.com AYR and 8051
Philips/Signetics http://www.semiconductors.philips.com 8051
Zilog http://www.zilog.com Z8 and Z80
Dallas Semi/Maxim http://www.maxim-ic.com 8051
Freescale Semi http://www.freescale.com 68HCI l/68HC08
See http:f/www.mk:rocontroller.com for a complete list.
See the following web sites for PIC mlcrocontrollers and PIC Trainer:
http://www.mlcrochip.com
http:/lwww.MlcroDigitalEd.com
Review Questions
I. Name three features of the PIC18xxx.
2 What 1s the mam difference between the PICl8Fxxx and PICl8Cxx.x m
.c
controllers"
Give the size of RAM m each of the following
(a) PICl8F2420 (b) PICl8F4520 •
4 Give the size of the on-chip program ROM m each of the followmg
(a) PICl8F2420 (b) PIC l8F4520
5 The PICl81s a(n) _ _ -btt microprocessor