8051 Microcontroller: Block diagram and explanation
Introduction to 8051
The 8051 microcontroller is a very popular 8-bit microcontroller introduced by Intel in the year 1981 and it has become almost the academic standard now a days. The 8051 is based on an 8-bit CISC core with Harvard architecture. Its 8-bit architecture is optimized for control applications with extensive Boolean processing. It is available as a 40-pin DIP chip and works at +5 Volts DC.
Salient Features of 8051
- 4 KB on chip program memory (ROM or EPROM)
- 128 bytes on chip data memory (RAM)
- 8-bit data bus
- 16-bit address bus
- 32 general purpose registers each of 8 bits
- Two - 16 bit timers T0 and T1
- Five Interrupts (3 internal and 2 external)
- Four Parallel ports each of 8-bits (PORT0, PORT1, PORT2, PORT3) with a total of 32 I/O lines
- One 16-bit program counter and One 16-bit DPTR ( data pointer)
- One 8-bit stack pointer
- One Microsecond instruction cycle with 12 MHz Crystal
- One full duplex serial communication port
The architecture of the 8051 microcontroller can be understood from the block diagram. It has Harward architecture with RISC (Reduced Instruction Set Computer) concept.
The block diagram of 8051 microcontroller is shown. It consists of:
- an 8-bit ALU
- one 8-bit PSW (Program Status Register)
- A and B registers
- one 16-bit Program counter
- one 16-bit Data Pointer Register (DPTR)
- 128 bytes of RAM and 4kB of ROM and four parallel I/O ports each of 8-bit width
Block Diagram of 8051 Video Tutorial
Arithmetic Logic Unit (ALU)
- 8-bit ALU
- can perform all the 8-bit arithmetic and logical operations in one machine cycle
- The ALU is associated with two registers A & B which are special function registers which hold the results of many arithmetic and logical operations.
- It is also called the Accumulator and as it’s name suggests, it is used as a general register to accumulate the results of a large number of instructions.
- By default it is used for all mathematical operations and also data transfer operations between CPU and any external memory.
- It is mainly used for multiplication (MUL AB) and division ( DIV AB) operations along with A register.
- It has no other function other than as a location where data may be stored.
The R registers
- The "R" registers are a set of eight registers that are named R0, R1 up to and R7.
- These registers are used as auxillary registers in many operations.
- These registers are also used to temporarily store values.
Program Counter (PC)
- 16-bit program counter
- It always points to the address of the next instruction to be executed. After execution of one instruction the program counter is incremented to point to the address of the next instruction to be executed.
- Contents of PC are placed on address bus to find and fetch the desired instruction.
- Since the PC is 16-bit width, 8051 can access program addresses from 0000H to FFFFH, a total of 6kB of code.
Stack Pointer Register (SP)
- 8-bit register which stores the address of stack top. i.e the Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from.
- When a value is pushed onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location.
Similarly when a value is popped off the stack, the 8051 returns the value from the memory location indicated by SP, and then decrements the value of SP.
Since the SP is only 8-bit wide it is incremented or decremented by two.
- SP is modified directly by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI.
- It is also used intrinsically whenever an interrupt is triggered.
- The CPU needs this storage area as there are only limited number of registers.
- It is a part of RAM used by the CPU to store information temporarily. This information may be either data or address.
- The register used to access the stack is called the Stack Pointer which is an 8-bit register. So,it can take values of 00 to FF H.
- When the 8051 is powered up, the SP register contains the value 07. It means the RAM location value 08 is the first location being used for the stack by the 8051 controller.
- There are two important instructions to handle this stack.
- PUSH: The loading of data from CPU registers to the stack is done by PUSH
- POP: The loading of contents of the stack back into aCPU register is done by POP
MOV R6 , #35 H
MOV R1 , #21 H
In the above instructions the contents of the Registers R6 and R1 are moved to stack and they occupy the 08 and 09 locations of the stack. Now the contents of the SP are incremented by two and it is 0A.
Similarly POP 3 instruction pops the contents of stack into R3 register. Now the contents of the SP is decremented by 1.
- In 8051 the RAM locations 08 to 1F (24 bytes) can be used for the Stack.
In any program if we need more than 24 bytes of stack, we can change the SP point to RAM locations 30 - 7F H. This can be done with the instruction MOV SP , # XX.
Data Pointer Register (DPTR)
- It is a 16-bit register which is the only user-accessible.
- As the name suggests, DPTR is used to point to data.
- It is used by a number of commands which allow the 8051 to access external memory. When the 8051 accesses external memory it will access external memory at the address indicated by DPTR.
- DPTR can also be used as two 8-registers DPH and DPL.
Program Status Register (PSW)
- The 8051 has a 8-bit PSW register which is also known as Flag register. In the 8-bit register only 6-bits are used by 8051. Two unused bits are user definable bits.
- In the 6-bits four of them are conditional flags. They are Carry - CY, Auxiliary Carry - AC, Parity - P and Overflow - OV. These flag bits indicate some conditions that resulted after an instruction was executed.
The meaning of various bits of PSW register is shown below:
|Bit Designation||Bit Number||Bit Function|
|AC||PSW.6||Auxiliary Carry Flag|
|FO||PSW.5||Flag 0 available for general purpose|
|RS1||PSW.4||Register Bank select bit 1|
|RS0||PSW.3||Register bank select bit 0|
|---||PSW.1||User difinable flag|
Parity flag; set/cleared by hardware
The selection of the register Banks and their addresses are given below.
Special Function Registers (SFRs)
- Certain registers which use RAM addresses from 80h to FF H and they are meant for certain specific operations. These registers are called Special Function Registers (SFRs).
- Some of these registers are bit addressable.
- Some of them are related to I/O ports (P0, P1, P2 and P3).
- Some of them are meant for control operations (TCON, SCON, PCON)
- Remaining are the auxillary SFRs, in the sense that they don't directly configure the 8051.
The list of SFRs and their functional names are given below.
Name of SFR
Program Status word register
Stack Pointer Register
Data Pointer - low byte
Data Pointer - high byte
Interrupt Priority control
Interrupt Enable control
Timer Mode Register
Timer Control Register
Timer 0 - Higher byte
Timer 0 - Lower byte
Timer 1 - Higher byte
Timer 1 - Lower byte
Serial Control Register
Serial Buffer Register
Power Control Register
|The * indicates the bit addressable SFRs.|
- Notes by Prof. Sujit Wagh, SKNCOE, Pune