0% found this document useful (0 votes)
3 views23 pages

MC ModULE 1

The document provides an overview of microcontrollers, detailing their components, advantages, and applications in embedded systems. It contrasts microcontrollers with microprocessors, explaining their distinct functionalities and architectures, including Harvard and von Neumann designs. Additionally, it covers RISC and CISC architectures, and provides a detailed look at the 8051 microcontroller, including its programming model and pin diagram.

Uploaded by

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

MC ModULE 1

The document provides an overview of microcontrollers, detailing their components, advantages, and applications in embedded systems. It contrasts microcontrollers with microprocessors, explaining their distinct functionalities and architectures, including Harvard and von Neumann designs. Additionally, it covers RISC and CISC architectures, and provides a detailed look at the 8051 microcontroller, including its programming model and pin diagram.

Uploaded by

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

BEC405A - MICROCONTROLLERS

1.0 Introduction to Microcontroller

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.

Key components of a microcontroller:

 CPU: The processing unit that executes instructions.


 Memory: Stores program instructions (ROM) and temporary data (RAM).
 Input/output (I/O): Allows communication with external devices like sensors, buttons, and displays.

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.

1.1 Microprocessor v/s Microcontroller

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.

Feature Microprocessor (µP) Microcontroller (µC)

i. Functionality Central processing unit Mini-computer on a chip

ii. Purpose General-purpose computing Specific tasks in embedded systems

iii. Design Complex, high clock speed Simpler, lower clock speed

iv. Memory External RAM and ROM Internal RAM and ROM

v. I/O peripherals External Integrated

vi. Cost More expensive Less expensive

vii. Power consumption Higher Lower

Embedded systems (washing


Computers, servers, laptops,
viii. Applications machines, thermostats, toys,
smartphones
industrial control)

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.

1.2 Micro controller & Embedded Processors

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.

Examples: washing machine controllers, thermostat regulators, remote controls.


Embedded Processor:

 A broader term encompassing any processor used in an embedded system.


 An embedded system is a dedicated computer system with a specific function, like controlling a car's
engine or operating a traffic light.
 Can include microcontrollers (MCUs) as well as more powerful processors depending on the application's
needs.
 Microprocessors (µPs) can also be used as embedded processors in some cases, particularly for complex
embedded systems requiring high processing power (e.g., industrial robots). However, microprocessors
typically require external memory and I/O components, making them less ideal for size and cost-
constrained applications.

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.

1.3 Processor Architectures - Harvard v/s Princeton

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).

1.3.1 Von Neumann Architecture (Princeton Architecture):

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.

1.3.2 Harvard Architecture

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.

1.3.3 Difference Between Von-Neumann and Harvard Architecture

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:

von Neumann Architecture


Feature Harvard Architecture
(Princeton Architecture)

Separate memory spaces for Single memory space for both


i. Memory
instructions and data instructions and data

Separate data buses for Single set of data buses for both
ii. Data Buses
instructions and data instructions and data

iii. Instruction Fetching & Can't happen simultaneously


Can happen concurrently
Data Access (bottleneck)

Faster due to concurrent


iv. Speed Slower due to single bus bottleneck
processing

v. Complexity More complex design Simpler design

vi. Cost Slightly more expensive More cost-effective

More challenging due to managing Easier due to one unified memory


vii. Programming
two memory spaces space

Real-time signal processing, high- General-purpose computing, cost-


viii. Applications
performance systems sensitive applications

1.4 RISC v/s CISC

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 (Reduced Instruction Set Computing):

 Focuses on a smaller set of simpler instructions.


 Each instruction typically takes one clock cycle to execute.
 Relies on the compiler to break down complex tasks into these simpler instructions.
 Uses a fixed instruction format for easier decoding by the processor.
 Aims for faster execution speed and lower power consumption.

RISC offers a simpler approach with faster execution speed and lower power consumption.
CISC (Complex Instruction Set Computing):

 Offers a larger set of complex instructions.


 These complex instructions can perform multiple operations in a single cycle, potentially reducing the
total number of instructions needed for a program.
 Less reliance on the compiler for optimization.
 Instructions can be variable in length and format, increasing decoding complexity.
 May be slower due to complex instruction processing and potential for multiple clock cycles per
instruction.

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:

RISC (Reduced Instruction Set CISC (Complex Instruction Set


Feature
Computing) Computing)

Smaller set of simpler


i. Instruction Set Larger set of complex instructions
instructions

Each instruction typically in one Complex instructions may take


ii. Instruction Execution
clock cycle multiple clock cycles

Relies on compiler to break down Less reliance on compiler for


iii. Reliance on Compiler
complex tasks optimization

Fixed instruction format for Variable instruction length and


iv. Instruction Format
easier decoding format

Potentially fewer instructions


Faster execution speed, lower
v. Focus needed, simpler programming
power consumption
model

Faster, simpler design, lower More versatile instruction set,


vi. Advantages
power consumption potentially smaller program size

May require more instructions Slower, more complex design,


vii. Disadvantages
for complex tasks higher power consumption

Mobile devices, embedded


Legacy systems, personal
viii. Applications systems, high-performance
computers (historically)
computing
1.5 Architecture of 8051 Microcontroller

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.

 A 16 – bit Data Pointer (DPTR) register. It is used to access external memory.

 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.

 Internal RAM of 128 bytes divided as :


i) Four register banks of 8 register each. (R0 to R7 each of 8 – bit size)
ii) Sixteen bytes, which are bit addressable. The individual bits of these bytes can be altered.
iii) Eighty bytes of general RAM memory.

 Internal ROM of 4K bytes used to store program code.


 Special Function Registers (SFRs): These are small, on-chip memory locations that control various
functionalities of the microcontroller. Examples include timers, serial communication ports, and I/O pin
control registers.

 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.

1.8 Internal RAM Organization


Data memory (Internal RAM): The 8051 has 128 bytes of Internal RAM. This Internal RAM is found on-chip on
the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and
modifying its contents. Internal RAM is volatile, so when the 8051 is reset this memory is cleared. The 128
bytes of internal RAM is subdivided as shown on the memory map.
 The 128 bytes of internal RAM is subdivided as shown on the memory map:
i) Four register banks of 8 register each (32bytes). By default register bank 0 is selected and different
register banks are selected with the help of flags bits (RS1 & RS0) present in PSW.
RB0 – 00h to 07h
RB1 – 08h to 0fh
RB2 – 10h to 17h
RB3 – 18h to 1Fh

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.

1.9 PSW (PROGRAM STATUS WORD)


1.10 I/O ports functions in 8051 Microcontroller
1.11 EXTERNAL MEMORY INTERFACE

EXTERNAL ROM (PROGRAM MEMORY) INTERFACING

Figure :Interfacing of ROM/EPROM to 8051

[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.

EXTERNAL RAM (DATA MEMORY) INTERFACING

Figure Interfacing of RAM to 8051

[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.

Address Decoding (Memory Map) For 16k X 8 Ram


Addr A1 A1 A1 A1 A1 A1 A A A A A A A A A A Hex
ess 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 Addr

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.

Figure 5.6.3 16Kx8 Memory (RAM) Interfacing with 8051


[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay]
Example 2: Design a μController system using 8051 to interface the external ROM of
size 4k x 8.
Solution: Given, Memory size: 4k
i.e we require 2n=4k :: n address lines
 Here n=12 :: A0 to A11 address lines are required.
 Remaining lines A0, A0, A0, A0 & PSEN are connected though OR gate to CS &
RD of external ROM.
 When A0 to A0 are low (logic ‘0’), only then external ROM is selected.
Address Decoding (Memory Map)for 4k x 8 RAM
Addr A1 A1 A1 A1 A1 A1 A A A A A A A A A A Hex
ess 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 Addr

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

Figure 4Kx8 Memory (ROM) 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]
Example 3: Design a μController system using 8051, 16k bytes of ROM & 32k bytes of
RAM. Interface the memory such that starting address for ROM is 0000H & RAM is
8000H.
Solution:
Given, Memory size- ROM : 16k
i.e we require 2n=16k :: n address lines
Here n=14 :: A0 to A13 address lines are required.
A14,A15,PSEN ORed CS when low – ROM is selected
Memory size- RAM :32k
i.e we require 2n=32k :: n address lines
Here n=15 :: A0 to A15 address lines are required.
A15 inverted(NOT Gate) CS when high- RAM is selected.
For RAM selection
 PSEN is used as chip select pin ROM.
 RD is used as read control signal pin..
 WR is used as write control signal pin.
Address Decoding (Memory Map) for 16k x 8 ROM.
Addr A1 A1 A1 A1 A1 A1 A A A A A A A A A A Hex
ess 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 Addr

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

Address Decoding (Memory Map) for 32k x 8 RAM.


Addr A1 A1 A1 A1 A1 A1 A A A A A A A A A A Hex
ess 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 Addr

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

You might also like