UNIT-III MICROCONTROLLERS
MICROCONTROLLERS AND EMBEDDED PROCESSORS – OVERVIEW
OF 8051 FAMILY. 8051 HARDWARE – I/O PINS – PORTS – CIRCUITS –
EXTERNAL MEMORY PROGRAMMING: DATA TYPES – I/O
PROGRAMMING – LOGIC OPERATIONS – DATA CONVERSION
PROGRAMS.
MICROCONTROLLERS AND EMBEDDED PROCESSORS:
Microcontrollers
A microcontroller is a small integrated circuit that contains a CPU, memory (RAM and
ROM), input/output ports, and timers on a single chip. It is designed to perform specific
control tasks in embedded systems.
Single chip containing CPU, memory, and peripherals
Used for dedicated applications
Low power consumption
Low cost and compact
Examples of Microcontrollers
1. Intel 8051 Microcontroller
2. ATmega328P Microcontroller
3. PIC16F877A Microcontroller
4. ARM Cortex-M3 Microcontroller
5. MSP430 Microcontroller
6. STM32F103 Microcontroller
Advantages of Microcontrollers
1. Compact Size – CPU, memory, and I/O ports are integrated on a single chip.
2. Low Cost – Requires fewer external components, reducing system cost.
3. Low Power Consumption – Suitable for battery-operated devices.
4. Easy to Interface – Built-in peripherals like timers, ADC, and communication ports.
5. Reliable Operation – Fewer components reduce hardware failure chances.
6. Simple Design – Easier to design and develop embedded systems.
Example: Intel 8051 Microcontroller
Disadvantages of Microcontrollers
1. Limited Processing Speed – Not suitable for very high-performance applications.
2. Limited Memory – RAM and ROM capacity is usually small.
3. Restricted Expansion – Limited ability to add external devices.
4. Not Suitable for Complex Systems – Cannot handle heavy computing tasks.
5. Less Flexibility – Designed mainly for specific applications.
Embedded Processors
An embedded processor is a specialized processor used inside embedded systems to
control and manage system operations. It may require external memory and peripherals to
function.
Designed for embedded system applications
May need external memory and components
Higher processing capability than simple microcontrollers
Used in complex systems like smartphones, networking devices, and multimedia
systems
Advantages of Embedded Processors
1. High Processing Speed – Suitable for complex and high-performance applications.
2. Supports Large Memory – Can interface with large external RAM and ROM.
3. Flexible Design – Can be used for many different embedded applications.
4. Better Performance – Capable of handling multitasking and complex computations.
5. Advanced Features – Supports operating systems and advanced peripherals.
Example: ARM Cortex-M Processor
Disadvantages of Embedded Processors
1. Higher Cost – Requires external memory and additional hardware components.
2. Higher Power Consumption – Consumes more power compared to microcontrollers.
3. Complex Design – System design and programming are more complicated.
4. Larger System Size – Needs more external components.
5. Longer Development Time – Development and debugging take more time.
Difference Between Microcontrollers and Embedded Processors
Feature Microcontroller Embedded Processor
Components CPU, memory, and I/O in one chip Mainly CPU; other components
external
Complexity Simple systems Complex systems
Cost Low cost Higher cost
Power Low Higher
Consumption
Application Small devices (washing machines, Advanced devices
remote controls) (smartphones, routers)
OVERVIEW OF 8051 FAMILY:
The Intel 8051 Microcontroller family is a group of 8-bit microcontrollers originally
developed by Intel in 1980. It is one of the most widely used microcontroller families in
embedded systems. The 8051 family includes different versions with improved memory,
speed, and features.
8-bit CPU for processing data.
4 KB on-chip ROM for program storage.
128 bytes of RAM for data storage.
32 Input/Output (I/O) pins for interfacing with external devices.
Two 16-bit timers/counters for timing operations.
Full duplex serial communication port.
Five interrupt sources for handling multiple tasks.
64 KB external program memory support.
Members of 8051 Family
Intel 8031 Microcontroller
Intel 8051 Microcontroller
Intel 8052 Microcontroller
AT89C51 Microcontroller
Applications
Industrial control systems
Home appliances
Automotive electronics
Communication devices
Embedded systems and automation
Block Diagram 8051 Microcontroller:
1. CPU (Central Processing Unit)
The CPU is the main part of the microcontroller that executes instructions and controls all
operations. It performs arithmetic and logical operations and coordinates communication
between different components.
2. Oscillator and Timing Circuit
The oscillator generates the clock signal required for the microcontroller to operate. It
determines the speed of instruction execution and synchronizes all internal operations.
3. Program Memory (ROM – 4096 Bytes)
The ROM stores the program instructions that the microcontroller executes. In the 8051, it
contains 4 KB of internal program memory for storing the firmware.
4. Data Memory (RAM – 128 Bytes)
The RAM stores temporary data and variables during program execution. The 8051
contains 128 bytes of internal RAM.
5. Two 16-bit Timers/Counters
The 8051 has two timers/counters (Timer 0 and Timer 1) used for:
Time delay generation
Event counting
Baud rate generation for serial communication
6. Programmable I/O Ports
The microcontroller has four 8-bit ports (P0, P1, P2, P3) that provide 32 input/output pins
for interfacing with external devices like sensors, LEDs, and motors.
7. Programmable Serial Port
The serial port (UART) allows serial communication between the microcontroller and
other devices. It supports full-duplex communication, meaning data can be transmitted and
received simultaneously.
8. Interrupt System
The interrupt system allows external or internal devices to interrupt the CPU to perform
urgent tasks. This improves the efficiency of the system.
9. Bus Expansion Control (64 KB)
This unit allows the 8051 to connect external memory up to 64 KB when internal memory
is not sufficient.
PIN Diagram of 8051 Microcontroller
8051 Microcontroller Pin Diagram Explanation
(Example: Intel 8051 Microcontroller)
1. Port 1 (Pins 1–8)
P1.0 to P1.7 pins.
Used as general purpose input/output pins.
No alternate functions.
Used to connect external devices like LEDs, switches, and sensors.
2. Reset Pin (Pin 9 – RST)
Used to reset the microcontroller.
When a high signal is applied, the program starts from the beginning.
3. Port 3 (Pins 10–17)
P3.0 to P3.7 pins.
Used as I/O pins and also have special functions.
Used for serial communication, interrupts, timers, and memory control signals.
4. Crystal Oscillator Pins (Pins 18–19)
XTAL1 and XTAL2 pins.
Used to connect an external crystal oscillator.
Provides clock signals for microcontroller operation.
5. Ground (Pin 20 – GND)
Used to connect the ground of the circuit.
6. Port 2 (Pins 21–28)
P2.0 to P2.7 pins.
Used as input/output port.
Also used as high-order address bus when external memory is connected.
7. Control Pins (Pins 29–31)
PSEN pin used for external program memory reading.
ALE pin used for address latch enable during memory interfacing.
EA pin used to select internal or external program memory.
8. Port 0 (Pins 32–39)
P0.0 to P0.7 pins.
Used as input/output port.
Also acts as multiplexed address and data bus.
9. Power Supply (Pin 40 – VCC)
Provides +5V power supply to the microcontroller.
8051 HARDWARE
The 8051 hardware refers to the internal components present inside the Intel 8051
Microcontroller.
It includes CPU, RAM, ROM, timers, serial communication unit, interrupt system,
and I/O ports.
The hardware allows the microcontroller to process data and control external devices.
It operates with an external crystal oscillator and uses pins to communicate with other
circuits.
The 8051 microcontroller has 40 pins used for power, input/output, control signals,
and communication.
Advantages
Integrated components like CPU, RAM, ROM, timers and I/O ports in a single chip.
Simple architecture and easy to understand.
Low cost and widely used in embedded systems.
Reliable for small control applications.
Supports interrupt and serial communication.
Disadvantages
Limited processing speed compared to modern microcontrollers.
Small memory capacity.
Limited number of peripherals.
Not suitable for complex or high-speed applications.
I/O PINS OF 8051
Input/Output (I/O) pins are used to connect the microcontroller with external
devices.
The 8051 microcontroller has 32 I/O pins.
These pins allow data to be sent from the microcontroller to external devices
(output) or received from devices (input).
I/O pins are grouped into four ports.
They can control LEDs, motors, switches, sensors, and displays.
Advantages
Allow communication between the microcontroller and external devices.
Flexible pins that can work as input or output.
Useful for connecting sensors, switches, LEDs, and displays.
Easy to control through programming.
Disadvantages
Limited number of I/O pins available.
Some pins have multiple functions which may cause conflicts.
External components may be required for proper operation.
Not suitable for high-power devices directly.
PORTS IN 8051
The 8051 microcontroller contains 4 ports, each having 8 pins.
1. Port 0 (P0.0 – P0.7)
o Dual-purpose port.
o Used as general I/O or low-order address/data bus during external memory
access.
o Requires external pull-up resistors.
2. Port 1 (P1.0 – P1.7)
o Simple general-purpose I/O port.
o Does not have any alternate functions.
3. Port 2 (P2.0 – P2.7)
o Used as general I/O.
o Also acts as high-order address bus when external memory is used.
4. Port 3 (P3.0 – P3.7)
o Works as general I/O.
o Each pin has special alternate functions such as interrupts, serial
communication, and control signals.
Advantages
Organized grouping of pins for easy data transfer.
Four ports provide 32 I/O lines.
Ports can be programmed as input or output.
Some ports support additional functions like interrupts and serial communication.
Disadvantages
Certain ports have special functions which restrict general usage.
Port 0 requires external pull-up resistors.
Limited number of ports for large applications.
Speed of data transfer is limited.
CIRCUITS IN 8051
The 8051 microcontroller contains several internal circuits that help it function properly.
Oscillator Circuit – Generates the clock signal required for microcontroller
operation.
Reset Circuit – Resets the microcontroller and starts program execution from the
beginning.
Memory Circuits – Includes internal ROM (program memory) and RAM (data
memory).
Timer/Counter Circuits – Used for timing operations and counting events.
Serial Communication Circuit – Enables communication with other devices using
serial data transmission.
Advantages
Internal circuits like oscillator, reset, timers improve performance.
Provides timing and synchronization for operations.
Supports serial communication and interrupts.
Reduces the need for many external components.
Disadvantages
Limited number of timers and counters.
Basic circuit design compared to modern controllers.
Limited flexibility for advanced applications.
External circuits may still be required for some functions.
EXTERNAL MEMORY PROGRAMMING IN 8051
External Memory Programming in the Intel 8051 Microcontroller is the process of using
external memory devices such as ROM or RAM to store and execute programs when the
internal memory of the microcontroller is not sufficient. The 8051 can access up to 64 KB of
external memory using Port 0, Port 2, and control signals like PSEN, ALE, and EA for
memory interfacing.
External Program Memory Support
The 8051 can access up to 64 KB of external program memory.
Use of Port 0
Port 0 (P0.0–P0.7) works as a multiplexed address and data bus (AD0–AD7).
Use of Port 2
Port 2 (P2.0–P2.7) provides the higher order address lines (A8–A15).
Program Store Enable (PSEN)
PSEN pin is used to read instructions from external program memory.
Address Latch Enable (ALE)
ALE pin is used to separate the address and data signals coming from Port 0.
External Access Pin (EA)
EA pin determines whether the microcontroller uses internal memory or external
program memory.
External RAM Support
The 8051 can also connect external RAM for storing temporary data.
Memory Interfacing
External memory is connected through address bus, data bus, and control signals.
Use of Latch Circuit
A latch (like 74LS373) is used to store the lower address from Port 0 during
multiplexing.
Flexibility
Allows developers to increase program size and improve system capability.
Advantages
Increases memory capacity.
Suitable for large programs and data storage.
Flexible memory expansion.
Improves program capability.
Disadvantages
Requires additional external hardware.
Increases system cost and complexity.
Slower access compared to internal memory.
Benefits of External Memory Programming in 8051
Large Program Storage – Allows the use of up to 64 KB of external program
memory.
Memory Expansion – Increases the memory capacity beyond the internal memory of
the microcontroller.
Supports Complex Programs – Useful for large and complex embedded
applications.
Flexible System Design – External memory can be added or modified based on
application requirements.
Improved Performance – Enables the microcontroller to handle more instructions
and data efficiently.
Easy Program Modification – Programs stored in external memory can be updated
or replaced easily.
Better Data Handling – External RAM allows storage of large amounts of data
during program execution.
DATA TYPES IN 8051
Definition:
Data types in the 8051 microcontroller define the type and size of data that can be processed
by the processor during programming.
Explanation:
Since the 8051 is an 8-bit microcontroller, most operations are performed on 8-bit data.
Different data types help programmers store and manipulate values in memory.
Common Data Types
1. Byte (8-bit Data)
o Most commonly used data type.
o Can store values from 00H to FFH (0–255).
2. Bit Data Type
o Used for bit-level operations.
o Each bit can store 0 or 1.
o Useful for control operations like turning devices ON or OFF.
3. Unsigned Integer
o Used to store only positive values.
o Range depends on memory size.
4. Signed Integer
o Used to store both positive and negative numbers.
5. Boolean Data Type
o Represents true or false values.
Advantages
Efficient use of memory.
Supports bit manipulation operations.
Suitable for control-oriented applications.
Easy to implement in embedded programming.
Disadvantages
Limited data size support.
No direct floating-point support.
Complex calculations require additional programming.
I/O PROGRAMMING IN 8051
Definition:
I/O programming in the 8051 microcontroller is the process of controlling input and output
devices through its ports using software instructions.
Explanation:
The 8051 microcontroller has 32 input/output pins, organized into four ports (Port 0, Port
1, Port 2, Port 3). These ports allow communication with external devices such as switches,
LEDs, displays, sensors, and motors.
Each port can be programmed as input or output.
Examples of I/O Programming
Reading input from switches.
Sending signals to LEDs.
Controlling motors or relays.
Interfacing with sensors.
Basic I/O Operation
Input Operation: Microcontroller reads data from external device.
Output Operation: Microcontroller sends data to external device.
Advantages
Easy connection with external hardware devices.
Flexible input and output control.
Supports digital interfacing.
Useful in automation and embedded systems.
Disadvantages
Limited number of I/O pins.
Cannot directly drive high-power devices.
Some pins have multiple alternate functions.
External components may be required.
LOGIC OPERATIONS IN 8051
Definition:
Logic operations in the 8051 microcontroller perform logical calculations on data at bit level
or byte level.
Explanation:
Logical instructions are used to compare, combine, or manipulate bits in registers or memory
locations. These operations are important for decision making in programs.
Common Logic Operations
1. AND Operation (ANL)
o Combines two bits and produces 1 only if both bits are 1.
2. OR Operation (ORL)
o Produces 1 if any one of the bits is 1.
3. Exclusive OR (XRL)
o Produces 1 when bits are different.
4. Complement (CPL)
o Changes 1 to 0 and 0 to 1.
5. Clear Operation (CLR)
o Clears the value of a register or bit.
Advantages
Efficient bit-level data manipulation.
Useful for control and decision making.
Improves program logic and efficiency.
Important for digital system operations.
Disadvantages
Limited to simple logical operations.
Complex logical tasks require multiple instructions.
Requires careful programming to avoid errors.
DATA CONVERSION PROGRAMS IN 8051
Definition:
Data conversion programs in the 8051 microcontroller convert data from one format to
another so that it can be processed or displayed properly.
Explanation:
Different devices use different data formats. For example, sensors may provide data in
binary, while displays may require ASCII or BCD format. Data conversion programs
transform the data into the required format.
Common Types of Data Conversion
1. Binary to BCD Conversion
o Used when displaying numeric values on displays.
2. BCD to Binary Conversion
o Converts BCD data into binary format for calculations.
3. ASCII to Binary Conversion
o Converts character data into numeric values.
4. Binary to ASCII Conversion
o Used for displaying numbers as characters.
Applications
Digital displays
Data communication systems
Embedded device interfacing
Measurement systems
Advantages
Improves compatibility between devices.
Helps in data display and communication.
Enables processing of different data formats.
Disadvantages
Requires extra program instructions.
Increases execution time slightly.
Complex conversions require longer programs.
Example: Binary to BCD Conversion Program
Program (8051 Assembly Language)
ORG 0000H
MOV A, #45H ; Load binary number (example value)
MOV B, #0AH ; Load divisor 10
DIV AB ; Divide A by B
MOV R0, A ; Quotient (tens digit)
MOV R1, B ; Remainder (units digit)
END
Explanation
MOV A, #45H → Loads a binary value into the accumulator.
MOV B, #0AH → Loads 10 (decimal base for BCD conversion).
DIV AB → Divides the value in A by B.
Quotient (A) represents the tens digit.
Remainder (B) represents the units digit.
These two values together represent the BCD form of the binary number.
Example Result
Binary value = 45
After conversion → 4 (tens) and 5 (units)
BCD Output = 45
Another Example: ASCII to Binary Conversion
Program
ORG 0000H
MOV A, #'5' ; Load ASCII character '5'
ANL A, #0FH ; Convert ASCII to binary
END
Explanation
ASCII value of '5' = 35H
ANL A, #0FH removes the upper bits.
Final result = 05H (Binary value 5).