MC ModULE 1
MC ModULE 1
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and
programmable input/output peripherals. It's designed to execute specific tasks in embedded systems, which are
systems dedicated to a specific function within a larger mechanical or electrical system.
Microcontroller integrates a Central Processing Unit (CPU), memory, and input/output (I/O)
functionalities, all condensed onto a single integrated circuit. This makes them compact, cost-effective, and
perfect for controlling specific tasks within a bigger system.
Microcontrollers are commonly used in various applications such as automotive systems, home
appliances, medical devices, industrial automation, and consumer electronics. They offer a cost-effective and
efficient solution for controlling and monitoring tasks in embedded systems. Programming microcontrollers
typically involves writing code in a high-level language like C/C++ or using specialized development
environments provided by microcontroller manufacturers.
Home appliances: microwaves controlling cooking time and temperature, washing machines running
cycles.
Automotive systems: engine management, airbag deployment.
Consumer electronics: gaming systems handling controls, digital cameras adjusting settings.
Advantages of microcontrollers:
Small size and low cost: Make them ideal for embedding in various devices.
Low power consumption: Efficient for battery-powered applications.
Self-contained: Integrates all necessary components for a dedicated task.
Microprocessors and microcontrollers are both essential components in the world of embedded systems, but they
serve different purposes and have distinct characteristics.
Microprocessor (µP): Acts as the central processing unit (CPU) in a computer system. It's designed for
general-purpose computing and powerful processing. Think of it as the brain of a computer.
Microcontroller (µC): Functions as a complete mini-computer on a single chip. It's optimized for specific
tasks within an embedded system, like controlling a washing machine's cycle.
iii. Design Complex, high clock speed Simpler, lower clock speed
iv. Memory External RAM and ROM Internal RAM and ROM
Microprocessors are more powerful and handle complex calculations, but they require additional
components like memory and I/O interfaces, making the system more expensive and complex.
Microcontrollers are self-contained and cost-effective, ideal for dedicated tasks in embedded systems
where size and power efficiency are crucial.
Microprocessors are suitable for tasks requiring high computational power, while microcontrollers are specialized
for embedded applications that require control and monitoring functions in various devices.
The terms "microcontroller" and "embedded processor" are actually quite closely related. In fact, a
microcontroller can be considered a type of embedded processor.
Microcontroller (MCU):
A self-contained mini-computer on a single chip designed for specific tasks within an embedded system.
Includes a CPU, memory (RAM and ROM), and integrated I/O peripherals for interacting with external
devices (sensors, actuators, displays).
Optimized for low power consumption and cost-effectiveness.
Microcontroller (MCU): Use this term when referring to a specific type of embedded processor that's self-
contained and optimized for low-power, low-cost control tasks.
Embedded Processor: Use this term as a broader category that includes microcontrollers (MCUs) along
with other processors used in embedded systems.
Microcontrollers are a specific type of embedded processor designed for simplicity and integration, embedded
processors encompass a broader range of processors used in embedded systems, offering varying levels of
complexity and performance depending on the application requirements.
Harvard and Princeton architectures are two fundamental approaches to computer architecture, including
processors and memory organization. Processor architectures come in two main flavors: Harvard and von
Neumann (also known as Princeton).
The Von Neumann architecture is a type of computer architecture in which the central processing unit (CPU),
memory, and input/output (I/O) devices all use a single shared bus for communication. It was named after John
von Neumann, a pioneer in the development of electronic computers. The Von Neumann architecture is also
known as the Von Neumann model or the Princeton architecture.
In a Von Neumann architecture, instructions and data are stored in a single memory system. This memory
is usually implemented as random access memory (RAM) and is connected to the CPU and I/O devices through
a common bus. The CPU executes instructions by fetching them from memory, decoding them, and then executing
them.
The Von Neumann architecture consists of four main components:
CPU: The central processing unit is the brain of the computer. It performs all the calculations and
operations required to execute instructions.
Memory: The memory holds both instructions and data that the CPU needs to execute. The memory is
organized as a linear sequence of addressable cells, each containing a fixed number of bits.
Input/output (I/O) devices: These devices are used to communicate with the outside world. Examples
include keyboards, displays, and printers.
System bus: The system bus is a collection of wires that connect the CPU, memory, and I/O devices. It is
used to transmit data, instructions, and control signals between these components.
Harvard architecture is a type of computer architecture that has separate memory spaces for instructions and data.
It was developed at Harvard University in the 1930s, and it is named after this institution. In a Harvard architecture
system, the CPU accesses instruction and data memory spaces separately, which can lead to improved
performance.
The Harvard architecture consists of the following main components:
CPU: The central processing unit performs all the calculations and operations required to execute
instructions.
Instruction memory: This memory holds instructions that the CPU needs to execute. It is typically
implemented as read-only memory (ROM) or flash memory.
Data memory: This memory holds data that the CPU needs to perform computations. It is typically
implemented as random access memory (RAM).
Input/output (I/O) devices: These devices are used to communicate with the outside world. Examples
include keyboards, displays, and printers.
System bus: The system bus is a collection of wires that connect the CPU, instruction memory, data
memory, and I/O devices. It is used to transmit data, instructions, and control signals between these
components.
Von Neumann architecture is the traditional design found in most personal computers and servers due to
its simplicity and cost-effectiveness.
Harvard architecture offers better performance by eliminating the bottleneck caused by the single bus in
von Neumann architecture. This makes it preferable for tasks requiring high throughput of data and instructions.
Here is a tabular comparison between Von Neumann architecture and Harvard architecture:
Separate data buses for Single set of data buses for both
ii. Data Buses
instructions and data instructions and data
RISC and CISC are two design philosophies for processor architectures, each aiming to achieve optimal
performance in different ways. Here's a breakdown of their key differences:
RISC offers a simpler approach with faster execution speed and lower power consumption.
CISC (Complex Instruction Set Computing):
CISC provides a wider range of instructions, potentially reducing program size but may be slower and less power-
efficient.
Here's a table summarizing the key differences between RISC (Reduced Instruction Set Computing) and
CISC (Complex Instruction Set Computing) architectures:
The 8051 microcontrollers, designed by Intel in the early 1980s, is a popular choice for beginners due to its
relatively simple architecture. Here's a breakdown of its key components:
The architectural block diagram of 8051 is shown in fig. The 8051 is a 40 – pin DIP and most commonly used
microcontroller. The specific features of 8051 are the following
8 – Bit CPU with two registers: A (accumulator) & B. Accumulator is used in most arithmetic and logic
operations. Register B is also used for integer multiplication and division.
A 16 – bit register called Program Counter (PC). It holds the address of the location of the next
instruction to be executed.
An 8 – bit Program Status Word (PSW) register. It indicates certain conditions like status of carry, sign,
parity, etc., after the execution of some instructions.
Four 8 – bit ports, P0 to P3. A port pins are used to send or to read data from external devices.
Two 16 – bit timer/counter: Used as timers to generate delay between two events with the help of
internal clock pulses or used as a counter to count external pulses.
Full duplex serial data transmitter/receiver register, SBUF. This holds the byte to be transmitted or the
received byte, when serial communication is used.
Two external interrupts and three internal interrupts. Interrupts are events which interrupt the normal
sequence of execution of instructions.
Control registers: TCON, TMOD, SCON, PCON, IP and IE which control the operations of the timers,
serial ports and interrupts.
Oscillator and clock circuits.
1.6 PROGRAMMING MODEL OF 8051
The programming model of 8051 in fig 1.6 shows the 8051 as a collection of 8 – bit, 16 –bit registers and 8 – bit
memory locations. The model is complicated by number of special function registers that must be present to
make a microcomputer a microcontroller.
Internal ROM : 4 k
Internal RAM : 128 bytes
4 Register Banks (each with 8 registers)
16 Bit addressable memory locations
Special Function Registers (SFR’s)
CPU or Math Registers
A or Accumulator (ACC)
B (Register B)
Pointer Registers
Data Pointer (DPTR – DPL and DPH)
Stack Pointer (SP)
Peripheral Control Registers
IE (Interrupt Enable)
IP (Interrupt Priority)
TMOD (Timer Mode)
TCON (Timer Control)
TL0/TH0 (Timer 0 Low/High)
TL1/TH1 (Timer 1 Low/High)
SCON (Serial Control)
SBUF (Serial Data Buffer)
PCON (Power Control)
PSW Program Status Word
Peripheral Data Registers
I/O Port Registers (P0, P1, P2 and P3)
1.7 Pin diagram of 8051 Microcontroller
The 8051 microcontroller is a popular choice for beginners due to its relatively simple architecture. Here's
a look at its pin diagram:
Pins 1 to 8 (Port 1): These pins are a bi-directional I/O port that can be used for interfacing with external
devices.
Pin 9 (RESET): This pin is used to reset the microcontroller to its initial values.
Pins 10 to 17 (Port 3): These pins have multiple functions including serving as interrupt inputs, timer
inputs, control signals, and serial communication signals.
Pins 18 & 19 (XTAL1 & XTAL2): These pins are used for connecting an external crystal oscillator that
provides the clock signal for the microcontroller.
Pin 20 (VCC): This pin provides the power supply voltage (typically +5V) to the microcontroller.
Pin 21 to 28 (Port 2): These pins are another bi-directional I/O port that can be used for various purposes.
Pin 29 (PSEN): This pin is the Program Store Enable signal and is used during the process of fetching
instructions from program memory.
Pin 30 (EA): This pin is the External Access input and is used to enable or disable external memory
interfacing.
Pins 32 to 39 (Port 0): This is a bi-directional I/O port that also serves as the lower order address bus for
memory access.
Pin 40 (GND): This pin is the ground connection for the microcontroller.
By understanding the functions of each pin, you can effectively interface the 8051 microcontrollers with
various external components to build electronic circuits and systems.
RAM location can be referred by their name (say R4) or by its address (04h)
Ex: ADD A, R4 or ADD A, 04H
ii) Sixteen bytes, which are bit addressable (also byte addressable). The individual
bits of these bytes can be altered. Ex: SETB 07h
iii)Eighty bytes of general purpose RAM memory from addresses 30h through 7Fh, may be used by user
variables that need to be accessed frequently or at high-speed. This area is also utilized by the
microcontroller as a storage area for the operating stack.
[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay]
Figure shows how to access or interface ROM to 8051.
Port 0 is used as multiplexed data & address lines. It gives lower order (A7-A0) 8
bit address in initial T cycle & higher order (A8-A15) used as data bus.
8 bit address is latched using external latch & ALE signal from 8051.
Port 2 provides higher order (A15-A8) 8 bit address.
PSEN is used to activate the output enable signal of external ROM/EPROM.
[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay]
Figure shows how to connect or interface external RAM (data memory) to 8051.
Port 0 is used as multiplexed data & address lines.
Address lines are decoded using external latch & ALE signal from 8051 to provide
lower order (A7-A0) address lines.
Port 2 gives higher order address lines.
RD & WR signals from 8051 selects the memory read & memory write operations
respectively.
Note: RD & WR signals: generally P3.6 & P3.7 pins of port 3 are used to generate
memory read and memory write signals. Remaining pins of port 3 i.e. P3.0-P3.5 can be
used for other functions.
Solved Examples:
Example 1: Design a μController system using 8051 to Interface the external RAM of
size 16k x 8.
Solution: Given, Memory size: 16k
Which means, we require 2n=16k: n address lines
Here n=14: A0 to A13 address lines are required.
A14 and A15 are connected through OR gate to CS pin of external RAM.
When A14 and A15 both are low (logic ‘0’), external data memory (RAM) is
selected.
Start 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000
H
End 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FF
FH
Figure shows interfacing of 16k x 8 RAM to 8051.
Start 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000
H
End 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0FF
FH
Figure shows interfacing of 4k x 8 ROM to 8051
Start 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000
H
End 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FF
FH
Start 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8000
H
End 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 FFF
FH
Figure 5.6.5 shows the interfacing of 16Kx8 Memory (ROM) and 32Kx8 RAM with 8051
Figure 16Kx8 Memory (ROM) and 32Kx8 RAM Interfacing with 8051
[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay, pg.no.320]
1.12 THE 8051 OSCILLATOR AND CLOCK
The heart of the 8051 is the circuitry that generates the clock pulses by which all internal
operations are synchronized. Pins XTAL1 and XTAL2 are provided for connecting a resonant
network to form an oscillator. Typically a quartz crystal and capacitors are employed, as shown
in figure 1.13. The crystal frequency, typically 1MHz to 16MHz is the basic internal clock
frequency of microcontroller.
Serial data communication needs often dictate the frequency of the oscillator because of the requirement that
internal counters must divide the basic clock rate to yield standard communication bit per second (baud) rates.
However decrease in frequency stability and accuracy make the ceramic resonator a poor choice if the high
speed data communication with other systems, or critical timing, is to be done.
f = crystal clock frequency
P = smallest interval of time within the microcontroller called pulse
Machine cycle: The smallest interval of time to accomplish any simple instruction, or
Part of a complex instruction.
One machine cycle = Six states
One state = Two oscillator pulse