8051 Microcontroller
8051 Microcontroller
• Intel 8051 is an 8-bit single chip 40 pin Dual in Package (DIP) IC. It operates on 12MHz clock and single +5V supply.
• Microcontroller 8051 has an 8-bit CPU. It consists of Accumulator, register, Arithmetic Logic Unit (ALU) and Control Unit (CU). It is
used to perform basic mathematical calculations and Logical operations.
• 128 bytes of RAM and 4Kbytes of ROM are available with 8051.
• 8051 consist of four 8-bit ports. They are port 0, port 1, port 2 and port 3. These ports can be programmed either input or output
port.
• There are two timer's timer 0 and timer 1 provided in 8051. Both timers are 16 bits wide.
• The majority of 8051 registers are 8-bit registers. Some of the widely used general purpose registers are A (Accumulator), B, R0,
R1, R2, R3, R4, R5, R6, R7, Data Pointer and Program Counter. Only two registers Data pointer (DPTR) register and Program
Counter (PC) are 16-bit wide.
• A group of specific internal registers use for some special functions is called Special Function Registers (SFR). SFRs hold the Port
operation, Timer operation, Serial communication, Interrupt Control, Memory management etc. Addresses of SFRs are between
80H and FFH.
• There are five interrupts available in 8051, in which three are internal interrupts and two are external interrupts. Three internal
interrupts are timer 0(TF0), timer 1(TF1) and serial I/O port (RI or TI) interrupts. Two external interrupts are INT0 and INT1.
Pin diagram • Port 0 (Pins 32-39):
Dual-purpose: It can act as a bidirectional I/O port or lower byte of address/data bus
(AD0-AD7).
• Port 1 (Pins 1-8):
Dedicated 8-bit bidirectional I/O port. It does not have alternate functions, used solely
for input/output operations.
• Port 2 (Pins 21-28):
Dual-purpose: Can be used as a bidirectional I/O port or the higher byte of address bus
(A8-A15).
Port 3 (Pins 10-17):
Multipurpose: Works as an I/O port but also has special functions.
• P3.0: RXD (serial input)
• P3.1: TXD (serial output)
• P3.2: INT0 (external interrupt 0)
• P3.3: INT1 (external interrupt 1)
• P3.4: T0 (timer 0 input)
• P3.5: T1 (timer 1 input)
• P3.6: WR (write control signal)
• P3.7: RD (read control signal)
• Vcc (Pin 40): Power supply pin (+5V).
• GND (Pin 20): Ground.
• XTAL1 (Pin 19) and XTAL2 (Pin 18): Connected to an external crystal oscillator to
provide a clock signal.
• RST (Pin 9): Reset input pin. A high pulse on this pin resets the microcontroller.
• ALE (Pin 30): Address Latch Enable. This pin is used to latch the low byte of the
address when interfacing with external memory.
• PSEN (Pin 29): Program Store Enable. This is used to read external program
memory.
• EA (Pin 31): External Access Enable. It determines whether the microcontroller
uses internal or external program memory.
Summary of Ports in 8051
Port I/O Capability Special Functions
General-purpose I/O, Multiplexed External Memory Interface (A0–A7,
P0
Address/Data Bus D0–D7)
P1 General-purpose I/O No special functions
P2 General-purpose I/O, Address Bus External Memory Interface (A8–A15)
Serial, Interrupts, Timers, External
P3 General-purpose I/O, Special Functions
Memory Control (RD, WR)
Program Counter (PC): The Program Counter (PC) is a 16-bit pre-settable up counter used as a memory
pointer. The Program Counter (PC) keeps track of program execution. To execute a program, the starting
address of the program is loaded in Program Counter (PC).
Data Pointer (DPTR): Data pointer is a 16-bit register made up of two 8-bit registers. They are Data Pointer
Higher order byte (DPh) and Data Pointer Lower byte (DPl) registers. DPTR holds a 16-bit address of external
memory.
Flags register Flags are used to store the result of certain function after executing instruction. 8051
microcontroller contains a special register called the Program Status Word (PSW), which
holds several flags used to indicate the status of operations. The PSW contains 8 bits, and five of
these are commonly used as flags.
Internal RAM
Internal RAM 8051 has 128-byte internal RAM and called data memory. These 128 bytes
are divided into three groups and they are Register Banks, Bit addressable registers and
General purpose. There are four register banks available in 8051 are Bank 0, Bank 1,
Bank 2 and Bank 3.
Bit-Addressable Area
Address Range: 20H to 2FH
This section of RAM (16 bytes) is bit-addressable, meaning individual bits
can be manipulated directly (total of 128 bits).
Useful for setting and clearing control flags, variables, and bits in
software
.
General-Purpose RAM
Address Range: 30H to 7FH
This section (80 bytes) is used for storing data and variables that are not
directly accessible through registers or bit-addressable memory.
Special Function Registers (SFRs): A set
of memory-mapped registers that control the
operation of the microcontroller's peripherals
and core functions. These registers can be
accessed directly by their addresses and are
critical for tasks such as I/O control, timer
operation, interrupt handling, serial
communication, and more.
• SCON configures the baud rate, transmission mode, and other serial communication settings.
Stack in 8051:
• The stack is a section of the internal RAM (not the external RAM) used
for temporarily storing data such as return addresses, register values, and
other important information when a subroutine is called or during an
interrupt.
• It operates in a Last In, First Out (LIFO) manner. This means the last
data stored in the stack is the first to be retrieved.
• The stack grows upward in the RAM, meaning that as data is pushed onto
the stack, the stack pointer is incremented.