Microcontroller - Introduction - 1
Microcontroller - Introduction - 1
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.
. 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 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.
Definitions
A microcontroller is a small computer on a single integrated circuit (IC)
containing a processor core, memory, and programmable input/output
ports.
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
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
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.
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.
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).
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.
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
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 | 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:
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 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
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.
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-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.
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 | 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.
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
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 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.
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.
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
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.
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
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
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:
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.
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.
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
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.
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.
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
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.
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
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.
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.
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.
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.
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.
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 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.
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
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 | 47
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.
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
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).
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.
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 | 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.
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 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 | 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.
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 | 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.
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 | 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 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:
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.
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 | 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).
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.
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
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.
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.
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
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.
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