Microcontroller - Introduction
Microcontroller - Introduction
Microcontroller - Introduction
DATE 05/04/2019
COMPILED BY MR. AKETCH - A TVET TRAINER - KENYA COAST NATIONAL POLYTECHNIC. DATE 05/04/2019
Page |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.
. 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.
Using a configurable IC, is a great idea. Not only the same IC, can be
configured t o 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
Page |3
market were 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.
Definitions
A microcontroller is a small computer on a single integrated circuit (IC)
containing a processor core, memory, and programmable input/output
ports.
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
Page |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
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.
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 function 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.
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
Page |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).
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
Page |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 the
function 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.
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
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.3: Basic connections between the microprocessor and external 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 | 16
Another table of comparison is here:
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
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:
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 this 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 this instructions are register based and data transfer takes place from register to
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 | 19
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.
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
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.
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-equipments.
- 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.
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.
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!
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,
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 is a good way of classifying chip according to architecture, historically, there has
been more than a few instances where developers introduces significant architectural changes to
the same family such as XD, NX, and various SSE extensions in the case of Intel.
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 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.
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
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 microcontroller
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 and more efficient. Microcontrollers were seen as the answer to
the requirements was raised in advanced electronics. This is the reason why manufacturers have
now focused their production around the following main developmental aspects:
i. Ease-of-use
ii. Market availability
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 | 29
iii. Less power usage
iv. Smaller processing power
v. More integrated features like RF and USB
vi. Smaller form factors
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
P a g e | 30
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.
Generally five interrupt sources are there in 8051 Microcontroller. There are 5 vectored interrupts
are shown in below
INTO
TFO
INT1
TF1
R1/T1
Out of these, INT0 and INTI are external interrupts that could be negative edge triggered or low
level triggered. When All these interrupts are activated, set the corresponding flags except for serial
interrupt, The interrupt flags are cleared when the processor branches to the interrupt service
routine (ISR), provides the interrupt is a negative edge triggered whereas the timers and serial port
interrupts two of them are external interrupts, two of them are timer interrupts and one serial port
interrupt terminal in general.
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 principle 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:
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.
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 | 31
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 microcontroller 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.
Prescaler
Prescaler is 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
P a g e | 32
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).
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 | 34
Timers and Counters in 8051 Microcontroller
Many of the microcontroller applications require counting of external events such as frequency of
the pulse trains and generation of precise internal time delays between computer actions. Both
these tasks can be implemented by software techniques, but software loops for counting, and
timing will not give the exact result rather more important functions are not done. To avoid these
problems, timers and counters in the micro-controllers are better options for simple and low-cost
applications. These timers and counters are used as interrupts in 8051 microcontroller.
The 8051 microcontrollers have two timers/counters which work on the clock frequency.
Timer/counter can be used for time delay generation, counting external events et
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.
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 | 35
Figure 2.4: 8051 Microcontroller timer registers
8051 has Timer Mode Register and Timer Control Register for selecting a mode of operation
and controlling purpose.
Let's see these registers,
TMOD register
TMOD is an 8-bit register used to set timer mode of timer0 and timer1.
M1 M0 Mode Operation
0 0 0 (13-bit timer mode) 13-bit timer/counter, 8-bit of THx & 5-bit of TLx
0 1 1 (16-bit timer mode) 16-bit timer/counter, THx cascaded with TLx
8-bit timer/counter (auto reload mode), TLx reload with
1 0 2 (8-bit auto reload mode)
value held by THx each time TLx overflow
Split 16-bit timerx into two 8-bit timer i.e. THx and TLx
1 1 3 (split timer mode)
like two 8-bit 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 | 36
TCON Register
Timer Modes
Timers have their operation modes which are selected in TMOD register using M0 & M1 bit
combinations.
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
Mode 0 (13-bit timer mode)
Mode 0 is 13-bit timer mode for which 8-bit of THx and 5-bit of TLx (as Prescaler) is used. It is
mostly used for interfacing that is possible with old MCS-48 family microcontrollers.
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
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.
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 are 5 different ways to execute this instruction and hence we say, we have got 5 addressing
modes for 8051.
They are
1. Immediate addressing 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
2. Direct addressing mode
3. Register direct addressing mode
4. Register indirect addressing mode
5. Indexed 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
the hexadecimal number would be taken as address.
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.
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 | 42
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 | 43
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.
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 | 44
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 | 45
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).
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 | 46
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 | 47
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.
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.
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
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.
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 | 49
8051 MICROCONTROLLER MEMORY ORGANIZATION
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.
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 | 50
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.
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.
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 | 52
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.
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.
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 | 53
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 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 | 54
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:
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 | 55
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.
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.
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 | 56
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).
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
Output. Upon reset, all the Port Bits are SET (1) and hence, all the Port Pins are configured as
Inputs.
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
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
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.
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 | 60
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.
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
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
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.
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