eiot u1 i line

Microprocessor: CPU only. Needs external memory and peripherals.

Microcontroller: CPU + memory + peripherals in one chip.

๐Ÿ“˜ Formal Definition (8051 Microcontroller)

The 8051 microcontroller is an 8-bit microcontroller developed by Intel, widely used in embedded systems. It includes a CPU, RAM, ROM, I/O ports, timers, serial communication, and interrupt control, all integrated on a single chip, making it suitable for control-oriented embedded applications.


๐Ÿ” Features of 8051 Microcontroller (as per CS3691):

  1. 8-bit processor: Can process 8 bits of data at a time.

  2. Clock speed: Typically 12 MHz.

  3. Memory:

    • 4 KB on-chip ROM (program memory)

    • 128 bytes on-chip RAM (data memory)

  4. I/O Ports: 4 parallel I/O ports (each 8-bit) – total 32 I/O lines.

  5. Timers: Two 16-bit timers/counters (Timer 0 and Timer 1).

  6. Interrupts: 5 interrupt sources.

  7. Serial Communication: One full-duplex UART.

  8. On-chip oscillator and clock circuitry.

  9. Harvard Architecture: Separate memory for program and data.

  10. Bit as well as byte addressable RAM.

๐Ÿง  Introduction to 8051 Architecture

The 8051 is an 8-bit microcontroller with a Harvard architecture. It integrates a CPU, RAM, ROM, I/O ports, timers, serial communication, and interrupt control—ideal for embedded control applications.


๐Ÿงฉ Block Diagram Overview

The block diagram typically includes:

  • CPU (with ALU and registers)

  • 4 I/O Ports (P0–P3)

  • Program Memory (ROM)

  • Data Memory (RAM)

  • Timers/Counters (T0, T1)

  • Serial Port (TxD, RxD)

  • Interrupt Control

  • Oscillator & Clock Circuit

  • Internal Buses


๐Ÿงฌ Internal Components Overview

  1. CPU (Central Processing Unit)

  2. ALU (Arithmetic and Logic Unit)

  3. Registers (A, B, PSW, SP, PC, DPTR)

  4. ROM (4KB) and RAM (128B)

  5. Timers – T0 and T1

  6. Serial port

  7. Interrupt system

  8. Oscillator and clock


๐Ÿงฎ Central Processing Unit (CPU)

Coordinates all operations: fetching, decoding, executing instructions.

Arithmetic and Logic Unit (ALU)

Performs arithmetic (add, subtract) and logical (AND, OR, etc.) operations.


๐Ÿงพ CPU Registers Overview

๐Ÿ…ฐ️ Register A (Accumulator)

Primary register for arithmetic, logic, and data movement.

๐Ÿ…ฑ️ Register B

Used during multiplication/division and temporary storage.

๐Ÿ”ข Data Pointer (DPTR)

16-bit: split into DPH (high byte) and DPL (low byte); used to access external memory.

๐Ÿ“ Program Counter (PC)

16-bit; points to the next instruction to execute.

๐Ÿ” Stack Pointer (SP)

8-bit; points to the top of the stack (default value: 07H).


๐Ÿ Flag Register & PSW (Program Status Word)

๐Ÿณ️ Flag Bits:

  • CY – Carry

  • AC – Auxiliary Carry

  • F0 – User-defined

  • RS1, RS0 – Register bank select

  • OV – Overflow

  • P – Parity

๐Ÿงฉ PSW Bit Pattern:

text
CY | AC | F0 | RS1 | RS0 | OV | — | P

๐Ÿ—ƒ️ Register Bank Selection:

  • RS1 RS0 = 00 → Bank 0

  • RS1 RS0 = 01 → Bank 1

  • RS1 RS0 = 10 → Bank 2

  • RS1 RS0 = 11 → Bank 3


๐Ÿง  Memory Organization

๐Ÿ“‚ Data Memory (RAM)

  • 128 Bytes Internal RAM:

    • 00H–1FH: Working registers

    • 20H–2FH: Bit-addressable

    • 30H–7FH: General purpose

๐Ÿ“„ Program Memory (ROM)

  • 4KB internal ROM for code storage

๐Ÿ”„ Memory Mapping and Bus

  • Harvard architecture (separate buses)

  • Internal data bus for internal transfers


๐Ÿ–ง I/O Ports

๐Ÿ”Œ 4 x 8-bit Ports

  • P0: Dual role (I/O & address/data lines for external memory)

  • P1: General-purpose I/O

  • P2: Used for high-order address in external memory

  • P3: Alternate functions (RxD, TxD, INT, T0, T1)

๐Ÿ“ Bit/Byte Addressing

  • Some ports are bit-addressable (e.g., P1.0, P1.1...)


๐Ÿ“‹ Special Function Registers (SFRs)

๐Ÿ› ️ Definition:

Registers that control functions (e.g., timers, serial, I/O).

๐Ÿ“Š SFR Address Range: 80H–FFH

๐Ÿ”˜ Bit-addressable SFRs:

  • Accumulator (A), B register, PSW, Ports (P0–P3), IE, IP, etc.


⏱️ Timers and Counters

Timer 0 & Timer 1

  • 16-bit each

  • Modes: 13-bit, 16-bit, 8-bit auto-reload

⚙️ Control Registers

  • TCON: Timer control

  • TMOD: Mode control


๐Ÿ“จ Serial Communication

๐Ÿ” Serial Port:

  • TxD (transmit), RxD (receive)

๐Ÿ“ก Control Registers:

  • SCON – Serial Control

  • SBUF – Serial data buffer


๐Ÿšจ Interrupt System

Sources:

  • INT0, INT1 (external)

  • T0, T1 (timers)

  • Serial port

๐Ÿงญ SFRs for Interrupts:

  • IE (Interrupt Enable)

  • IP (Interrupt Priority)


⏲️ Oscillator and Clock

  • Frequency Range: 4–30 MHz (standard: 12 MHz)

  • Uses external crystal oscillator


๐Ÿ”— Bus System

๐ŸšŒ Internal Bus:

Transfers data between CPU and internal components.

๐Ÿ”Œ External Bus:

For interfacing with external memory/peripherals.


๐Ÿ“˜ 8051 Microcontroller: Pin Description — Topics & Subtopics


๐Ÿ”ท 1. 8051 Pin Overview

  • Total of 40 pins

  • Packaged in a 40-pin Dual Inline Package (DIP)

  • Some pins have multiplexed or alternate functions


๐Ÿ”ท 2. I/O Ports (32 pins total)

Port 0 (Pins 32–39)

  • Dual function:

    • General-purpose I/O

    • Time-multiplexed Address/Data bus (AD0–AD7) for external memory

  • Requires external pull-up resistors for I/O operations

Port 1 (Pins 1–8)

  • General-purpose I/O only

  • Not multiplexed

  • Internally pulled up

Port 2 (Pins 21–28)

  • High-order address lines (A8–A15) during external memory access

  • Acts as general-purpose I/O when external memory is not used

Port 3 (Pins 10–17)

  • Multifunctional port: I/O + alternate functions

๐Ÿ” Port 3 Alternate Functions
PinNameAlternate Function
10P3.0RXD – Serial input
11P3.1TXD – Serial output
12P3.2INT0 – External interrupt 0
13P3.3INT1 – External interrupt 1
14P3.4T0 – Timer 0 input
15P3.5T1 – Timer 1 input
16P3.6WR – Write signal for external memory
17P3.7RD – Read signal for external memory


๐Ÿ”ท 3. Power Supply Pins
PinNameDescription
40Vcc+5V DC power supply
20VssGround

๐Ÿ”ท 4. Oscillator Pins

PinNameFunction
19XTAL1Input to internal oscillator (from crystal)
18XTAL2Output from internal oscillator


Typically connected to a 12 MHz crystal

๐Ÿ”ท 5. Control and Special Function Pins

PinNameDescription
9RSTReset input (active HIGH) – resets microcontroller
30ALEAddress Latch Enable – de-multiplexes address/data from Port 0
29PSENProgram Store Enable – read strobe for external program memory
31EAExternal Access – low: external ROM, high: internal ROM


๐Ÿ”ท 1. Total Accessible Memory Range

Type of MemorySizeAddress Range
Program Memory64 KB0000H – FFFFH
Data Memory64 KB0000H – FFFFH

๐Ÿ”ท 2. Internal Memory Capacities

Memory TypeSize
Internal ROM (Program)4 KB
Internal RAM (Data)256 bytes

๐Ÿ“„ 3. Program Memory (ROM/EPROM)

Internal Program Memory

  • Size: 4KB

  • Address Range: 0000H – 0FFFH

  • Stores program instructions

  • Accessed when EA pin is HIGH

External Program Memory

  • Size: Up to 64KB

  • Address Range: 0000H – FFFFH

  • Accessed when EA pin is LOW

  • PSEN signal is used to enable external ROM


๐Ÿ”Œ 4. EA (External Access) Pin Functionality

EA PinFunction
EA = 1Use internal 4KB ROM
EA = 0Access full external ROM (up to 64KB)

๐Ÿ“ฆ 5. Data Memory (RAM)

Internal RAM (256 bytes total)

Split into two parts:

RangeAccess TypeDescription
00H – 7FHDirect & IndirectLower 128 bytes
80H – FFHIndirect onlyUpper 128 bytes – SFR area

๐Ÿ” 6. Internal RAM Organization (00H–7FH)

RangeSectionDetails
00H–1FHRegister Banks4 banks × 8 registers (R0–R7)
20H–2FHBit Addressable Area16 bytes → 128 addressable bits
30H–7FHGeneral Purpose RAMFor variables, temporary data, stack

๐Ÿ—‚️ 7. Register Banks (00H–1FH)

BankPSW Bits RS1 RS0Address Range
Bank 00000H–07H
Bank 10108H–0FH
Bank 21010H–17H
Bank 31118H–1FH
➡️ Selected using RS1 and RS0 bits in PSW register

๐ŸŽฏ 8. Bit Addressable Area (20H–2FH)

  • 16 bytes → 128 bits (bit addresses: 00H – 7FH)

  • Each byte has 8 bits that can be accessed individually

  • Useful for flags, control bits, etc.


๐Ÿ“Œ 9. General Purpose RAM (30H–7FH)

  • 80 bytes of RAM

  • Used for general data storage, temporary variables, etc.

  • Also used for stack (default stack starts at 07H)


๐Ÿงพ 10. Special Function Registers (SFRs)

  • Located from 80H to FFH

  • Control and status registers for:

    • Timers, Serial, I/O, Interrupts, etc.

  • Byte-addressable

  • Some are also bit-addressable (e.g., P0, P1, PSW, IE)


๐Ÿ” 11. Bank Selection Logic (PSW – Program Status Word)

RS1RS0Selected Bank
00Bank 0 (00H–07H)
01Bank 1 (08H–0FH)
10Bank 2 (10H–17H)
11Bank 3 (18H–1FH)

๐Ÿ“˜ 8051 Microcontroller: Stack – Definition and Purpose


๐Ÿ”ท 1. Definition and Purpose

The stack is a temporary storage area in internal RAM used to store data during program execution, especially:

  • Return addresses from subroutines

  • Temporary register values during interrupts or nested function calls

It operates using the LIFO principle (Last In, First Out).


๐Ÿ”ท 2. Role of the Stack in 8051

  • Helps in quick storage and retrieval of data

  • Used automatically by CALL/RET, PUSH/POP, interrupts, etc.

  • Grows upward in memory (toward higher addresses)


๐Ÿ”ท 3. Stack Pointer (SP) Register

AttributeDetails
Size8-bit register
FunctionHolds the RAM address of the top of the stack
Default Value07H after reset
Stack StartsAt 08H (next byte after SP)

๐Ÿ”ท 4. Stack Operations

OperationAction
PUSH or CALLSP is incremented first, then data is stored
POP or RETData is retrieved first, then SP is decremented
๐Ÿ“Œ This means SP always points to the last used location on the stack.

๐Ÿ”ท 5. Stack Initialization

  • After reset:
    SP = 07H → stack starts at 08H

  • You can change SP manually to relocate the stack

    assembly

    MOV SP, #2FH ; stack will now start at 30H

๐Ÿ”ท 6. Stack Location in RAM

RAM RegionUsage
00H–1FHRegister banks (avoid using for stack)
20H–2FHBit-addressable area (avoid stack here too)
30H–7FHGeneral-purpose RAM (recommended for stack)
Best practice: Set stack above 2FH to avoid conflict with registers and bit-addressable memory

๐Ÿ”ท 7. Interaction with RAM Sections

⚠️ If stack overlaps with:

  • Register banks → R0–R7 data may get corrupted

  • Bit-addressable RAM → may affect flag bits or control logic

Recommendation: Relocate stack to higher general-purpose RAM section to prevent overwrite.


๐Ÿ”ท 8. Illustration / Example

assembly
MOV SP, #2FH ; Stack starts at 30H
PUSH ACC ; SP = 30H, ACC saved at 30H → SP = 31H PUSH B ; SP = 31H, B saved at 31H → SP = 32H POP B ; SP = 32H, B retrieved → SP = 31H POP ACC ; SP = 31H, ACC retrieved → SP = 30H

๐Ÿ“Š Stack Growth:

java

Initial SP = 2FH PUSH ACC → SP = 30H (ACC stored) PUSH B → SP = 31H (B stored) POP B → SP = 31H → 30H POP ACC → SP = 30H → 2FH