8051 Microcontroller
8051 Microcontroller
The 8051 Microcontroller is one of the most popular and most commonly used microcontrollers in various
fields like embedded systems, consumer electronics, automobiles, etc.
A complete computer system manufactured on a single chip is called a microcontroller.
Features of a microcontroller are similar to that of a microprocessor like registers, ALU, program counter,
flags, stack pointer, etc. Along with these common features, a microcontroller has some additional features
such as a clock circuit, internal RAM, ROM, serial and parallel 1/O counter containing on-chip program
memory. A microcontroller can also be referred as a 'microcomputer'. It is single chip microcomputer.
It consists of are four parallel 8-bit ports, which are programmable as well as addressable as per the
requirement.
8051 is an 8 – bit Microcontroller i.e. the data bus of the 8051 Microcontroller (both internal and external) is
8 – bit wide.
1] Register:
Accumulator: ACC is the accumulator register. It is 8-bit register. It is also used for data transfer between
8051 and any external memory. Register are usually known as data storage devices. 8051 microcontroller
has 2 register, namely Register A and Register B. Register A serves as an accumulator while register B
function as a general purpose register. These register are used to stored output of mathematical and logical
instruction.
Register B: The B register is used with the A register for multiplication and division operations. For other
instruction it is treated as a scratch pad register.
2] Arithmetic and logic unit (ALU): The ALU can perform arithmetic and logical operations on 8-bit data. All
arithmetic and logical operation are perform by ACC Addition, multiplication, subtraction with carry come under
arithmetic operation. Logical AND, OR and exclusive OR(XOR) come under logical operation.
1|Page
3] Program counter (PC): A program counter is a 16-bit register and it has no internal address. The basic function of
program counter is to fetch from memory the address of the next instruction to be executed. The PC holds the
address of the next instruction residing in memory and when a command is encountered, it produces that
instruction. This way the PC increments automatically, holding the address of the next instructions.
4] Data pointer (DPTR): The data pointer or DPTR is a 16-bit register. It is made up two 8-bit registers called DPH
and DPL. Separate addresses assigned to each of DPH and DPL. These 8-bit registers are used for the storing memory
addresses that can be used to access internal and external data/code.
7] Timers and counters: Synchronization among internal operations can be achieved with the help of clock circuits
which are responsible for generating clock pulses. During each clock pulse a particular operation will be carried out,
thereby, assuring synchronization among operations. For the formation of an oscillator, we are provided with two
pins XTAL and XTAL2 which are used for connecting a resonant network in 8051 microcontroller device.
8] PSW (Program status word): Program status word or PSW is a hardware register which is a memory location
which holds a program’s information and also monitors the status of the program his is currently being executed.
Generally, the instruction of the result of a program is a stored in a single bit register called a ‘flag’. There are 7 flags
in the PSW of 8051. Among these flags, 4 are math flags and 3 are general purpose or user flags.
The 4 math flags are: 1} Carry (C) 2} Auxiliary carry (AC) 3} Overflow (OV) 4} Parity (P)
The 3 general purpose flags or user flags are: 1} F0 2} GF0 3} GF 1
9] Data and Address bus: A bus is group of wires using which data transfer takes place from one location to another
within a system. Buses reduce the number of paths or cables needed to set up connection between components.
There are mainly two kinds of buses - Data Bus and Address Bus
Data Bus: The purpose of data bus is to transfer data. It acts as an electronic channel using which data travels. Wider
the width of the bus, greater will be the transmission of data.
Address Bus: The purpose of address bus is to transfer information but not data. The information tells from where
within the components, the data should be sent to or received from. The capacity or memory of the address bus
depends on the number of wires that transmit a single address bit.
2|Page
Comparison of microcontroller and microprocessor
REGISTER BANKS:
The 8051 microcontroller has a total of 128 bytes of RAM. Lets discuss the allocation of these 128 bytes of RAM and
examine their usage as register and stack.
RAM [Random Access Memory] space allocation in 8051:
There are 128 bytes of RAM in the 8051. This 128 bytes of RAM inside the 8051 are assigned addresses 00 to 7FH.
This 128 bytes are divided into three different groups as follows.
1. Total of 32 bytes from locations 00 to 1F hex are set aside for register banks and the stack.
2. Total of 16 bytes from locations 20H to 2FH are set aside for bit addressable Read/Write memory.
3|Page
3. Total of 80 bytes from locations 30H to 7FH are used for read and write storage. These 80 bytes locations of
RAM are widely used for the purpose of storing data and parameters by 8051 programmers.
RAM Allocation in the 8051:
Note: Bank 1 used the same RAM space as the stack. We must either not use register Bank 1, or we must allocate
another area of RAM for the stack
4|Page
8051 Flag Bits and PSW Register
The program status word (PSW) register is an 8-bit register, also known as flag register. It is of 8-bit wide
but only 6-bit of it is used. The two unused bits are user-defined flags. Four of the flags are called
conditional flags, which means that they indicate a condition which results after an instruction is executed.
These four are CY (Carry), AC (auxiliary carry), P (parity), and OV (overflow). The bits RS0 and RS1 are
used to change the bank registers. The following figure shows the program status word register.
The PSW Register contains that status bits that reflect the current status of the CPU.
We can select the corresponding Register Bank bit using RS0 and RS1 bits.
CY, the carry flag − This carry flag is set (1) whenever there is a carry out from the D7 bit. It is
affected after an 8-bit addition or subtraction operation. It can also be reset to 1 or 0 directly by an
instruction such as "SETB C" and "CLR C" where "SETB" stands for set bit carry and "CLR" stands
for clear carry.
5|Page
AC, auxiliary carry flag − If there is a carry from D3 and D4 during an ADD or SUB operation, the
AC bit is set; otherwise, it is cleared. It is used for the instruction to perform binary coded decimal
arithmetic.
P, the parity flag − The parity flag represents the number of 1's in the accumulator register only. If
the A register contains odd number of 1's, then P = 1; and for even number of 1's, P = 0.
OV, the overflow flag − This flag is set whenever the result of a signed number operation is too
large causing the high-order bit to overflow into the sign bit. It is used only to detect errors in signed
arithmetic operations.
6|Page