0% found this document useful (0 votes)
23 views67 pages

Microcontroller - Introduction - 1

The document provides an introduction to microcontrollers, explaining their significance in modern electronics as devices that integrate hardware and software for various applications. It outlines the components of microcontrollers, their functionalities, and their prevalence in everyday devices such as appliances, vehicles, and industrial systems. Additionally, it discusses the advantages of using microcontrollers over traditional integrated circuits, emphasizing their programmability and versatility in handling diverse tasks.

Uploaded by

Lucky Kitsuka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views67 pages

Microcontroller - Introduction - 1

The document provides an introduction to microcontrollers, explaining their significance in modern electronics as devices that integrate hardware and software for various applications. It outlines the components of microcontrollers, their functionalities, and their prevalence in everyday devices such as appliances, vehicles, and industrial systems. Additionally, it discusses the advantages of using microcontrollers over traditional integrated circuits, emphasizing their programmability and versatility in handling diverse tasks.

Uploaded by

Lucky Kitsuka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA.

DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |1
TOPIC ONE
INTRODUCTION TO MICROCONTROLLERS
Welcome to the wonderful world of microcontrollers. As you might be
aware microprocessors in general and microcontrollers in particular have
substantially changed the electronics today.

Nowadays electronic devices and circuits are not


designed as electronic connections,
but as software running within the microcontrollers.
So electronic devices today are the blend
of hardware and software.

These small devices have revolutionized the world of electronics.

Today microcontrollers are everywhere, think of a device and you


will find a microcontroller somewhere in it. May it be your remote
Control, air conditioner, microwave oven, DVD player, television or
cell phone all have a microcontroller sitting inside.

. Moreover, they are very simple to use, you don't need to be an expert in
electronics to use them in your next project. A basic understanding of
electronics and digital circuits is all that is required to get started. Once
you are in the business, sky is the limit. Think of any logical application
and you will find microcontroller handling the job nicely. Industrial
automation including automatic assembly lines, robots and quality control
systems all are backed by some kind of microcontroller.

So exactly what is a microcontroller or a microprocessor? As a hobbyist


or as a student of electronics you must have come across a number of
integrated circuits. These are small devices, with lots ofcircuitry inside
them, having few connections for external communication. However, all
these integrated circuits differ from each
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |2
other, in terms of function. The circuit inside an integrated circuit, may
it be digital or analog, is purpose designed. Like 555, a very popular timing
IC, has all the necessary circuitry inside to make various types of
oscillators. Similarly, a 7447 is a binary to 7-segment decoder, and has
input pins to accept binary coded decimal (BCD) number; the output
pins will then turn on and off accordingly to display the number on a 7-
segment display. So on and so forth, you come across hundreds and
thousands of ICs with specific functions. In order to get an application
work, you must know specifically the function, input and output
requirements of the particular integrated circuit.

Microcontrollers and microprocessors are integrated circuits (IC), but


they differ fundamentally from other ICs. They are a class in themselves,
that the designers have not made them to do a particular job.As such when
you buy them from the market, you can not specify what function it will
do.

In order to get some useful function, these ICs have to be configured.


Thus, a microprocessor or microcontroller can be configured to check
the status of a button, and then turn a motor ON or OFF. While the same
IC can be configured later, to read the status of an infra-red sensor, decode
the signal and turn another device ON or OFF.

If these two types of circuitries were to be made using conventional digital


ICs, it would have required a large number of components. Moreover, any
change in the specification, like change of Infra-Redcodes would result
in total change in design!

Using a configurable IC, is a great idea. Not only the same IC, can be
configured to do different tasks, but a change in specifications can easily
be implemented by just changing the device configuration. This greatly
facilitated the engineers and hobbyists to rapidly develop new electronic
devices, and continuously improve previous ones. Not only the hardware
requirements decreased, but also design time, and time to
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |3
market was decreased.
Microcontrollers and microprocessors therefore took over the market.
Large hardware designs were reduced, and most of the circuitry was
replaced by the configuration scripts. Today we call this ability to
configure a microprocessor or microcontroller, programming.

A program is a series of instructions, in a correct and logical manner to


instruct the microprocessor or microcontroller respond to various inputs.

By changing the program, the behavior of microcontroller will change.


Think of it as a music system. The manufacturer has not designed itto
produce any particular sounds out of its speakers. Yet it has all the
necessary circuitry to do that. What music it will produce would depend
upon the tape, or CD inserted. Thus, you change the CD, and the same
hardware is playing different thing. So, we can say that the music system
is a programmable device, and the information stored on tape, or CD is the
program, or instructions to help the music system, make sounds.

Similarly, microprocessors and microcontrollers are programmed to do a


job. The job can be changing a TV channel to controlling complex
movements of a robot. All these applications have a microcontroller doing
its specific job. It can be astonishing to find the same microcontroller in
the remote control, and the robot. In one place it is driving an infra-red
LED and in other it is driving the motors.

Definitions
A microcontroller is a small computer on a single integrated circuit (IC)
containing a processor core, memory, and programmable input/output
ports.

It is a single IC which contains the microprocessor with integrated


peripherals like memory, serial ports, parallel ports, timer/counter,
interrupt controller, data acquisition interfaces like ADC, DAC is
BY
BY MR.
MR. AKETCH
AKETCH -- AA TVET TRAINER -- KENYA
TVET TRAINER KENYA COAST NATIONAL POLYTECNIC
COAST NATIONAL POLYTECNIC MOMBASA.
MOMBASA. DATE
DATE 05/04/2019
05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |4
called Microcontroller.

It can also be defined as a compact integrated circuit designed to govern


a specific operation in an embedded system. It is called an embedded
controller because the microcontroller and its support circuits are often
built into, or embedded in, the devices they control.

A typical microcontroller includes a processor, memory and input/output


(I/O) peripherals on a single chip.

A microcontroller sometimes abbreviated µC, uC or MCU)

Where do we find microcontrollers?


Microcontrollers are found in vehicles, robots, office machines, medical
devices, mobile radio transceivers, vending machines and home appliances
among other devices.

They are used in automatically controlled products and devices, such as


automobile engine control systems, implantable medical devices, remote
controls, office machines, appliances, power tools, toys and other
embedded systems. By reducing the size and cost compared to a design
that uses a separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more devices
and processes

They are especially designed for embedded applications. This is in contrast


to the microprocessors used in personal computers or other general purpose
applications

Most programmable microcontrollers that are used today as said before are
embedded in other consumer products or machinery including phones,
peripherals, automobiles and household appliances for computer systems.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |5

Input and output devices to the microcontroller include solenoids, LCD


displays, relays, switches and sensors for data like humidity, temperature
or light level, amongst others
Just as mentioned, you can find microcontrollers in all kinds of electronic
devices these days.

Any device that measures, stores, controls, calculates, or displays


information must have a microcontroller chip inside.

The largest single use for microcontrollers is in automobile industry


(microcontrollers here widely used for controlling engines and power
controls in then automobiles).

You can also find microcontrollers inside keyboards, mouse, modems,


printers, and other peripherals.
In test equipment, microcontrollers make it easy to add features such as the
ability to store measurements, to create and store user routines, and to
display messages and waveforms.

Other consumer products that use microcontrollers include digital


camcorders, optical players, LCD/LED display units, implantable medical
devices, remote controls, office machines, appliances, power tools, toys
and etc. And these are just a few examples.

The first microcontrollers were Intel 8048 integrated into PC keyboards,


Intel 8051 and 68HCxx series of microcontrollers from Motorola.
Microcontrollers perform numeric operations that include;
• Supermarkets in Cash Registers, Weighing Scales, etc.
• Home in Ovens, Washing Machines, Alarm Clocks, etc.
• Toys, VCRs, Stereo Equipment, etc.
• Office in Typewriters, Photocopiers, Elevators, etc.
• Industry in Industrial Automation, safety systems, etc.

BY
BY MR.
MR. AKETCH
AKETCH -- AA TVET TRAINER -- KENYA
TVET TRAINER KENYA COAST NATIONAL POLYTECNIC
COAST NATIONAL POLYTECNIC MOMBASA.
MOMBASA. DATE
DATE 05/04/2019
05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |6
• On
roads in Cars, Traffic Signals, etc.
A microcontroller basically contains one or more following components:
 Central processing unit (CPU)
 Random Access Memory) (RAM)
 Read Only Memory (ROM)
 Input/output ports
 Timers and Counters
 Interrupt Controls
 Analog to digital converters
 Digital analog converters
 Serial interfacing ports
 Oscillatory circuits

A microcontroller is available in different word lengths like


microprocessors (4bit,8bit,16bit,32bit,64bit and 128-bit microcontrollers
are available today).

Block diagram of a typical microcontroller

Figure 1.1: A block diagram of a microcontroller.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |7
CPU
It is the brain of the controller and contains the arithmetic logic unit, the control unit, and the registers.
CPU is responsible for fetching the instruction, decoding, then finally executing the instruction.
The

CPU connects every part of a microcontroller into a single system. The primary function of CPU is
fetching and decoding instructions. The instruction fetched from program memory must be decoded
by the CPU.

Memory
The function of memory in a microcontroller is the same as a microprocessor. It is used to store data
and program. A microcontroller usually has a certain amount of RAM and ROM (EEPROM,
EPROM, etc.) or flash memories for storing program source codes.

Memory is split into program memory and data memory. This is not shown in the block diagram
above.

Parallel input/output ports


Parallel input/output ports are mainly used to drive/interface various devices such as LCD’S,
LED’S, printers, memories, etc to a microcontroller.

Serial ports
Serial ports provide various serial interfaces between a microcontroller and other peripherals like
parallel ports.

Timers/counters
This is the one of the useful functions of a microcontroller. A microcontroller may have more
than one timer and counters. The timers and counters provide all timing and counting functions
inside the microcontroller. The major operations of this section are performed clock functions,
modulations, pulse generations, frequency measuring, making oscillations, etc. This also can be
used for counting external pulses. Watchdog Timer is used to reset the controller in case of
software “crashes” to ensure safety of critical systems for microcontrollers.

Analog to Digital Converter (ADC)


ADC converters are used for converting the analog signal to digital form. The input signal in this
converter should be in analog form (e.g. sensor output) and the output from this unit is in digital
form. The digital output can be used for various digital applications (e.g. measurement devices).

Digital to Analog Converter (DAC)


DAC perform reversal operation of ADC conversion converts the digital signal into analog format. It
usually used for controlling analog devices like DC motors, various drives, etc.

Interrupt control

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |8
The interrupt control is used for providing interrupt (delay) for a working program. The interrupt
may be external (activated by using interrupt pin) or internal (by using interrupt instruction during
programming).

Special functioning block


Some microcontrollers are used only for some special applications (e.g. space systems and robotics)
these controllers containing additional ports to perform such special operations. This considered as
special functioning block.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pa ge |9
History
This is how it all got started…
It was year 1969, and a team of Japanese engineers from the
BUSICOM Company arrived to United States with a request
that a few integrated circuits for calculators be made
according to their projects. The proposition was set to
INTEL, and Marcian Hoff was responsible for the project.
Since he was the one who has had experience in working
with a computer (PC) PDP8, it occurred to him to suggest a
fundamentally different solution instead of the suggested
construction. This solution presumed that thefunction of the
integrated circuit is determined by a program stored in it.
That meant that configuration would be more simple, but
that it would require far more memory than the project that
was proposed by Japanese engineers would require.

After a while, though Japanese engineers tried finding an


easier solution, Marcian's idea won, and the first
microprocessor was born. In transforming an idea into a
ready made product , Frederico Faggin was a major help
to INTEL. He transferred to INTEL, and in only 9 months
had succeeded in making a product from its first conception.
INTEL obtained the rights to sell this integral block in 1971.
First, they bought the license from the BUSICOM Company
who had no idea what treasure they had. During that year,
there appeared on the market a

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 10

microprocessor called 4004. That was the first 4-bit


microprocessor with the speed of 6 000 operations per
second.

Not long after that, American company CTC requested from


INTEL and Texas Instruments to make an 8-bit
microprocessor for use in terminals. Even though CTCgave
up this idea in the end, Intel and Texas Instruments kept
working on the microprocessor and in April of 1972, first 8-
bit microprocessor appeared on the market under a name
8008. It was able to address 16Kb of memory, and it had 45
instructions and the speed of 300 000 operations per
second. That microprocessor was the predecessor of all
today's microprocessors. Intel kept their developments up
in April of 1974, and they put on the market the 8-bit
processor under a name 8080 which was able to address
64Kb of memory, and which had 75 instructions, and the
price began at $360.

In another American company Motorola, they realized


quickly what was happening, so they put out on the market
an 8-bit microprocessor 6800. Chief constructor was Chuck
Peddle, and along with the processor itself,Motorola was
the first company to make other peripherals such as 6820
and 6850. At that time many companies recognized greater
importance of microprocessors and began their own
developments. Chuck Peddle leaved
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 11

Motorola to join MOS Technology and kept working


intensively on developing microprocessors.

At the WESCON exhibition in the USA in 1975, a crucial


event in the history of the microprocessors took place.MOS
Technology announced that it was selling processors 6501
and 6502 at $25 each, that interested customers could
purchase immediately. It was such a sensation that many
thought it was a kind of fraud, considering that competing
companies were selling the 8080 and 6800 at
$179 each. On the first day of the exhibit, in response to
the competitor, both Motorola and Intel cut the prices of
their microprocessors to $69.95. Motorola accused MOS
Technology and Chuck Peddle of plagiarizing the protected
6800. Because of that, MOS Technology gave up further
manufacture of the 6501, but kept manufacturing the 6502.
It was the 8-bit microprocessor with 56 instructions and
ability to directly address 64Kb of memory. Due to low
price, 6502 became very popular so it was installed into
computers such as KIM-1, Apple I, Apple II, Atari,
Commodore, Acorn, Oric, Galeb, Orao, Ultra and many
others. Soon several companies began manufacturing the
6502 (Rockwell, Sznertek, GTE, NCR, Ricoh, Commodore
took over MOS Technology). In the year of its prosperity
1982, this processor was being sold at a rate of 15 million
processors per year!

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 12

Other companies did not want to give up either. Frederico


Faggin left Intel and started his own company Zilog Inc. In
1976 Zilog announced the Z80. When designing this
microprocessor Faggin made a crucial decision. The 8080
had already been developed and he realized that manywould
remain loyal to that processor because of the great
expenditures which rewriting of all the programs would
result in. Accordingly he decided that a new processor had
to be compatible with the 8080, i.e. it had to be able to
perform all the programs written for the 8080. Apart from
that, many other features have been added so that the Z80
was the most powerful microprocessor at that time. It was
able to directly address 64Kb of memory, had 176
instructions, a large number of registers, a built-in option
for refreshing dynamic RAM memory, a single power
supply, greater operating speed etc. The Z80 was a great
success and everybody replaced the 8080 by the Z80.
Certainly the Z80 was commercially the most successful 8-
bit microprocessor at that time. Besides Zilog, other new
manufacturers such as Mostek, NEC, SHARP and SGS
appeared soon. The Z80 was the heart of many computers
such as: Spectrum, Partner, TRS703, Z-3 and Galaxy.
In 1976 Intel came up with an upgraded version of the 8-bit
microprocessor called the 8085. However, the Z80 was so
much better that Intel lost the battle. Even though a few more
microprocessors appeared later on the market (6809,
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 13

2650, SC/MP etc.), the die had already been cast. There
were no such great improvements which could make
manufacturers to change their mind, so the 6502 and Z80
along with the 6800 remained chief representatives of the
8-bit microprocessors of that time.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 14
Microprocessor
It is a multipurpose, programmable, clock-driven, register-based,
electronic device that reads binary instructions from memory, accepts
binary data as input and processes data according to instructions
(program), and provides result as output.

Figure 1.2: Microprocessor simplified block diagram

Figure 1.3: Basic connections between the microprocessor and external memory

Comparison of a Microprocessor and a Microcontroller


Microprocessors Microcontrollers
1 It is only a general-purpose computer It is a microcomputer itself
2 Memory, I/O ports, timers, interrupts are All are integrated inside the microcontroller chip
not available inside the chip
3 It must have many additional digital It can function as a microc omputer without any
components to perform its operation additional components.
4 The systems become bulkier and It makes the system simple, economic and compact
expensive.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 15
5 It not capable for handling Boolean It effective handling Boolean functions
functions
6 It has higher accessed time required It has low accessed time
7 Have very few pins that are programmable Most of its pins are programmable
8 Cost of the entire system increases Cost of the entire system is low
9 Have very few numbers of bit Have many bits handling instructions
handling instructions.
10 It widely Used in modern PC and laptops This is widely in control systems e.g.
e.g., INTEL 8086, INTEL Pentium series INTEL8051,89960, PIC16F877
Table 1.0: Summery of comparison of a Microprocessor and a Microcontroller

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 16
Another table of comparison is here:

Table 1.1: Summery of comparison of a Microprocessor and a Microcontroller

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 17

Figure 1.3: Difference between a Microprocessor and Microcontroller

Types of Microcontrollers
Microcontrollers are divided into various categories based on bits, memory/device, family,
instruction sets, and memory architecture. So the microcontroller can be classified according
to their characteristics as shown in graph below:

Figure 1.4: Types of microcontroller

Bit
Based on bit configuration, the microcontroller is further divided into three categories.
i) The 8-Bit Microcontroller
This type of microcontroller is used to execute arithmetic and logical operations like
addition, subtraction, multiplication division, etc. For example, Intel 8031 and 8051 are
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 18
8 bits microcontroller.
ii) 16-bit microcontroller
This type of microcontroller is used to perform arithmetic and logical operations where
higher accuracy and performance is required. For example, Intel 8096 is a 16-bit
microcontroller.
iii) The 32-Bit Microcontroller
This type of microcontroller is generally used in automatically controlled appliances
like automatic operational machines, medical appliances, etc.
Memory/Device
Based on the memory configuration, the microcontroller is further divided into two categories.
i) External memory microcontroller − this type of microcontroller is designed in such a way
that they do not have a program memory on the chip. Hence, it is named as external memory
microcontroller. For example: Intel 8031 microcontroller.
ii) Embedded memory microcontroller − This type of microcontroller is designed in such a
way that the microcontroller has all programs and data memory, counters and timers,
interrupts, I/O ports are embedded on the chip. For example: Intel 8051 microcontroller.

Instruction Set
Based on the instruction set configuration, the microcontroller is further divided into two
categories.
i) CISC − CISC stands for complex instruction set computer.
- It was first developed by Intel.
- It contains large number of complex instructions.
- In these instructions are not register based.
- Instructions cannot be completed in one machine cycle.
- Data transfer is from memory to memory.
- Micro programmed control unit is found in CISC.
- Also, they have variable instruction formats.
ii) RISC − RISC stands for Reduced Instruction Set Computers.
- It reduces the operational time by shortening the clock cycle per instruction.
- It is a type of microprocessor that has a limited number of instructions.
- They can execute their instructions very fast because instructions are very small
and simple.
- RISC chips require fewer transistors which make them cheaper to design and
produce.
- In RISC, the instruction set contains simple and basic instructions from which more
complex instruction can be produced.
- Most instructions complete in one cycle, which allows the processor to handle many
instructions at same time.
- In these instructions are register based and data transfer takes place from register
toregister.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 19

Difference between CISC and RISC summarized


Architectural Reduced Instruction Set
Complex Instruction Set Computer
Characteristics Computer (RISC)
(CISC)
Instruction size and Large set of instructions with Small set of instructions with
format variable formats (16-64 bits per fixed format (32 bit).
instruction).
Data transfer Memory to memory. Register to register.
Most micro coded using control
Mostly hardwired without control
CPU control memory(ROM) but modern CISC use
memory.
hardwiredcontrol.
Instruction type Not register based instructions. Register based instructions.
Memory access More memory access. Less memory access.
Clocks Includes multi-clocks. Includes single clock.
Instructions are reduced and
Instruction nature Instructions are complex.
simple.
Table 1.1: Difference between CISC and RISC summarized

Memory Architecture [start here next time]


i) Von Neumann Microcontroller Architecture
Von Neumann Architecture or Princeton Architecture is a Computer Architecture, where
the Program i.e., the Instructions and the Data are stored in a single memory.

Since the Instruction Memory and the Data Memory are the same, the Processor or CPU
cannot access both Instructions and Data at the same time as they use a single bus.

The Von Neumann architecture developed for the ENIAC (Electronic Numerical Integrator
And Computer) uses the same memory and data paths for both program and data
storage. ENIAC was the world's first general-purpose computer. ENIAC was designed and
built for the United States Army to calculate artillery firing tables.

Figure 1.5: Von Neumann Microcontroller Architecture


This type of architecture has severe limitations to the performance of the system as it
creates a bottleneck while accessing the memory.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 20

ii) Harvard Microcontroller Architecture


Harvard Architecture, in contrast to Von Neumann Architecture, uses separate memory for
Instruction (Program) and Data. Since the Instruction Memory and Data Memory are separate
in a Harvard Architecture, their signal paths i.e., buses are also different and hence, the CPU
can access both Instructions and Data at the same time.

Both the concepts are similar except the way they access memories. The idea behind the
Harvard architecture is to split the memory into two parts – one for data and another for
programs.

Real world computer designs are actually based on modified Harvard architecture and are
commonly used in microcontrollers and DSP (Digital Signal Processing).
Almost all Microcontrollers, including 8051 Microcontroller implement Harvard
Architecture.

Figure 1.6: Von Harvard Microcontroller Architecture


Microprocessors widely use von Neumann architecture, while microcontrollers use Harvard
architecture. Why?

Microprocessors use von Neumann architecture, because (except for the boot code) they usually
load programs off of an external device such as a hard drive, SSD, or USB stick and execute them
out of RAM, same as where their data is stored. Harvard architecture would have been awkward in
this situation, as it would have meant two separate RAM memories, one for code and one for data.

Microcontrollers usually have their programs burned into flash memory (and earlier, ROM,
EPROM, or EEPROM), while the data is in separate RAM memory. So, this lead to them naturally
gravitating to a Harvard architecture because of the distinct memories (and the separate busses
meant faster access).

Advantages of Microcontrollers
The main advantages of microcontrollers are given.
- As the higher integration inside microcontroller reduces cost and size of the system.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 21
- Usage of a microcontroller is simple, easy to troubleshoot and system maintaining.
- Most of the pins are programmable by the user for performing different functions.
- Easily interface additional RAM, ROM, I/O ports.
- Low time required for performing operations.

Disadvantages of Microcontrollers
- Microcontrollers have got more complex architecture than that of microprocessors.
- Only perform a limited number of executions simultaneously.
- Mostly used in micro-equipment.
- Cannot interface high power devices directly.

Applications
You can find microcontrollers in all kinds of electronic devices these days. Any device that
measures, stores, controls, calculates, or displays information must have a microcontroller chip
inside.

The largest single use for microcontrollers is in the automobile industry (microcontrollers widely
used for controlling engines and power controls in automobiles). You can also find
microcontrollers inside keyboards, mouse, modems, printers, and other peripherals.

In test equipment, microcontrollers make it easy to add features such as the ability to store
measurements, to create and store user routines, and to display messages and waveforms.
Consumer products that use microcontrollers include digital camcorders, optical players,
LCD/LED display units, etc. And these are just a few examples.
Some basic applications of a microcontroller are given below.
- Used in biomedical instruments.
- Widely used in communication systems.
- Used as a peripheral controller in PC.
- Used in robotics.
- Used in automobile fields.
- Light sensing and controlling devices like LED.
- Temperature sensing and controlling devices like microwave oven, chimneys.
- Fire detection and safety devices like Fire alarm.
- Measuring devices like Volt Meter.

What types of microcontrollers are there? Nowadays


 8051 – The ‘8051 core’ was one of the most popular standards in 8-bit microcontrollers ever with
large derivatives, extra features & vast community support. Developed by Intel in the 1980s, it
still seems to be the instruction set they love to teach you in college & used till date in many
applications.
 PIC microcontrollers are a family of specialized microcontroller chips produced byMicrochip
Technology in Chandler, Arizona. The acronym PIC stands for "peripheral interface
controller," although that term is rarely used nowadays. This is the classic microcontrollers. It is
Very simple, very proven, but it lacks many of the features those other manufacturers are building
into their chips.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 22
 AVR – AVR stands for Advanced Virtual RISC micro-controller. This is basically a direct
competitor of PICs. They do everything a PIC does, but in my opinion, better, faster, cheaper,
simpler, & with wide community support.
 MSP – examples is MSP430. These are very good microcontrollers by Texas Instruments (TI),
not as beefy as AVR or PICs. However, they are popular for low-power applications. Imagine
running a complete system on single A battery for 5 years. This is in the realm of nano-amp (One
thousand millionth) current consumption. Awesome!
 ARM – An ARM processor is one of a family of CPUs based on the RISC (reduced instruction
set computer) architecture developed by Advanced RISC Machines (ARM). They are taking over
the world but can be really intimidating if you’ve never played with any microcontrollers before.
CHOICE OF THE MICROCONTROLLER TO USE
As the ‘brain’ of an embedded system, the processor has a big effect on the system’s overall success
or failure. Selection of the right device is therefore extremely important. How following are crucial
factors worth considering:
Steps to selecting a microcontroller
Selecting the right microcontroller for a product can be a daunting task. Not only are there a number
of technical features to consider, there are also business case issues such as cost and lead- times that
can cripple a project.

At the start of a project there is a great temptation to jump in and start selecting a microcontroller
before the details of the system has been hashed out. This is of course a bad idea. Before any thought
is given to the microcontroller, the hardware and software engineers should work out the high levels
of the system, block diagram and flowchart them and only then is there enough information to start
making a rational decision on microcontroller selection. When that point is reached, there are 10 easy
steps that can be followed to ensure that the right choice is made.

Step 1: Make a list of required hardware interfaces


Using the general hardware block diagram, make a list of all the external interfaces that the
microcontroller will need to support. There are two general types of interfaces that need to be listed.
The first are communication interfaces. These are peripherals such as USB, I2C, SPI, UART, and
so on. Make a special note if the application requires USB or some form of Ethernet. These interfaces
greatly affect how much program space the microcontroller will need to support. The second type of
interface is digital inputs and outputs, analog to digital inputs, PWM’s, etc. These two interface types
will dictate the number of pins that will be required by the microcontroller. Figure 1 shows a generic
example of a block diagram with the i/o requirements listed.

Step 2: Examine the software architecture


The software architecture and requirements can greatly affect the selection of a microcontroller. How
heavy or how light the processing requirements will determine whether you go with an 80 MHz DSP
or an 8 MHz 8051. Just like with the hardware, make notes of any requirements that will be important.

Step 3: Select the architecture


Using the information from steps 1 and 2 an engineer should be able to start getting an idea of the

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 23
architecture that will be needed. Can the application get by with eight-bit architectures? How about
16 bits? Does it require a 32-bit ARM core? Between the application and the required software
algorithms these questions will start to converge on a solution. Do not forget to keep in mind possible
future requirements and feature creep. Just because you could currently get by with an 8 bit
microcontroller doesn’t mean you shouldn’t consider a 16 bit microcontroller for future features or
even for ease of use.

Step 4: Identify Memory Needs


Flash and RAM are two very critical components of any microcontrollers. Making sure that you do
not run out of program space or variable space is undoubtedly of highest priority. It is far easier to
select a part with too much of these features than not enough. Getting to the end of a design and
discovering that you need 110% or that features need to be cut just is not going to fly.

Step 5: Start searching for microcontrollers


Now that there is a better idea of what the required features of the microcontroller will be the search
can begin! One place that can be a good place to start is with a microcontroller supplier.

Step 6: Examine Costs and Power Constraints


At this point the selection process has revealed a number of potential candidates. This is a great time
to examine the power requirements and cost of the part. If the device will be powered from a battery
and mobile, then making sure the parts are low-power is absolutely precarious. If it does not meet
power requirements then keep weeding the list down until you have a select few. Do not forget to
examine the piece price of the processor either.

Step 7: Check part availability


With the list of potential parts in hand, now is a good time to start checking on how available the
part is. Some of the things to keep in mind are what the lead times for the part? Are they kept in stock
at multiple distributors or is there 6 – 12-week lead time? What are your requirements for
availability? You don’t want to get stuck with a large order and have to wait three months to be able
to fill it. Then there is a question of how new the part is and whether it will be around for the duration
of your product life cycle. If your product will be around for 10 years then you need to find a part
that the manufacturer guarantees will still be built in 10 years.

Step 8: Select a development kit


One of the best parts of selecting a new microcontroller is finding a development kit to play with and
learn the inner working of the controller. Once an engineer has settled their heart on the part they
want to use they should research what development kits are available.

Step 9: Investigate compilers and tools


The selection of the development kit nearly solidifies the choice of microcontroller. The last
consideration is to examine the compiler and tools that are available. Most microcontrollers have a
number of choices for compilers, example code and debugging tools. It is important to make sure
that all the necessary tools are available for the part. Without the right tools the development process
could become tedious and expensive.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 24

Step 10: Start Experimenting


Even with the selection a microcontroller nothing is set in stone. Usually, the development kit arrives
long before the first prototyped hardware. Take advantage by building up test circuits and interfacing
them to the microcontroller. Choose high risk parts and get them working on the development kit. It
may be that you discover the part you thought would work great has some unforeseen issue that
would force a different microcontroller to be selected. In any event, early experimentation will ensure
that you made the right choice and that if a change is necessary, the impact will be minimal!

Frequently Used Terms


Before we concentrate on microcontrollers, it is important terms to understand the following
terms you will frequently encounter in the embedded systems field.

Microprocessor
It is a multipurpose, programmable, clock-driven, register-based electronic device that reads binary
instructions from memory, accepts binary data as input and processes data according to instructions
(program), and provides result as output.

Microcontroller
It is a small computer on a single integrated circuit (IC) containing a processor core, memory, and
programmable input/output ports.
A microcontroller already contains all components which allow it to operate as stand-alone, and it
has been designed in particular for monitoring and/or control tasks.

Mixed-Signal Controller
This is a microcontroller which can process both digital and analog signals.

Embedded System
In embedded systems, the control unit is integrated into the system like in a cell phone, where the
controller is included in the device.

Real-Time System
Controllers are frequently used in real-time systems where the reaction to an event has to occur
within a specified time as found in aerospace, railroad, or automotive areas,

Digital Signal Processor (DSP)


Digital signal processors are used to process signals like in telecommunications where a mobile
phone contain a DSP and are designed for fast addition and multiplication.

Embedded processor
Is simply a computing device placed inside a system it controls. A processor embedded into a system
handles all the computation and logical operation of a computer. The embedded processor also
handles such tasks as storing and retrieving data from memory, and processing data from any inputs
or outputs. Embedded processors often work as part of a computer system, alongside memory and
I/O devices.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 25

The primary difference between microcontrollers and embedded processors is makeup and
integration. Embedded processors, while in a sense "controlling" the system they are a part of, require
external resources such as RAM and registers in order to do so. A processor is not a control"system."
Microcontrollers, on the other hand, contain everything required to control a system in a single chip.
A microcontroller might contain an embedded processor as part of its makeup, but also combines
other computer parts, such as memory and signal registers, in a single chip.

Microcontrollers are "embedded" inside some other device (often a consumer product) so that they
can control the features or actions of the product. Another name for a microcontroller, therefore, is
"embedded controller."

Exercises
Exercise 1.1 What is the difference between a microcontroller and a microprocessor?
Exercise 1.2 Why do microcontrollers exist at all? Why not just use a normal processor and add all
necessary peripherals externally?
Exercise 1.3 What do you believe are the three biggest fields of application for
microcontrollers? Discuss you answers with other students.
Exercise 1.4 Name the basic components of a microcontroller. For each component, give an
example where it would be useful.
Exercise 1.5 What is an embedded system? What is a real-time system? Are these terms
synonyms? Is one a subset of the other? Why or why not?
Exercise 1.7 Why are there so many microcontrollers? Wouldn’t it be easier for both manufacturers
and consumers to have just a few types?

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 26
TOPIC TWO

MICROCONTROLLER FAMILIES
A microcontroller family or a CPU family (also microprocessor family) is a group of
microcontrollers, microprocessors, or component chips that make up one, developed by a specific
manufacturer that share the same general architecture and feature set.

Within a specific family, chips may be further classified according to their model which may have
different capabilities, clock speeds, and applications.

Models may be further divided into stepping which have minor refinements and tweaks (a sharp
twist or pull) in order to correct and enhance the stability and reliability of the model.

While families are a good way of classifying chip according to architecture, historically, there has
been more than a few instances where developers introduce significant architectural changes to the
same family such as XD, NX, and various SSE extensions in the case of Intel.

NX stands for No eXecute and XD stands for eXecute Disable

SSE is a process or technology that enables single instruction multiple data. Older processors only
process a single data element per instruction. SSE enables the instruction to handle multiple
data elements.

On occasion, a manufacturer may decide to group a number of smaller microprocessor families into
a larger extended family which represents a large group of chips that share a common theme and
possibly root ISA.

ISA (Industry Standard Architecture) is a standard bus (computer interconnection) architecture that
was associated with the IBM AT motherboard.

ISA was one of the first expansion buses for PCs. Providing the hardware interface for connecting
peripheral devices in PCs, ISA accepted cards for sound, display, hard drives and other devices.

Below is a list of microprocessor families organized by company, alphabetized


 Adapteva  MediaTek
 Ambric  MIPS Technologies
 AMD (Advanced Micro Devices)  MOS Technology
 Atmel  Motorola
 Broadcom  National Semiconductor
 Centaur Technology  NexGen
 Clearspeed  Phytium
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 27
 Cray Inc.  Qualcomm
 Cypress Semiconductor  Quantum Effect Devices
 Cyrix  Rapport
 Digital Equipment Corporation  Ross Technology
 Exponential Technology  SGI
 Fujitsu  Sun Microsystems
 General Instrument  Sunway
 HAL Computer Systems  Tesla (czech)
 Hitachi  Transmeta
 HP  Western Design Center
 IBM  Western Digital
 Intel  Zilog

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 28

Table 2.0: List of microprocessor families

Recall in our previous discussion on types of microcontrollers, we found that microcontrollers can
be divided into various categories based on bits, memory/device, family, instruction sets, and
memory architecture. Here our focus is on family.

Microcontroller families basically refer to common name of architecture. It is important to note


that microcontroller belonging the same family share certain features and compatibility.

Fig. 2.0: Types of microcontrollers


For example, in the 8051 family, they are the 8052 and the 8031. The 8052 has all the standard
features of the 8051 as well as an extra 128 bytes of RAM and an extra timer. For example, AVR
(Advanced Virtual RISC) is a family microcontrollers chips that include:
 Atmega-8
 Atmega-16
 Atmega-32
 Atmega-128
 Atmega-328
 AT90S1200

THE 8051 MICROCONTROLLER FAMILY MEMBERS


The first microprocessor 4004 was invented by Intel Corporation. Intel 8085 and 8086
microprocessors were also invented by Intel.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 29

History of 8051 and Key Developments


Intel Corporation fabricated the 8051microcontroller, an 8-bit microcontroller, which was referred
as MCS-51 in 1981.

This microcontroller was also referred as “system on a chip” because it has 128 bytes of RAM,
4Kbytes of ROM, 2 Timers, 1 Serial port, and four ports on a single chip.

The CPU can work for only 8bits of data at a time because 8051 is an 8-bit processor. In case the
data is larger than 8 bits then it has to be broken into parts so that the CPU can process conveniently.

Most manufacturers have put 4Kbytes of ROM even though the quantity of ROM can be exceeded
up to 64 K bytes.

Intel permitted other manufacturers to fabricate different versions of 8051 but with the limitation that
code compatibility should be maintained. This has added advantage that if the program is written
then it can be used for any version of 8051 despite of manufacturer.

When it became widely popular, Intel allowed other manufacturers to make and market different
flavors of 8051 with its code compatible with 8051. It means that if you write your program for one
flavor of 8051, it will run on other flavors too, regardless of the manufacturer. This has led to several
versions with different speeds and amounts of on-chip RAM.
Main Features of the 8051(summery)
Features Quality
ROM 4K bytes
RAM (Data Memory) 128 bytes
Timer 2 (16-bit Timer/Counter)
I/O pins 32
Serial Port 1 (Using UART makes it simpler for serial communication)
Interrupt sources 6
Input/output Pins 4 Ports of 8 bits each on a single chip
ALU 8 – bit ALU (Arithmetic Logic Unit)
Speed execute 1 million one-cycle instructions per second with a clock
frequency of 12MHz.
Data size 8 bits
Address lines 16 bits. Therefore, memory capacity is 216 = 64 KB
Architecture Harvard Memory Architecture – It has 16-bit Address bus (each
of RAM and ROM) and 8-bit Data Bus.
NB ROM amount indicates on-chip program space
Table 2.1: Features of the 8051 microcontrollers
This microcontroller is also called as “System on a chip” because it has all the features on a single

As years passed by, the quality of technology surpassed the expectation of the greatest minds, with
gadgets becoming smaller, sleeker (smooth and glossy) and more efficient. Microcontrollers were
seen as the answer to the requirements was raised in advanced electronics. This is the reason why

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 30

manufacturers have now focused their production around the following main developmental aspects:
i. Ease-of-use
ii. Market availability
iii. Less power usage
iv. Smaller processing power
v. More integrated features like RF and USB
vi. Smaller form factors

Block Diagram of 8051 Microcontroller


The following illustration shows the block diagram of an 8051 microcontroller –

Figure 2.1: 8051 Microcontroller Block Diagram


CPU (Central Processor Unit):
As we know that the CPU is the brain of any processing device of the microcontroller. It monitors
and controls all operations that are performed on the Microcontroller units.

The User has no controlover the work of the CPU directly. It reads program written in ROM memory
and executes them and do the expected task of that application.

Interrupts:
As its name suggests, Interrupt is a subroutine call that interrupts of the microcontrollers main
operations or work and causes it to execute any other program, which is more important at the time
of operation.

The feature of Interrupt is very useful as it helps in case of emergency operations. An Interrupts
gives us a mechanism to put on hold the ongoing operations, execute a subroutine and then again
resumes to another type of operations.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 31

The Microcontroller 8051 can be configured in such a way that it temporarily terminates or pause
the main program at the occurrence of interrupts. When a subroutine is completed, then the execution
of main program starts.

Interrupts are the events that temporarily suspend the main program, pass the control to the external
sources and execute their task. It then passes the control to the main program where it had left off.
These five sources of interrupts in 8051are:

1. Timer 0 overflow interrupt- TF0


2. Timer 1 overflow interrupt- TF1
3. External hardware interrupt- INT0
4. External hardware interrupt- INT1
5. Serial communication interrupt- RI/TI

Each interrupt can be enabled or disabled by setting bits of the IE register and the whole interrupt
system can be disabled by clearing the EA bit of the same register.

What is the difference between vector and non-vector interrupt (Reference – Intel 8085)?
Vector interrupt: - In this type of the address of the service routine is hard-wired. the CPU actually
knows the address of the Interrupt Service Routine in advance. The interrupt address is known to the
processor. The interrupting device directs the processor to the appropriate interrupt service routine. For
example: RST7.5, RST6.5, RST5.5, and TRAP.

Non-Vector interrupt: - In this type of interrupt the address of the service routine needs to be supplied
externally by the device. The interrupt address is not known to the processor so, the interrupt address
needs to be sent externally by the device to perform interrupts. For example: INTR.

Maskable interrupt (Can be delayed or Rejected) − In this type of interrupt, we can disable the interrupt
by writing some instructions into the program. For example: RST7.5, RST6.5, RST5.5.

Non-Maskable interrupt (Cannot be delayed or Rejected) − In this type of interrupt, we cannot


disable the interrupt by writing some instructions into the program. For example: TRAP.

Memory:
Microcontroller requires a program which is a collection of instructions. This program tells
microcontroller to do specific tasks. These programs require a memory on which these can be saved
and read by Microcontroller to perform specific operations of a particular task.

The storage space which is employed to momentarily store data for functioning is acknowledged as
Data Memory and we employ Random Access Memory or RAM for this principal reason.

Microcontroller 8051 contains code memory or program memory 4K so that is has 4KB Rom and
it also comprise of data memory (RAM) of 128 bytes.

BUS:

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 32

Basically, Bus is a collection of wires which work as a communication channel or medium for
transfer of Data. These buses consist of 8, 16 or more wires of the microcontroller. Thus, these can
carry 8 bits, 16 bits simultaneously. Hire two types of buses that are shown in below
1. Address Bus
2. Data Bus
Address Bus: Microcontroller 8051 has a 16-bit address bus for transferring the data. It is used to
address memory locations and to transfer the address from CPU to Memory of the microcontroller.
It has four addressing modes that are
 Immediate addressing modes.
 Bank address (or) Register addressing mode.
 Direct Addressing mode.
 Register indirect addressing mode.
Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of particular
applications.

Oscillator:
An electronic circuit or electronic device that is used to generate periodically oscillating electronic
signal is called as an electronic oscillator

The microcontroller being a digital circuit piece of equipment, it requires clock pulses for its
operation of microcontroller applications. For this purpose, microcontroller 8051 has an on-chip
oscillator which works as a clock source for Central Processing Unit of the microcontroller. The
output pulses of oscillator are stable. Therefore, it enables synchronized work of all parts of the 8051
Microcontroller.

Input/output Port
Normally microcontroller is used in embedded systems to control the operation of machines.
Therefore, to connect it to other machines, devices or peripherals, we require I/O interfacing ports in
the microcontroller interface. For this purpose microcontroller 8051 has 4 input, output ports to
connect it to the other peripherals

Timers/Counters
8051 microcontrolles has two 16-bit timers and counters. These counters are again divided into an 8-
bit register. The timers are used for measurement of intervals to determine the pulse width of pulses.
This will be discussed further later.

System Clock (or Internal Clock)


In this mode, the timer is incremented with every tick of the system clock. This is the default mode.
Note that the term “internal” only refers to the fact that this is the clocking source the whole
controller uses. The oscillator responsible for it may well be external.

Prescaler
A prescaler is an electronic counting circuit used to reduce a high frequency electrical signal to a lower
frequency by integer division.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 33

Itis a kind of slow down for Timer incrementing, instead of incrementing each clock cycle it can be
adjusted to every 2nd, 4th, 8th. etc

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Pag e | 34

THE PIN DIAGRAM


The pin out diagram of 8051 microcontroller consists of 40 pins. The following image shows the
8051 Microcontroller Pin Diagram with respect to a 40-pin Dual In-line Package (DIP).

Figure 2.2: 8051 Microcontroller pin out diagram


 Pins 1 to 8 − These pins are known as Port 1. Different from other ports. This port does not
serve any other functions. It is internally pulled up, bi-directional I/O port.
 Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.
 Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD, etc.
 Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system
clock.
 Pin 20 − This pin provides the power supply to the circuit.
 Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address
bus signals are also multiplexed using this port.
 Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a
signal from the external program memory.
 Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable
the external memory interfacing.
 Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex
the address-data signal of port.
 Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address
and data bus signals are multiplexed using this port.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019

COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 35
 Pin 40 − This pin is used to provide power supply to the circuit. It is termed as Vcc is the
chief power supply. By and large it is +5V DC.

The 8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or
output. Hence, total 32 input/output pins allow the microcontroller to be connected with the
peripheral devices.
 Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the
logic state.
* Input/output (I/O) pin − All the circuits within the microcontroller must be
connected to one of its pins except P0 port because it does not have pull-up resistors
built-in.
* Input pin − Logic 1 is applied to a bit of the P register. The output FE transistor is
turned off and the other pin remains connected to the power supply voltage over a
pull-up resistor of high resistance.
 Port 0 − The P0 (zero) port is characterized by two functions −
* When the external memory is used then the lower address byte (addresses A0A7) is
applied on it, else all bits of this port are configured as input/output.
* When P0 port is configured as an output then other ports consisting of pins with built-
in pull-up resistor connected by its end to 5V power supply, the pins of this port have
this resistor left out.
Input Configuration
If any pin of this port is configured as an input, then it acts as if it “floats”, i.e. the input has
unlimited input resistance and in-determined potential.

Output Configuration
When the pin is configured as an output, then it acts as an “open drain”. By applying logic 0 to a
port bit, the appropriate pin will be connected to ground (0V), and applying logic 1, the external
output will keep on “floating”.
In order to apply logic 1 (5V) on this output pin, it is necessary to build an external pull-up resistor.
Port 1
P1 is a true I/O port as it does not have any alternative functions as in P0, but this port can be
configured as general I/O only. It has a built-in pull-up resistor and is completely compatible with
TTL circuits.
Port 2
P2 is similar to P0 when the external memory is used. Pins of this port occupy addresses intended
for the external memory chip. This port can be used for higher address byte with addresses A8-
A15. When no memory is added then this port can be used as a general input/output port similar to
Port 1.
Port 3
In this port, functions are similar to other ports except that the logic 1 must be applied to appropriate
bit of the P3 register.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 36
Timers and Counters in 8051 Microcontroller
There are many applications of microcontroller where we want to count external events such as generation
of internal time delays between computer work and frequency of the pulse trains. This type of task is
generally done by software techniques, but these software techniques will not give the exact result rather
more important functions are not done.

To solve these problems timers and counters in the micro-controllers are best options for simple
applications. In 8051 microcontroller, timers and counters are used as interrupts.

Timers of 8051Microcontroller and their Registers


8051 Microcontroller has two 16-bit counters/timers: timer 0 and timer1. These timers work as a counter
also. It means these timers perform dual function. When they work as a timer to generate a time delay or as
counter to count events happening outside the microcontroller. Both timers are 16 bits wide.

We know that 8051 microcontrollers have an 8-bit microcontroller. So, it can process 8-bit data at a time.
So, these registers are divided into two parts Higher 8-bits (TH) and Lower 8-bits (TL). The higher byte is
stored in TH register and the lower byte is stored in TL register.

In short, we can say that, timer is a special type of clock which is used to measure time
intervals. Whereas Counter is a device that able to count the number of times a particular event or
process occurred, with respect to a clock signal. Counters can be easily implemented with the help of flip-
flop. The 8051 microcontroller has 2 timers/counters called T0 and T1.

Clock
Every Timer needs a clock to work, and 8051 provides it from an external crystal which is the main
clock source for Timer. The internal circuitry in the 8051 microcontrollers provides a clock source
to the timer which is 1/12th of the frequency of crystal attached to the microcontroller, also called
as Machine cycle frequency.

Figure 2.3: 8051 Microcontroller clock source for timer


For example, suppose we have crystal frequency of 11.0592 MHz then microcontroller will
provide 1/12th. That is:
Timer clock frequency = (Xtal Osc.frequency)/12 = (11.0592 MHz)/12 = 921.6 KHz
Period T= 1/(921.6 KHz)=1.085 μS

Timer
8051 has two timers Timer0 (T0) and Timer1 (T1), both are 16-bit wide. Since 8051 has 8-bit
architecture, each of these is accessed by two separate 8-bit registers as shown in the figure below.
These registers are used to load timer count.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 37
Timer 0 Registers
Timer 0 register is 16 bits register and accessed as low byte and high byte. The TL0 is referred as a low byte
register and the TH0 is referred as a high byte register. These registers can be also accessed like any other
registers. Example, the instruction MOV TL0, #5H moves the value into the low-byte of Timer 0.

Timer 0 Register

Timer1 Registers
Timer1 is also 16 bits register and is divided into two 8-bit register, referred to as TL1 (lower timer 1
register) and TH1 (Higher timer 1 register). The low byte register is referred as a TL0 and the high byte
register is referred as TH0.

These registers can be accessed like any other registers. Example, the instruction MOV TL1, #5H moves
the value into the low-byte of Timer1.

Timer 1 Register
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 38

During counter operation


 When these timer and counter act as a counter they always count Up. It starts counting from its initial
value 0000 H and count up to FFFF H (max count value). Every time it will start counting it
incremented by one.

 After reaching its final value (FFFF H) if it counts again. It will return back to its initial value (0000
H). This condition is called Roll Over Condition.

 Maximum count rate of counter is 1/24 of the oscillator frequency.


 A counter can use an external signal to count the pulses.

TMODE & TCON Registers


Timers and counters in 8051 microcontrollers contain two special function registers: TMOD (Timer Mode
Register) and TCON (Timer Control Register), which are used for selecting a mode of operation and
controlling purpose.

What is the difference between TCON and TMOD?


Counters and Timers in 8051 microcontrollers contain two special function registers: TMOD (Timer Mode
Register) and TCON (Timer Control Register), which are used for activating and configuring timers and
counters.

TMODE (Timer Mode Control) Register:


TMODE register is used for selecting timer or counter mode of operation. It is an 8-bit register which is
used by both timers 0 and 1 to set the various timer operation modes. The lower 4 bits are set for Timer 0
and the upper four bits are set for Timers1. In both cases, the upper 2 bits to specify the operation and the
lower 2 bits are used to set the timer mode.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 39

TMODE Register
Gate: Bit D7 and D3 is allotted for gate. This bit is used to starting and stopping the timer. Timers can be
started by software means and hardware means also. If the gate bit is set to ‘0’ this is the software way of
starting and stopping the timer by an external source. If this bit is set to ‘1’ this is the software way of
starting and stopping the timer.

C/T: Bit D6 and D2 is allotted for counter / Timer (C/T). This bit is used to decide whether a timer is used
as a timer to generate time delay or used as a counter to work as a event counter. If this bit is set to be “0”
then it is used as a timer to generate time delay and if it is “1” then it is used as a counter to external count
event.

Mode selection Bits (M0 and M1): Bit D0, D1 and D4, D5 is allotted for M0 and M1 these are Mode
selection Bits. The combination of these bits is used to select the timer mode.

Modes of Operation

Mode 1 (16-Bit Timer Mode)


The Timer mode "1" is a 16-bit timer and is a commonly used mode. It functions in the same way as 13-
bit mode except that all 16 bits are used. TLx is incremented starting from 0 to a maximum 255. Once the
value 255 is reached, TLx resets to 0 and then THx is incremented by 1.

It enables counting from 0000 to FFFFH and loaded into the timer’s registers TH and TL. The timer must
be started after TH and TL are loaded with a 16-bit initial value. This can be done with the help of
instructions “SETB TR0” for timer 0 and “SETB TR1” for timer 1.

When rolls over condition will occurs It means it count from FFFF to 0000H, the TF (timer flag) flag bit is
set to be high. If this roll over condition may occurs, we have option to stop the timer with the help of
instructions “CLR TR0“for timer 0 and CLR TR1 for timer.
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 40
After the timer reaches its limit and rolls over condition occurs, again the process get repeat, the registers
TH and TL must be reloaded with the original value and TF must be reset to 0.

Mode0 (13-Bit Timer Mode)


The operation of Mode 0 is exactly same like mode 1 except that it has a 13-bit timer instead of 16-bit in
mode 1. The 13-bit counter can count values from 0000 to 1FFFH and loaded into the timer’s registers TH
and TL. Therefore, every time timer is incremented by one, when the timer reaches its maximum value
1FFH, it rolls over to 0000, and TF (timer flag) flag bit is set to be high.

Mode 2 (8-bit Auto Reload mode)


This mode is an 8-bit auto reload mode. That allows the timer to load values of 00 to FFH into the timer’s
register TH. After TH register is loaded with 8-bit value, the 8051 gives a copy of it to TL register. Then
the timer must be started by using the instruction “SETB TR0” for timer 0 and “SETB TR1” for timer1. like
mode 1.

After timer is started, it starts to count up by incrementing the value of TL register. It counts up until it
reaches its final value of FFH. After reaching to its final value FFH if it again counts and reaches from FFH
to 00H. This condition is called rolls over condition. It sets high the TF (timer flag). If using timer 0, TF0
goes high; if using TF1 then TF1 is raised.

When Tl register rolls over from FFH to 00 and TF is set to 1, TL is reloaded automatically with the original
value kept by the TH register. To repeat the process, we must clear TF register and without any need by the
programmer to reload the original value. This makes mode 2 auto reload, whereas mode 1 in which
programmer has to reload TH and TL.

Mode 3 (Split Timer Mode)


Timer mode "3" is known as split-timer mode. When Timer 0 is placed in mode 3, it becomes two separate
8-bit timers. Timer 0 is TL0 and Timer 1 is TH0. Both the timers count from 0 to 255 and in case of overflow,
reset back to 0. All the bits that are of Timer 1 will now be tied to TH0.

When Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be set in modes 0, 1 or 2, but it
cannot be started/stopped as the bits that do that are now linked to TH0. The real timer 1 will be incremented
with every machine cycle.

Placing timer 1 in mode 3 causes it to stop counting; the control bit TR1 and the timer 1 flag TF1 are then
used by timer0.

TCON (Timer Control Register) Register


TCON is a register used to control operations of counters and timers in 8051 microcontrollers. It is an 8-bit
register. The upper four bits are used for timers and counters operations and lower four bits are used for
interrupts.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 41

TCON Register

TF1: The bit 7 is allotted for Timer1 over flow flag bit. This bit is Set to 1 whenever timer rolls from all 1s
to 0. And this bit is reset or cleared When the processor executes interrupt service routine (ISR) Located at
program address 001Bh.

TR1: The bit 6 is allotted as a Timer 1 run control bit. This bit is Set to 1 by programmer to enable timer
to count; It is reset or cleared to 0 by program to halt timer.

TF0: The bit 5 is allotted as a Timer 0 over flow flag. Same as TF1 (Timer1 over flow flag bit).

TR0: The bit 4 is allotted as a Timer 0 run control bit. Same as TR1 (Timer 1 run control bit).

IE1: The bit 3 is allotted as an External interrupt 1 Edge flag. It is not used in timer operations.

IT1: The bit 2 is allotted as a External interrupt1 signal type control bit. This bit is Set to be 1 by program
to Enable the external interrupt 1 to be triggered by a falling edge signal. This bit is Set to be 0 by program
to enable a low-level signal on external interrupt1 to generate an interrupt.

IE0: The bit 1 is allotted as an External interrupt 0 Edge flag. It is not used in to timer operations.

IT0: The bit 0 is allotted as an External interrupt 0 signal type control bit. Perform same function as IT1.

FAQ’S (Frequently asked questions)


What is difference between timer and counter in 8051?
8051 Microcontroller has two 16-bit counters/timers: timer 0 and timer1.This timer work as a counter also.
It means these timers perform dual function. When they work as a timer, they generate time delay or when
they work as counter, they count events happening outside the microcontroller. Both timers are 16 bits wide.

How many Timers & Counters connection does microcontroller have?


8051 Microcontroller has two 16-bit counters/timers: timer 0 and timer1. These timers work as a counter
also. It means these timers perform dual function. When they work as a timer to generate a time delay or as
counter to count events happening outside the microcontroller. Both timers are 16 bits wide.
We know that 8051 microcontrollers have an 8-bit microcontroller. So, it can process 8-bit data at a time.
So, these registers are divided into two parts Higher 8-bits (TH) and Lower 8-bits (TL). The higher byte is
stored in THBYregister
MR. AKETCH
and- Athe
TVET TRAINER
lower byte- KENYA COASTinNATIONAL
is stored POLYTECNIC MOMBASA. DATE 05/04/2019
TL register.
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 42

What are the modes of timers in 8051?


Timer Mode. In the timer mode, the internal machine cycles are counted.
Counter Mode.
TMOD Register.
Examples.
Mode 0 of Timer/Counter.
Mode 1 of Timer/Counter.
Mode 2 of Timer/Counter.
Mode 3 of Timer/Counter.

What are the applications of timer?


The timer is an important application in Embedded systems, it maintains the timing of an operation in sync
with a system clock or an external clock. The timer has so many applications such as measure time
generating delays, they can also be used for generating baud rates.

What is the function of mode 0 in 8051 timer?


The operation of Mode 0 is exactly same like mode 1 except that it has a 13-bit timer instead of 16-bit in
mode 1. The 13-bit counter can count values from 0000 to 1FFFH and loaded into the timer’s registers TH
and TL. Therefore, every time timer is incremented by one, when the timer reaches its maximum value
1FFH, it rolls over to 0000, and TF (timer flag) flag bit is set to be high.

Example
Let's generate a square wave of 2mSec period using an AT89C51 microcontroller with timer0 in
mode0 on P1.0 pin of port1. Assume xtal oscillator frequency of 11.0592 MHz.

Figure 2.8: square wave


As Xtal oscillator frequency is 11.0592 MHz we have machine cycle of 1.085uSec. Hence,
required count to generate delay of 1mSec. is,
Count =(1×10^-3)/(1.085×10^-6) ≈ 921
Maximum count of Mode0 is 2^13 (0 - 8191) and Timer0 count will increment from 0 – 8191. So
we need to load value which is 921 less from its maximum count i.e. 8191. Also, here in the below
program, we need additional 13 MC (machine cycles) from call to return of delay function. Hence
value needed to be loaded is,
Value=(8191-Count)+Function_MCycles+1 =7284= 0x1C74
BY MR.
So we need to AKETCH - A TVETvalue
load 0x1C74 TRAINER
in-Timer0.
KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 43
1C74 = 0001 1100 0111 0100 b, now load lower 5-bit in TL0 and next 8-bit in TH0 so here we get,
TL0 = 0001 0100 = 0x14 and TH0 = 1110 0011 = 0xE3

Other members of the 8051 family (8051 Flavors / Members)


There are two other members in the 8051 family of microcontrollers. They are the 8052 and the
8031.

8052 microcontroller
The 8052 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.

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 OK 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. Contrast 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 ports (of the 4 ports) for
I/O operations. To solve this problem, you can add external I/O to the 8031. Interfacing the 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.

Table 2.2: Comparison of 8051 Family Members


As can be seen from Table above, 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.

ADDRESSING MODES OF 8051


Addressing mode is a way to address an operand. Operand means the data we are operating upon (in
most cases source data). It can be a direct address of memory, it can be register names, it can be any
numerical data etc. Consider the following data move instruction of 8051.
MOV A, #6AH

Here the data 6A is the operand, often known as source data. When this instruction is executed, the
data 6AH is moved to accumulator A.

There areBY5MR.
different
AKETCH -ways
A TVETtoTRAINER
execute this instruction
- KENYA andPOLYTECNIC
COAST NATIONAL hence weMOMBASA.
say, weDATE
have05/04/2019
got 5 addressing
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 44
modes for 8051.
They are
1. Immediate addressing mode
2. Direct addressing mode
3. Register direct addressing mode
4. Register indirect addressing mode
5. Indexed addressing mode.

Immediate Addressing Mode


Let’s begin with an example.
MOV A, #6AH
In general we can write MOV A, #data
This addressing mode is named as “immediate” because it transfers an 8-bit data immediately to the
accumulator (destination operand).

Figure 2.9: Illustration on Immediate Addressing Mode

The figure above describes the above instruction and its execution. The opcode for MOV A, # data
is 74H. The opcode is saved in program memory at 0202 address. The data 6AH is saved in program
memory 0203. (See, any part of the program memory can be used, this is just an example) When the
opcode 74H is read, the next step taken would be to transfer whatever data at the next program
memory address (here at 0203) to accumulator A (E0H is the address of accumulator). This
instruction is of two bytes and is executed in one cycle. So after the execution of this instruction,
program counter will add 2 and move to o204 of program memory.

Note: The ‘#’ symbol before 6AH indicates that operand is a data (8 bit). If ‘#’ is not present then
BY MR. AKETCH
the hexadecimal - A TVET
number TRAINER
would - KENYA
be taken asCOAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
address.
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 45

Direct Addressing Mode


This is another way of addressing an operand. Here the address of the data (source data ) is given
as operand. Let’s take an example.
MOV A, 04H
Here 04H is the address of register 4 of register bank#0. When this instruction is executed, whatever
data is stored in register 04H is moved to accumulator. In the picture below we can see, register 04H
holds the data 1FH. So the data 1FH is moved to accumulator.

Note: We have not used ‘#’ in direct addressing mode, unlike immediate mode. If we had used ‘#’,
the data value 04H would have been transferred to accumulator instead 0f 1FH.

Figure 2.10: Illustration on Direct Addressing Mode


As shown in figure above this is a 2 byte instruction which requires 1 cycle to complete. Program
counter will increment by 2 and stand in 0204. The opcode for instruction MOV A, address is E5H.
When the instruction at 0202 is executed (E5H), accumulator is made active and ready to receive
data. Then program control goes to next address that is 0203 and look up the address of the location
(04H) where the source data (to be transferred to accumulator) is located. At 04H the control finds
the data 1F and transfers it to accumulator and hence the execution is completed.

Register Direct Addressing Mode


In this addressing mode we use the register name directly (as source operand). An example is shown
below.
MOV A, R4
At a time registers can take value from R0, R1…to R7. You may already know there are 32 such
registers. So how you access 32 registers with just 8 variables to address registers? Here comes
the use of register banks. There are 4 register banks named 0,1,2 and 3. Each bank has 8 registers
named fromBY MR.R0AKETCH - AAt
to R7. TVET TRAINER
a time - KENYA
only one COAST NATIONAL
register POLYTECNIC
bank can MOMBASA.
be selected. DATE 05/04/2019
Selection of register bank
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 46
is made possible through a Special Function Register (SFR) named Processor Status Word (PSW).
PSW is an 8 bit SFR where each bit can be programmed. Bits are designated from PSW.0 to PSW.7
Register banks are selected using PSW.3 and PSW.4 These two bits are known as register bank select
bits as they are used to select register banks. A picture below shows the PSW register and the Register
Bank Select bits with status.

Figure 2.11(a): Illustration on Register Direct Addressing Mode


So in register direct addressing mode, data is transferred to accumulator from the register (based on
which register bank is selected).
Take a look at the figure below.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 47

Figure 2.11(b): Illustration on Register Direct Addressing Mode


So we see that opcode for MOV A, R4 is EC. The opcode is stored in program memory address 0202
and when it is executed the control goes directly to R4 of the respected register bank (that is selected
in PSW). If register bank #0 is selected then the data from R4 of register bank #0 will be moved to
accumulator. (Here it is 2F stored at 04 H). 04 H is the address of R4 of register bank #0. Movement
of data (2F) in this case is shown as bold line. Now please take a look at the dotted line. Here 2F is
getting transferred to accumulator from data memory location 0C H. Now understand that 0C H is
the address location of Register 4 (R4) of register bank #1. Programmers usually get confused with
register bank selection. Also keep in mind that data at R4 of register bank #0 and register bank #1
(or even other banks) will not be same. So, wrong selection of register banks will result in undesired
output.
Also note that the instruction above is 1 byte and requires 1 cycle for complete execution. This means
using register direct addressing mode can save program memory.

Register Indirect Addressing Mode


So in this addressing mode, address of the data (source data to transfer) is given in the register
operand.
MOV A, @R0
Here the value inside R0 is considered as an address, which holds the data to be transferred to
accumulator.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 48
Example: If R0 holds the value 20H, and we have a data 2F H stored at the address 20H, then the
value 2FH will get transferred to accumulator after executing this instruction. Got it? See the figure
below.

Figure 2.12: Illustration on Register Indirect Addressing Mode


So the opcode for MOV A, @R0 is E6H. Assuming that register bank #0 is selected. So the R0
of register bank #0 holds the data 20H. Program control moves to 20H where it locates the data 2FH
and it transfers 2FH to accumulator.
This is a single byte instruction and the program counter increments 1 and moves to 0203 of program
memory.
Note: Only R0 and R1 are allowed to form a register indirect addressing instruction. In other words
programmer can must make any instruction either using @R0 or @R1. All register banks are
allowed.

Indexed Addressing Mode


Well let’s see two examples first.
MOVC A, @A+DPTR and MOVC A, @A+PC
where DPTR is data pointer and PC is program counter (both are 16 bit registers). Lets take the first
example.
MOVC A, @A+DPTR
What’s the first impression you have now? The source operand is @A+DPTR and we know we
will get the source data (to transfer) from this location. It is nothing but adding contents of DPTR
with present content of accumulator. This addition will result a new data which is taken as the address
of source data (to transfer). The data at this address is then transferred to accumulator. Take a look
at the figure below.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 49

Figure 2.13: Illustration on Indeax Addressing Mode


The opcode for the instruction is 93H. DPTR holds the value 01FE, where 01 is located in DPH
(higher 8 bits) and FE is located in DPL (lower 8 bits). Accumulator now has the value 02H. A 16
bit addition is performed and now 01FE H+02 H results in 0200 H. Whatever data is in 0200 H will
get transferred to accumulator. The previous value inside accumulator (02H) will get replaced with
new data from 0200H. New data in the accumulator is shown in dotted line box.
This is a 1 byte instruction with 2 cycles needed for execution. What you infer from that? The
execution time required for this instruction is high compared to previous instructions (which all were
1 cycle).
The other example MOVC A, @A+PC works the same way as above example. The only difference
is, instead of adding DPTR with accumulator, here data inside program counter (PC) is added with
accumulator to obtain the target address.
I hope you now have a clear cut understanding of 8051 addressing modes. If you have any doubts or
need any additional clarifications, please post your comments below. I will answer them.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 50
TOPIC THREE
MEMORYARCHITECTURE
Computer memory is any physical device capable of storing information temporarily. Memory
is the most essential element of a computing system because without it computer cannot perform
simple tasks. Computer memory is of two basic type:
1. Primary memory / Volatile memory and
2. Secondary memory / non-volatile memory
Primary Memory
This is the internal memory and is the main area in a computer where the data is stored. Stored
data can be recalled instantly, quickly accessed and correctly whenever desired by the CPU for
reading or storing. Primary memory is classified into two types: Random Access Memory (RAM)
and Read- Only Memory (ROM).

Figure 3.0: Computer memory classifications


1. Random Access Memory (RAM)
RAM is also called the read/write memory because information can be read from and written onto
it. It is holds instructions for the computer, its programs and the data and the CPU can directly
access the data from RAM almost immediately. The storage of data and instructions in RAM is
temporary as long as the computer is running but it disappears from RAM as soon as power to the
computer is switched off. It is therefore a volatile memory.

There are two basic types of RAM as given below:


1. Dynamic RAM (DRAM)
2. Static RAM (SRAM)

Dynamic RAM
As the name suggests, it is dynamic in nature/operation. The stored information, DATA is
lost in a very short time, it can be in order of milliseconds depending upon the design and
specifications and internal structure.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 51
It is a cheaper and slower memory device. It is made up using semiconductor device technology.
Millions of pn- junction transistors and capacitors are used in making the Dynamic Random Access
Memory. It requires periodically refresh as the capacitors get discharged.

Operation of DRAM
DRAM is an Integrated Circuit (IC) and the most basic form of computer memory, Inside the
DRAM, Dynamic Memory Cell, represents a single bit of data. The capacitor holds the bit of
information – a 0 or a 1. The charged state of capacitor is taken as binary“1”(one) and the
discharged state as “0”(zero). Due to leakage of capacitors, refresh is required. The pn -junction
transistors act as a switch. This transistor switch is used by the control circuitry on the memory chip
to read the capacitor or change physical state of charging/ discharging. Capacitor stores the charge.
When it is fully charged it is treated as binary“1”(high level) in the memory cell. When there is no
charge stored in capacitor, it is treated as binary“0”(low level). It’s discharging rate is very high and
it takes few milliseconds.
For DRAM to work, it is to be recharged before they get discharged. Instructions are written so that
the memory controller reads the memory and then writes it right back by charging. Refreshing
operation is performed automatically thousands of times per second. The DRAM loses the data if
it does not get refresh operation. Refresh operation is an important and essential task for the
successful operation of Dynamic Random Access memory (DRAM).

Static RAM
Static RAM is a memory device in which the information or the data stored in it remains
protected unless and until the power supply is removed. It is costlier than the DRAM and it
consumes more power. It has higher working speed than DRAM.
SRAM made up of different technology than that of DRAM. This retains stored information only
as long as the power supply is on. Static RAM’s are costlier and consume more power. They have
higher speed than D-RAMs.

Operation of SRAM
A Flip Flop is used in static RAM, which holds each bit of memory that is binary 1 or 0. It
does not require refresh operation. A number of transistors are used in flip-flop for a Memory
Cell which never has to be refreshed. This is the main reason why static RAM is significantly faster
than dynamic RAM.

SRAM has more parts; its static memory cell takes up a lot of more space on a chip than it takes in
a dynamic memory cell. During design a Memory chip Engineer has to optimize the space
significantly to have a better memory. Because of more parts in SRAM, one get less memory per
chip and that makes static RAM a lot more expensive than DRAM. Hence, Static RAM is fast and
expensive; on the other hand, Dynamic RAM is less expensive and slower.

Similarity between SRAM and DRAM is that both lose data once the power is removed from
the device. However, DRAM essentially needs to be refreshed periodically. The key difference
between SRAM and DRAM is the technology that is being used for holding information or
the data. SRAM makes use of latches (flip-flops) in order to store data (transistor circuit), whereas
DRAM uses capacitors for storing bits in the form of charge (bits: binary“1” for
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 52
full charge and “0” for no charge). High speed complementary Metal Oxide semiconductor (CMOS)
technology is the basis for SRAM construction, whereas Dynamic RAM uses Special DRAM
processes for construction. Static RAMs have a complex internal structure than in comparison to
DRAMs.

Non-Volatile RAM - (NVRAM)


This is a type of memory that combines the advantages of volatile and non-volatile memories and
is achieved by add a small internal battery to an SRAM device so that when external poweris
switched off to retain power so that the SRAM still retains its content or by combining a SRAM
with an EEPROM in one package. Upon power-up, data is copied from the EEPROM to the
SRAM. During operation, data is read from and written to the SRAM. When power is cut off, the
data is copied to the EEPROM.

2. Read- Only Memory (ROM)


It is called Read-only memory. Information can only be read from it and cannot be written or
changed onto ROM. The storage of data and instructions in ROM is permanent. It is a ‘built-in’
memory of a computer and stores some Basic Input – Output Instructions (BIOS) put by the
manufacturer to operate the computer. Read Only Memories (ROMs) were the first types of non-
volatile semiconductor memories. If you want to use ROMs, you have to hand the data over to the
chip manufacturer, where a specific chip is made containing your data.

Mask-ROM - (MROM).
An MROM is composed of several layers. The geometrical layout of those layers defines the chip’s
function. A MROM contains a matrix of memory cells. The name Mask-ROM is derived from the
one mask which defines the row-column connections.

Programmable Read Only Memory (PROM)


Programmable Read Only Memory (PROM) is a matrix of memory cells, each containing a silicon
fuse. Each fuse is intact and each cell reads as a logical 1. By selecting a cell and applyinga high
current pulse, the cell’s fuse can be destroyed, thereby programming a logical 0 into the selected
cell.

Erasable Programmable Read Only Memory (EPROM)


EPROM programming is non-destructive and memory is stored in so-called field effect transistors
(FETs) or rather in one of their pins called gate. This gate is named as the floating gate as it is
completely insulated from the rest of the circuit. By applying an appropriately high voltage, it is
possible to charge the floating gate through a physical process called avalanche injection. Once a
cell is programmed, the electrons remain in the floating gate indefinitely.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 53
The EPROM is non-volatile. Has a quartz window in order to erase data. To erase you have to use
ultraviolet light every time. The whole chip gets erased by exposing to ultraviolet. So you can not
erase byte by byte. The OTP type of EPROM (one time programmable) don’t have this quartz
window, therefore you can’t erase. EPROM used IC is in the image to the right. No EPROM for
PIC 16F84 since it has EEPROM which will be discussed next.

Electrically Erasable and Programmable ROM (EEPROM)


EEPROM (electrically erasable programmable read-only memory) is user-modifiable read-only
memory (ROM) that can be erased and reprogrammed (written to) repeatedly through the
application of higher than normal electrical voltage. Unlike EPROM chips, EEPROMs do not need
to be removed from the computer to be modified. However, an EEPROM chip has to be erased and
reprogrammed in its entirety, not selectively. It also has a limited life - that is, the number of times
it can be reprogrammed is limited to tens or hundreds of thousands of times. In an EEPROM that
is frequently reprogrammed while the computer is in use, the life of the EEPROM can be an
important design consideration.
A special form of EEPROM is flash memory, which uses normal PC voltages for erasure and
reprogramming.

Flash Memory
Flash memory, also known as flash storage, is a type of nonvolatile memory that erases data in units
called blocks. A block stored on a flash memory chip must be erased before data can be written or
programmed to the microchip. Flash memory retains data for an extended period of time, regardless
of whether a flash-equipped device is powered on or off.

This type of memory is used to store the program you compile for the microcontroller. Also used in
Flash Drives. This type also wears out eventually and erase/write cycles are mentioned in the data
sheet of the microcontroller.
Flash EEPROM is used for program and not data memory. Flash-EEPROMs have a lower
guaranteed write/erase cycle endurance compared to EEPROMs – about 1,000 to 10,000 cycles.
Flash-EEPROMs are cheaper.

Accessing Memory
Many microcontrollers come with on-chip program and data memory with two methods of
accessing memory:
i. Each memory is addressed separately. In ATmega16, the address ranges has three different
memory types. The programmer specifies which memory is to be accessed by using
different access methods.
ii. All memory types share a common address range. In HCS12 the programmer accesses
EEPROM in the same way as SRAM. The microcontroller uses the address to decide
which memory the access goes to.
Suppose a 16 bit controller writes a word (two bytes) into SRAM, say at address 0x0100. The
word consists of a low and a high byte. There are two variants: the low byte could go to 0x0100
and the high byte to the next address (0x0101), or the other way around.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 54
8051 MICROCONTROLLER MEMORY ORGANIZATION

The 4 discrete types of memory in 8051 are:


i. Internal RAM (Data Memory) – This memory is located from address 0 to 0xff.The
memory locations from 0x00 to 0x7F are accessed directly. The bytes from 0x20 to 0x2F are bit-
addressable. Loading R0 and R1 the memory location from 0x80 to 0xFF can easily accessed.
ii. Program Memory (ROM) – This is read only memory which is located at address 0. With
the help of 16 bit Special Function Register DPTR, this memory can also save the tables of
constants.
iii. Special Function Registers (SFR) – Located from address 0x80 to 0xFF of the memory
location. The same instructions used for lower half of Internal RAM can be used to access
SFR’s. The SFR’s are bit addressable too.
iv. External Data Memory – Located at address 0. The Instruction MOVX (Move External)
should be used to access the external data memory.

The 8051 Microcontroller Memory is separated in Program Memory (ROM) and Data Memory
(RAM). The Program Memory of the 8051 Microcontroller is used for storing the program to be
executed i.e. instructions. The Data Memory on the other hand, is used for storing temporary variable
data and intermediate results.

8051 Microcontroller has both Internal ROM and Internal RAM. If the internal memory is
inadequate, you can add external memory using suitable circuits.

Program Memory (ROM) of 8051 Microcontroller


In 8051 Microcontroller, the code or instructions to be executed are stored in the Program Memory,
which is also called as the ROM of the Microcontroller. The original 8051 Microcontroller by Intel
has 4KB of internal ROM.

Some variants of 8051 like the 8031 and 8032 series does not have any internal ROM (Program
Memory) and must be interfaced with external Program Memory with instructions loaded in it.
Almost all modern 8051 Microcontrollers, like 8052 Series, have 8KB of Internal Program Memory
(ROM) in the form of Flash Memory (ROM) and provide the option of reprogramming the memory.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 55
Figure 3.1: 8051 Program memory (ROM)

In case of 4KB of Internal ROM, the address space is 0000H to 0FFFH. If the address space i.e. the
program addresses exceed this value, then the CPU will automatically fetch the code from the
external Program Memory.

For this, the External Access Pin (EA Pin) must be pulled HIGH i.e. when the EA Pin is high, the
CPU first fetches instructions from the Internal Program Memory in the address range of 0000H to
0FFFFH and if the memory addresses exceed the limit, then the instructions are fetched from the
external ROM in the address range of 1000H to FFFFH.

Figure 3.1: 8051 External Program memory (ROM)


There is another way to fetch the instructions: ignore the Internal ROM and fetch all the instructions
only from the External Program Memory (External ROM). For this scenario, the EA Pin must be
connected to GND. In this case, the memory addresses of the external ROM will be from 0000H to
FFFFH.

Figure 3.2: EA Pin connected to GND in order to access external ROM

Data Memory (RAM) of 8051 Microcontroller


BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 56
The Data Memory or RAM of the 8051 Microcontroller stores temporary data and intermediate
results that are generated and used during the normal operation of the microcontroller. Original
Intel’s 8051 Microcontroller had 128B of internal RAM.

But almost all modern variants of 8051 Microcontroller have 256B of RAM. In this 256B, the first
128B i.e. memory addresses from 00H to 7FH is divided in to Working Registers (organized as
Register Banks), Bit – Addressable Area and General Purpose RAM (also known as Scratchpad
area).

In the first 128B of RAM (from 00H to 7FH), the first 32B i.e. memory from addresses 00H to 1FH
consists of 32 Working Registers that are organized as four banks with 8 Registers in each Bank.

Figure 3.2: 8051 Memory banks and special Registers

The 4 banks are named as Bank0, Bank1, Bank2 and Bank3. Each Bank consists of 8 registers named
as R0 – R7. Each Register can be addressed in two ways: either by name or by address.

To address the register by name, first the corresponding Bank must be selected. In order to select the
bank, we have to use the RS0 and RS1 bits of the Program Status Word (PSW) Register (RS0 and
RS1 are 3rd and 4th bits in the PSW Register).

When addressing the Register using its address i.e. 12H for example, the corresponding Bank may
or may not be selected. (12H corresponds to R2 in Bank2).

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 57
The next 16B of the RAM i.e. from 20H to 2FH are Bit – Addressable memory locations. There are
totally 128 bits that can be addressed individually using 00H to 7FH or the entire byte can be
addressed as 20H to 2FH. For example 32H is the bit 2 of the internal RAM location 26H.

The final 80B of the internal RAM i.e. addresses from 30H to 7FH, is the general purpose RAM area
which are byte addressable.

These lower 128B of RAM can be addressed directly or indirectly. The upper 128B of the RAM
i.e. memory addresses from 80H to FFH is allocated for Special Function Registers (SFRs). SFRs
control specific functions of the 8051 Microcontroller. Some of the SFRs are I/O Port Registers (P0,
P1, P2 and P3), PSW (Program Status Word), A (Accumulator), IE (Interrupt Enable), PCON (Power
Control), etc.

Table 3.0: 8051 Registers and functions


SRFs Memory addresses are only direct addressable. Even though some of the addresses between
80H and FFH are not assigned to any SFR, they cannot be used as additional RAM area.

In some microcontrollers, there is an additional 128B of RAM, which share the memory address
with SFRs i.e. 80H to FFH. But, this additional RAM block is only accessed by indirect
addressing.

Interfacing External Memory with 8051 Microcontroller

We have seen that a typical 8051 Microcontroller has 4KB of ROM and 128B of RAM (most
modern 8051 Microcontroller variants have 8K ROM and 256B of RAM).

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 58
The designer of an 8051 Microcontroller based system is not limited to the internal RAM and ROM
present in the 8051 Microcontroller. There is a provision of connecting both external RAM and ROM
i.e. Data Memory and Program.
The reason for interfacing external Program Memory or ROM is that complex programs written in
high-level languages often tend to be larger and occupy more memory.

Another important reason is that chips like 8031 or 8032, which doesn’t have any internal ROM,
have to be interfaced with external ROM.

A maximum of 64B of Program Memory (ROM) and Data Memory (RAM) each can be interface
with the 8051 Microcontroller.

The following image shows the block diagram of interfacing 64KB of External RAM and 64KB of
External ROM with the 8051 Microcontroller.

The 8051 Microcontroller Special Function Registers (SFRs)


The internal RAM or Data Memory of the 8051 Microcontroller is divided in to General Purpose
Registers, Bit Addressable Registers, Register Banks and Special Function Registers or SFRs.

The 8051 Microcontroller Special Function Registers are used to program and control different
hardware peripherals like Timers, Serial Port, I/O Ports etc. In fact, by manipulating the 8051
Microcontroller Special Function Registers (SFRs), you can assess or change the operating mode of
the 8051 Microcontroller.

As a reminder, the following image shows you the basic structure of 8051 Microcontroller’s Internal
RAM (refer to Figure 3.2: 8051 Memory banks and special Registers)

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 59
The 8051 Microcontroller Special Function Registers act as a control table that monitor and control
the operation of the 8051 Microcontroller. If you observe in Internal RAM Structure, the Address
Space from 80H to FFH is allocated to SFRs.
Out of these 128 Memory Locations (80H to FFH), there are only 21 locations that are actually
assigned to SFRs. Each SFR has one Byte Address and also a unique name which specifies its
purpose.

Since the SFRs are a part of the Internal RAM Structure, you can access SFRs as if you access the
Internal RAM. The main difference is the address space: first 128 Bytes (00H to 7FH) is for regular
Internal RAM and next 128 Bytes (80H to FFH) is for SFRs.

List of Registers
Refer to table to Table 3.0: 8051 Registers and functions

The 21 Special Function Registers of 8051 Microcontroller are categorized in to seven groups.
They are:

Math or CPU Registers: A and B


Status Register: PSW (Program Status Word)
Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack Pointer)
I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and IP
Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF

CPU or Math Registers


A or Accumulator (ACC)
The Accumulator or Register A is the most important and most used 8051 Microcontroller SFRs.
The Register A is located at the address E0H in the SFR memory space. The Accumulator is used
to hold the data for almost all the ALU Operations.

Some of the operations where the Accumulator is used are:


 Arithmetic Operations like Addition, Subtraction, Multiplication etc.
 Logical Operations like AND, OR, NOT etc.
 Data Transfer Operations (between 8051 and External Memory)
The name “Accumulator” came from the fact this register is used to accumulate (or store) the result
of all Arithmetic and most of the Logical Operations.

B (Register B)
The B Register is used along with the ACC in Multiplication and Division operations. These two
operations are performed on data that are stored only in Registers A and B. During Multiplication

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 60
Operation, one of the operand (multiplier or multiplicand) is stores in B Register and also the higher
byte of the result.

In case of Division Operation, the B Register holds the divisor and also the remainder of the result.
It can also be used as a General Purpose Register for normal operations and is often used as an
Auxiliary Register by Programmers to store temporary results.
Register B is located at the address F0H of the SFR Address Space.

Program Status Word (PSW)


The PSW or Program Status Word Register is also called as Flag Register and is one of the important
SFRs. The PSW Register consists of Flag Bits, which help the programmer in checking the condition
of the result and also make decisions.

Flags are 1-bit storage elements that store and indicate the nature of the result that is generated by
execution of certain instructions. The following image shows the contents of the PSW Register.

The following table describes the function of each flag.

Pointer Registers
Data Pointer (DPTR – DPL and DPH)
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 61
The Data Pointer is a 16-bit Register and is physically the combination of DPL (Data Pointer Low)
and DPH (Data Pointer High) SFRs. The Data Pointer can be used as a single 16-bit register (as
DPTR) or two 8-bit registers (as DPL and DPH).
DPTR doesn’t have a physical Memory Address but the DPL (Lower Byte of DPTR) and DPH
(Higher Byte of DPTR) have separate addresses in the SFR Memory Space. DPL = 82H and DPH
= 83H.
The DPTR Register is used by the programmer addressing external memory (Program-ROM or
Data-RAM).

Stack Pointer (SP)


SP or Stack Pointer points out to the top of the Stack and it indicates the next data to be accessed.
Stack Pointer can be accesses using PUSH, POP, CALL and RET Instructions. The Stack Pointer
is an 8-bit register and upon reset, the Stack Pointer is initialized with 07H.
When writing a new data byte into the stack, the SP (Stack Pointer) is automatically incremented by
1 and the new data is written at an address SP+1. When reading data from stack, the data is retrieved
from the Address in SP and after that the SP is decremented by 1 (SP-1).

I/O Port Registers (P0, P1, P2 and P3)


The 8051 Microcontroller four Ports which can be used as Input and/or Output. These four ports are
P0, P1, P2 and P3. Each Port has a corresponding register with same names (the Port Registers are
also P0, P1, P2 and P3). The addresses of the Port Registers are as follows: P0 – 80H, P1 – 90H, P2
– A0H and P2 – B0H.
Each bit in these SFRs corresponds to one physical Pin in the 8051 Microcontroller. All these Port
Registers are both Bit Addressable and Byte Addressable. Writing 1 or 0 on a Port Register Bit will
reflect as an appropriate voltage (5V and 0V) on the corresponding Pin.
If a Port Bit is SET (declared as 1), the corresponding Port Pin will be configured as Input and
similarly if a Port Bit is CLEARED (declared as 0), the corresponding Port Pin is configured as

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 62
Output. Upon reset, all the Port Bits are SET (1) and hence, all the Port Pins are configured as
Inputs.

Peripheral Control Registers


PCON (Power Control)
The PCON or Power Control register, as the name suggests is used to control the 8051
Microcontroller’s Power Modes and is located at 87H of the SFR Memory Space. Using two bits in
the PCON Register, the microcontroller can be set to Idle Mode and Power Down Mode.
During Idle Mode, the Microcontroller will stop the Clock Signal to the ALU (CPU) but it is given
to other peripherals like Timer, Serial, Interrupts, etc. In order to terminate the Idle Mode, you have
to use an Interrupt or Hardware Reset.
In the Power Down Mode, the oscillator will be stopped and the power will be reduced to 2V. To
terminate the Power Down Mode, you have to use the Hardware Reset.
Apart from these two, the PCON Register can also be used for few additional purposes. The
SMOD Bit in the PCON Register is used to control the Baud Rate of the Serial Port.
There are two general purpose Flag Bits in the PCON Register, which can be used by the
programmer during execution.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 63

SCON (Serial Control)


The Serial Control or SCON SFR is used to control the 8051 Microcontroller’s Serial Port. It is
located as an address of 98H. Using SCON, you can control the Operation Modes of the Serial
Port, Baud Rate of the Serial Port and Send or Receive Data using Serial Port.
SCON Register also consists of bits that are automatically SET when a byte of data is transmitted
or received.

Serial Port Mode Control Bits

TCON (Timer Control)

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 64
Timer Control or TCON Register is used to start or stop the Timers of 8051 Microcontroller. It also
contains bits to indicate if the Timers has overflowed. The TCON SFR also consists of Interrupt
related bits.

TMOD (Timer Mode)


The TMOD or Timer Mode register or SFR is used to set the Operating Modes of the Timers T0
and T1. The lower four bits are used to configure Timer0 and the higher four bits are used to
configure Timer1.

The Gatex bit is used to operate the Timerx with respect to the INTx pin or regardless of the INTx
pin.
GATE1 = 1 ==> Timer1 is operated only if INT1 is SET.
GATE1 = 0 ==> Timer1 is operates irrespective of INT1 pin.
GATE0 = 1 ==> Timer0 is operated only if INT0 is SET.
GATE0 = 0 ==> Timer0 is operates irrespective of INT0 pin.

The C/Tx bit is used selects the source of pulses for the Timer to count.
C/T1 = 1 ==> Timer1 counts pulses from Pin T1 (P3.5) (Counter Mode)
C/T1 = 0 ==> Timer1 counts pulses from internal oscillator (Timer Mode)
C/T0 = 1 ==> Timer0 counts pulses from Pin T0 (P3.4) (Counter Mode)
C/T0 = 0 ==> Timer0 counts pulses from internal oscillator (Timer Mode)

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 65

IE (Interrupt Enable)
The IE or Interrupt Enable Register is used to enable or disable individual interrupts. If a bit is
SET, the corresponding interrupt is enabled and if the bit is cleared, the interrupt is disabled. The
Bit7 of the IE register i.e. EA bit is used to enable or disable all the interrupts.

IP (Interrupt Priority)
The IP or Interrupt Priority Register is used to set the priority of the interrupt as High or Low. If a
bit is CLEARED, the corresponding interrupt is assigned low priority and if the bit is SET, the
interrupt is assigned high priority.

Peripheral Data Registers


SBUF (Serial Data Buffer)
The Serial Buffer or SBUF register is used to hold the serial data while transmission or reception.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 66

TL0/TH0 (Timer 0 Low/High)


The Timer 0 consists of two SFRs: TL0 and TH0. The TL0 is the lower byte and the TH0 is the
higher byte and together they form a 16-bit Timer0 Register.

TL1/TH1 (Timer 1 Low/High)


The TL1 and TH1 are the lower and higher bytes of the Timer 0.

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
P a g e | 67
Applications of 8051 Microcontroller:
The microcontroller 8051 applications include large amount of machines, principally because it is
simple to incorporate in a project or to assemble a machine around it. The following are the key spots
of spotlight:
1. Energy Management: Efficient measuring device systems aid in calculating energy consumption
in domestic and industrialized applications. These meter systems are prepared competent by
integrating microcontrollers.
2. Touch screens: A high degree of microcontroller suppliers integrate touch sensing abilities in
their designs. Transportable devices such as media players, gaming devices & cell phones are
some illustrations of micro-controller integrated with touch sensing screens.
3. Automobiles: The microcontroller 8051 discovers broad recognition in supplying automobile
solutions. They are extensively utilized in hybrid motor vehicles to control engine variations. In
addition, works such as cruise power and anti-brake mechanism has created it more capable with
the amalgamation of micro-controllers.
4. Medical Devices: Handy medicinal gadgets such as glucose & blood pressure monitors bring into
play micro-controllers, to put on view the measurements, as a result, offering higher dependability
in giving correct medical results.
5. Medical Devices: Handy medicinal gadgets such as glucose & blood pressure monitors bring into
play micro-controllers, to put on view the measurements, as a result, offering higher dependability
in giving correct medical results.

Assigment (To be submitted for marking)


With the aid diagram(s), explain Flash memory operation basics

Exercises
Exercise 2.2.1 What are the advantages of PROM over ROM? Are there any disadvantages?
Exercise 2.2.2 Why do EPROMs have a window, while EEPROMs do not have a window? What
is the window used for?
Exercise 2.2.3 What is the difference between an EEPROM and a Flash-EEPROM?
Exercise 2.2.4 What are the advantages and disadvantages of a RAM compared to an EEPROM?
Exercise 2.2.5 Why do microcontrollers use SRAMs and not DRAMs?
Exercise 2.2.8 Why does the NVRAM not copy every write access into the EEPROM? Would
that not be more secure?
Exercise 2.2.9 When is an OTP memory useful? Would you put a controller with OTP memory
into a cell phone?

BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECNIC MOMBASA. DATE 05/04/2019
COMPILED BYMR. AKETCH - A TVET - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019

You might also like