UNIT I
UNIT I
Microcontroller vs Microprocessor
Microprocessor
• A CPU (Central Processing Unit) on a single chip
• General-purpose device
• Needs external components for:
o RAM
o ROM
o I/O ports
o Timers, etc.
• Used in computing applications like:
o PCs
o Laptops
o Servers
Characteristics
Microcontroller
• A complete computer on a chip
• Contains:
o CPU
o RAM
o ROM (Flash)
o I/O ports
o Timers/Counters
o ADC/DAC
• Used in embedded applications like:
o Washing machines
o Microwave ovens
o IoT devices
o Robotics
Characteristics
Comparison Table
Feature Microprocessor Microcontroller
Application General purpose Embedded systems
On-chip Memory No Yes (RAM, ROM)
I/O Ports External Built-in
Cost High Low
Power Consumption High Low
Speed High (GHz) Medium (MHz)
Development Complex (more parts) Simple (single chip)
Example Devices Intel i7, AMD Ryzen 8051, Arduino, STM32
Summary
• Use Microprocessors for computing-heavy tasks (PCs, servers).
• Use Microcontrollers for device control in embedded systems.
8-bit Microcontroller
Definition
An 8-bit microcontroller is a microcontroller whose data bus and ALU are 8-bits wide,
meaning it processes 8 bits of data at a time.
Key Features
• 8-bit ALU → processes 8-bit data
• 8-bit Data Bus
• 16-bit Address Bus (can access 64KB memory)
• On-chip ROM, RAM, I/O ports, Timers, Counters
• Typically includes:
o UART/USART (for serial communication)
o ADC (Analog to Digital Converter)
o Interrupt controller
• Operates in the MHz range
• Low power consumption
Advantages
• Low cost
• Simple instruction set (easy to program)
• Compact and reliable
• Suitable for small embedded applications
Limitations
• Slower than 16/32-bit MCUs
• Limited memory and peripheral support
• Not suitable for complex computations (like image/video processing)
Summary
• 8-bit microcontrollers are ideal for simple, low-power embedded systems.
• Still widely used due to low cost, ease of use, and availability.
1. Overview
• The 8051 microcontroller is an 8-bit microcontroller developed by Intel.
• It is a Harvard architecture MCU with separate memory spaces for program and
data.
• Uses 8-bit ALU and registers.
• Has a 16-bit address bus for program memory (up to 64KB) and data memory.
2.6 Timers/Counters
• Two 16-bit timers/counters: Timer 0 and Timer 1.
• Can be configured as timer (count internal clock pulses) or counter (count external
events).
• Used for measuring time intervals, generating baud rates, etc.
• 5 sources of interrupts:
1. External Interrupt 0 (INT0)
2. Timer 0 Overflow
3. External Interrupt 1 (INT1)
4. Timer 1 Overflow
5. Serial Communication Interrupt
• Interrupts can be enabled/disabled via IE (Interrupt Enable) register.
• Priorities assigned via IP (Interrupt Priority) register.
3. Block Diagram
4. Key Architectural Features
• Harvard Architecture: Separate code and data memories improve speed.
• Bit Addressable Memory: Allows individual bit manipulation in certain RAM areas
and SFRs.
• Power Saving Modes: Idle and Power-down modes for low power consumption.
• Stack: Uses internal RAM; stack grows upward from address 08H.
5. Working Flow
• Fetch instruction from program memory.
• Decode and execute instruction using CPU.
• Use ALU for arithmetic and logic.
• Access data from internal/external RAM via data bus.
• Use peripherals as per instruction or interrupts.
Types of Instructions:
Instruction Format:
Programming Concepts:
5. Important Notes
• Efficiency matters: Code size and speed are crucial in embedded.
• Use hardware-specific headers to access registers.
• Debugging often done via simulators or hardware debuggers.
• Interrupts and concurrency require careful programming.
1. Arithmetic Instructions
Purpose:
Common Instructions:
Instruction Function Example
ADD Adds two operands ADD R1, R2 (R1 = R1 + R2)
SUB Subtracts one operand from another SUB R3, #5 (R3 = R3 - 5)
MUL Multiplies operands MUL R1, R2
DIV Divides operands DIV R4, R5
INC Increment operand by 1 INC R1
DEC Decrement operand by 1 DEC R2
NEG Negates (two’s complement) NEG R1
2. Logical Instructions
Purpose:
Common Instructions:
Common Instructions:
Common Instructions:
5. Bit-Oriented Instructions
Purpose:
Common Instructions:
Characteristics:
Example pseudo-steps:
Port Characteristics:
Pin
Pin Name Function Description
Number
1-8 P1.0–P1.7 Port 1 I/O pins — general purpose I/O with internal pull-ups
9 RST Reset pin — active high, resets the MCU on logic 1
Port 3 I/O pins — with alternate functions (UART, interrupts,
10-17 P3.0–P3.7
timers)
XTAL2,
18-19 Crystal oscillator pins — connect crystal/resonator
XTAL1
20 GND Ground pin
Port 2 I/O pins — high byte address bus in external memory
21-28 P2.0–P2.7
mode
Program Store Enable — read signal for external program
29 PSEN
memory
Address Latch Enable — latch demultiplexes address/data on
30 ALE
Port 0
External Access Enable — enable external program memory
31 EA
(active low)
Port 0 I/O pins — low byte address/data bus in external memory
32-39 P0.0–P0.7
mode (no internal pull-ups)
40 VCC Power supply +5V
Notes:
Summary:
Topic Key Points
Parallel Port Multiple bits transferred simultaneously, configure direction,
Programming read/write data.
4 ports (P0-P3), each 8 bits, some with special functions, P0 needs
8051 Ports
external pull-ups.
Write to port for output, read from port for input; internal/external
Port Programming
pull-ups important.
40-pin IC; pins assigned to ports, reset, oscillator, memory control,
Pin Configuration
and special functions.
8051 Timers
Introduction
• 8051 Microcontroller has two 16-bit timers:
o Timer 0
o Timer 1
• Can operate as:
o Timers – count internal clock pulses.
o Counters – count external events (via T0 and T1 pins).
• Used for generating delays, baud rates, event counting, etc.
Timer Registers
Each timer uses two 8-bit registers:
Bits Use
GATE 1: External interrupt start
C/T 0 = Timer, 1 = Counter
M1,M0 Select mode (0 to 3)
| GATE | C/T | M1 | M0 | GATE | C/T | M1 | M0 |
T1 T0
Timer Clock
• 8051 uses a 12 MHz crystal.
• 1 machine cycle = 12 clock cycles → Timer increments every 1 µs.
• Max count in 16-bit mode = 65536 → Delay = 65536 µs = 65.5 ms
Applications of Timers
• Generating time delays
• Creating waveforms (square wave, etc.)
• Counting external pulses
• Baud rate generation for serial communication
• Measuring pulse width
Introduction
• The 8051 microcontroller has one full-duplex serial port.
• Used for asynchronous (UART) and synchronous communication.
• Data transmission and reception is serial (bit-by-bit).
• Controlled by SBUF, SCON, PCON, and Timer 1.
• Bit 7 = SMOD
o If SMOD = 1, doubles baud rate in Modes 1, 2, and 3.
Reception
1. Introduction to Interrupts
• Interrupt: A signal to the CPU to pause current execution and jump to a special
routine (Interrupt Service Routine - ISR).
• Allows the microcontroller to respond immediately to important events.
• Improves efficiency by avoiding continuous polling.
Bit Bit
Bit 7 (EA) 6 Bit 5 (ES) Bit 4 (ET1) Bit 3 (EX1) Bit 2 (ET0) Bit 1 (EX0) 0
(—) (—)
Global Serial Timer 1 External Timer 0 External
enable/disable — Interrupt Interrupt Interrupt 1 Interrupt Interrupt 0 —
interrupt Enable Enable Enable Enable Enable
5. Interrupt Priority
• Managed by IP (Interrupt Priority) register.
• Allows assigning high or low priority to each interrupt.
• Higher priority interrupt can interrupt a lower priority ISR.
• Bits in IP register correspond to interrupts similar to IE.
12. Summary
• 8051 has 5 interrupt sources with vector addresses.
• Controlled by IE and IP registers.
• Supports priority and nested interrupts.
• Interrupts improve real-time capabilities.