0% found this document useful (0 votes)
528 views18 pages

01 MC Module-01 Notes 2023-24

Uploaded by

sahana
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)
528 views18 pages

01 MC Module-01 Notes 2023-24

Uploaded by

sahana
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/ 18

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:

Harvard Architecture:

 The 8051 utilizes a Harvard architecture, meaning it has separate memory spaces for program instructions
(ROM) and data (RAM).
 This separation allows for concurrent fetching of instructions and data, improving performance compared
to a single memory space design.

Internal Memory:

 On-chip program memory (ROM): Typically, 4KB in older models, used to store program instructions.
 On-chip data memory (RAM): Usually 128 bytes, used for storing temporary data during program
execution.

Central Processing Unit (CPU):

 The CPU is the core processing unit that executes instructions fetched from ROM.
 It performs arithmetic, logical, and data transfer operations.
 The 8051 CPU has an 8-bit data path, meaning it can process 8 bits of data at a time.
 It also has a 16-bit address bus, allowing it to access up to 64KB of memory (though typically only 4KB
of ROM is on-chip).

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.

I/O Ports:

 The 8051 has four 8-bit I/O ports (P0, P1, P2, and P3).
 These ports allow the microcontroller to interact with external devices like sensors, actuators, and displays.
 Each pin of a port can be configured as input or output.

Instruction Set:

 The 8051-instruction set is relatively simple, consisting of basic arithmetic, logical, and data transfer
instructions.
 This simplicity makes it easier to learn and program compared to more complex architectures.
Applications:

 Due to its simple architecture and low cost, the 8051 is a popular choice for educational purposes and
hobbyist projects.
 It's also found in various embedded systems applications such as simple industrial controls, robotics, and
data acquisition systems.

The 8051 architecture is known for its simplicity, reliability, and ease of use, making it an ideal choice for
a wide range of embedded systems and microcontroller applications.
1.6 An 8051 Microcontroller Registers

The 8051 microcontroller utilizes a set of registers to store data and control its operations. These registers
can be broadly categorized into two main types:

1. General Purpose Registers (GPRs):


 Include Accumulator (A), B register, and R registers (R0 to R7).
 Used for storing temporary data during program execution.
 Accumulator (A) plays a special role in most arithmetic and logical operations.
2. Special Function Registers (SFRs): A collection of on-chip memory locations that control various
functionalities of the microcontroller. Examples include:
 Program Status Word (PSW): Holds flags indicating the outcome of arithmetic and logical
operations.
 Stack Pointer (SP): Points to the top of the stack, a temporary storage area used for subroutine calls
and data manipulation.
 Data Pointer (DPTR): A 16-bit register that can be used as two separate 8-bit registers for data
transfers.
 Timer/Counter Registers (TMOD and timers TH0, TL0, TH1, TL1): Used for timing and pulse-
width modulation generation.
 Serial Communication Registers (SCON, SBUF): Facilitate serial communication with external
devices.
 I/O Port Registers (P0, P1, P2, P3): Control the data direction (input/output) of each pin on the
corresponding I/O port.

Here's a breakdown of some key registers:

 Accumulator (A): An 8-bit register that is the primary operand (data source or destination) for
most arithmetic and logical operations within the CPU.
 B register: Another 8-bit register used for general-purpose data storage and can participate in some
operations along with the accumulator.
 R registers (R0 to R7): Eight 8-bit registers that provide additional general-purpose data storage.
 Program Status Word (PSW): A 1-byte register containing flags that reflect the status of the CPU
after operation execution. These flags include Carry flag, Parity flag, Auxiliary Carry flag, and
Zero flag, useful for conditional branching and program flow control.
 Stack Pointer (SP): A 16-bit register that keeps track of the top of the stack, a Last-In-First-Out
(LIFO) data structure used for subroutine calls, temporary data storage, and parameter passing.
 Data Pointer (DPTR): A 16-bit register that can be functionally divided into two 8-bit registers
(DPH and DPL). It's primarily used for data transfers between memory and peripherals.
 I/O Port Registers (P0, P1, P2, P3): Each 8-bit register controls an 8-bit I/O port of the
microcontroller. Each bit in the register corresponds to a pin on the port, which can be configured
as input or output.

Understanding these registers is essential for programming the 8051 effectively. These registers provide
a way to control the microcontroller's behavior, manipulate data, and interact with external devices.

1.7 Pin diagram of 8051Microcontroller

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 I/O ports functions in 8051 Microcontroller

The 8051 microcontroller boasts four I/O ports (P0, P1, P2, and P3) that play a crucial role in communication
with the external world. Here's a detailed breakdown of their functions:

General Functionality:

 Each port is an 8-bit register, meaning it can handle 8 bits of data (0 or 1) at a time.
 Individual pins within a port can be configured as either inputs or outputs.
 This bi-directional nature allows the microcontroller to both receive data from sensors (input) and send
data to actuators (output).

Specific Functions of Each Port:

1. Port 0 (P0):
 Primarily functions as an 8-bit I/O port for general-purpose usage.
 In some configurations, the lower address bus (A0 to A7) shares pins with P0 during external
memory access. This feature requires careful configuration to avoid conflicts.
2. Port 1 (P1):
 Strictly an I/O port for general-purpose applications.
 It doesn't have any alternate functions like shared address bus duties.
 Often used for interfacing with simple buttons, LEDs, or other digital devices due to its dedicated I/O
nature.
3. Port 2 (P2):
 Functions as an 8-bit I/O port but also shares its upper 4 bits (P2.4 to P2.7) with the address bus (A8
to A11) for external memory access.
 Similar to P0, careful configuration is needed to avoid conflicts during memory operations.
4. Port 3 (P3):
 Most versatile port with various functionalities besides basic I/O.
 Lower 4 bits (P3.0 to P3.3) can be used for general-purpose I/O.
 Upper 4 bits (P3.4 to P3.7) have multiple functions depending on the application:
 Interrupt inputs (INT0, INT1) for responding to external events.
 Timer/counter inputs for timing-related operations.
 Serial communication pins (SCK, MOSI, MISO) for transmitting and receiving data serially.

Configuring I/O Ports:

 Special Function Registers (SFRs) within the 8051 microcontrollers control the configuration of I/O ports
(input/output mode).
 By setting specific bits in these SFRs, you can define whether a particular pin will be input or output.

Applications of I/O Ports:

 Reading data from sensors (e.g., temperature sensor, button press).


 Sending control signals to actuators (e.g., turning on an LED, controlling motor speed).
 Serial communication with other devices for data exchange.

Key Points to Remember:

 Understand the pin configuration (input/output) for each port before connecting external devices.
 Be mindful of potential address bus conflicts with Ports 0 and 2 during external memory access.
 Utilize SFRs to control the I/O functionality of each port.

By effectively using these I/O ports, you can unleash the potential of the 8051 microcontrollers to interact with
various external components and build real-world embedded systems applications.
1.9 Internal Memory organization of 8051 Microcontroller

The 8051 microcontroller utilizes a Harvard architecture, meaning it separates program instructions and data
storage. This allows for concurrent fetching of instructions and data, improving performance compared to a single
memory space design. Here's a breakdown of the internal memory organization:

Program Memory (ROM):

 On-chip, typically 4KB in older models, though variants can have more.
 Stores the program instructions that the microcontroller executes.
 Not directly writable by the user program. The program is written into ROM during the manufacturing
process or through special programming techniques.

Data Memory (RAM):

 On-chip, usually 128 bytes (though some variants may have more).
 Stores temporary data used during program execution, such as variables, intermediate results, and stack
data.
 Accessible by the user program for reading, writing, and manipulation.
Internal RAM Organization:

 The 128 bytes of internal data memory are further divided into two sections:

Special Function Registers (SFRs):

 Occupy the lower address range (typically 00h to 1Fh).


 Each SFR is a small memory location (usually 8-bit) that controls various functionalities of the
microcontroller.

Examples include:

 Program Status Word (PSW): Holds flags indicating outcomes of operations.


 Stack Pointer (SP): Tracks the top of the stack for subroutine calls and data storage.
 Timers/Counters: Used for timing and pulse-width modulation.
 Serial Communication: Facilitate communication with external devices.
 I/O Port control registers: Manage data direction (input/output) for each I/O pin.

Scratchpad RAM:

 Occupies the upper address range (typically 20h to 7Fh).


 Provides general-purpose data storage for user programs.
 This is the primary RAM space where you can store variables, perform calculations, and manipulate data
during program execution.

Stack (Optional):

 The stack is a Last-In-First-Out (LIFO) data structure typically implemented within the internal RAM
(often in the scratchpad area).
 It's used for subroutine calls, temporary data storage, and parameter passing.
 The Stack Pointer (SP) register keeps track of the top of the stack.

Addressing Memory:

 The 8051 has a 16-bit address bus, but the internal data memory only occupies the lower 8 bits (addresses
00h to 7Fh).
 Separate instructions are used to access SFRs and data memory locations.

Key Points:

 Program memory (ROM) stores permanent instructions.


 Data memory (RAM) stores temporary data during program execution.
 SFRs control various functionalities of the microcontroller.
 Scratchpad RAM provides general-purpose data storage for user programs.
 The stack (implemented in RAM) is used for subroutine calls and temporary data.

Understanding this internal memory organization is essential for effective 8051 programming. It helps you
allocate memory for instructions, data, and SFRs, and ensures you're using the appropriate memory space for
different purposes.
1.10 External Memory (ROM & RAM) interfacing 8051 Microcontroller

The 8051 microcontroller's internal memory (ROM and RAM) capacity might be limiting for complex
applications. To expand its capabilities, you can interface external memory devices like ROM and RAM.

1.10.1 External ROM (Program Memory) Interfacing

Interfacing external ROM (Read-Only Memory) with the 8051 microcontroller involves connecting the ROM
chip to the microcontroller and configuring the microcontroller to access the ROM for program code. The below
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 ROM is used to store program code that the 8051 will execute.
 To interface external ROM with the 8051, connect the address bus (A0-A15), data bus (D0-D7), and
control signals (PSEN, ALE/PROG) of the 8051 to the corresponding pins of the external ROM chip.
 Configure the PSEN (Program Store Enable) and ALE/PROG (Address Latch Enable/Program) signals to
properly access the external ROM.
 Use the MOVX instruction to read instructions from the external ROM.

Example Code:

 To read instructions from the external ROM, you can use the MOVX instruction in your 8051-assembly
code:

MOVX A, @DPTR ; Read data from external ROM into accumulator


1.10.2 External RAM (Data Memory) Interfacing

Interfacing external RAM (Random Access Memory) with the 8051 microcontroller involves connecting the
RAM chip to the microcontroller and configuring the microcontroller to access the RAM for data storage and
retrieval.

The below 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.
 External RAM is used to store data that the 8051 will manipulate during program execution.
 To interface external RAM with the 8051, connect the address bus (A0-A15), data bus (D0-D7), and
control signals (RD, WR, ALE/PROG) of the 8051 to the corresponding pins of the external RAM chip.
 Configure the RD (Read), WR (Write), and ALE/PROG signals to properly access the external RAM.
 Use MOVX instructions to read from and write to the external RAM.

Example Code:

 To read data from and write data to the external RAM, you can use the MOVX instruction in your 8051-
assembly code:

MOVX A, @DPTR ; Read data from external RAM into accumulator

MOVX @DPTR, A ; Write data from accumulator to external RAM

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.

You might also like