In this tutorial, you will learn about 8051 microcontroller. I will start with History of 8051 microcontroller and how 8051 microcontroller evolve such a famous microcontroller among engineering students. We will start with brief history of 8051 microcontroller. First we will discuss its various members and its history. After that we will discuss architecture of 8051 microcontroller, registers, pin configuration, timers, counters, serial ports programming, types of interrupts and many other features. We will also discuss internal registers of 8051 microcontroller, its hardware connections to make it ready to use in microcontrollers based projects. After that we will discuss its input/output programming. At the end of article there will be some suggestion about how to learn 8051 microcontroller quickly and how to make project using it.
But before reading this article you should know basic difference between microprocessor and microcontroller? After getting understanding of microcontroller and microprocessor you should read this article. Selection of microcontroller is also a very important aspect while designing any project.
- 1 8051 microcontroller history
- 2 8051 microcontroller architecture
- 3 8051 microcontroller I/O port programming
- 4 8051 microcontroller pin configuration
8051 microcontroller history
Intel Corporation is first company who presented 8051 microcontroller in market. It is 8 bit microcontroller. It have on chip 128 bytes of RAM, 4K bytes ROM, two timers, one serial port and four general purpose input/output ports. Each port has 8 bit register. It is also knows as single on chip. It have 8 bit processing unit. Its mean it can process 8 bit of data at a time. Large data must be divided into 8 bit information for processing. It can have maximum of 64k bytes ROM. It have gain many popularity after Intel allows other manufacturers to make it. After that its many versions with different speed, on chip RAM and ROM sizes were introduced in market by many manufacturers. But all these versions have same instruction set and program written for one will run on any other version without any change. 8052, 8031 are another versions of its family.
8051 microcontroller features
8051 microcontroller architecture
In this section we will discuss its internal architecture and main registers. Registers are mainly used while programming microcontrollers in assembly language. But for c programming, we still need to know about some registers. Registers are used to perform MOV and ADD instructions.
As you know in microprocessors registers are used to store temporary instructions and data. Instructions are used to processed addresses to fetch data. 8051 microcontrollers have 8 bit registers. 8 bit registers have 8 bit start from D0-D7. D0 is least significant bit and D7 is least significant bit. To process data larger than 8 bit, it should be broken into 8 bit pieces. It has many registers but general purpose registers are mostly accessible to programmers. There are two types of registers 1) General purpose registers 2) Special purpose registers. List of mostly used general purpose registers is given below:
- A accumulator ( It is used to perform arithmetic and logic instructions)
- B, R0, R1, R2, R3, R4, R5, R6, R7 registers ( They are used to store instruction address and data)
- DPTR ( Data pointers is used to access and process data in different addressing modes) It consists of high byte ( DPH) and a low byte (DPL) . It is used to hold 16 bit address. It is used as a base register in indirect jumps, external data transfer and lookup table instructions.
- PC (Program counter is 16 bit register. It is used to store the address of next instruction to be executed )
All these registers are of 8-bits other than data pointer and program counter registers.
8051 data type
8051 microcontroller has only one data type of 8 bit. The size of each register is also 8 bit. If data is larger than 8 bit, it is programmer responsibility to divide data into 8 bit pieces before processing. DB directive is most widely used data directive in assembly language for assemblers.
Program status word register
8051 microcontroller has program status register also know as flag register. Flag register is used to show status of arithmetic logic instructions like carry bit, zero carry bit etc. PSW is an 8 bit register. Only 6 bits are used. PSW register is also called flag register. Flag register has 8 flags. Four flags are called conditional flags which execute instruction only if condition is fulfilled. These conditional flags are OV (overflow), P (parity), AC (auxiliary carry) and CY (carry). Bit number 3 and 4 of PSW register is used to change the bank registers. Bit number 1 and 5 of program status register are unused and it can be used by programmer for any specific purpose.
32 Bytes of RAM are dedicated for register banks and stacks. These 32 bytes are broken in four banks. Each back has 8 registers from R0-R7. R0 is RAM location zero and so R7 is RAM location seven. The second bank register is started from location 8 and end 05H. The third bank starts from 10H and finished on location 17H. The last bank is located between the 18H-1FH.
8051 microcontroller stack
Stack is a part of RAM which is used by the processor to store data or an address temporarily. Stack is very important part of microprocessor because there are very limited numbers of registers to store data and addresses. Stack pointer is 8051 is 8 bit wide. It means it can hold data from 00 to FFH. Stack pointer is used by CPU to access the stack. 8051 have 8 bit stack pointer. It means it can access values from 00H-FFH. When it is turned on, the stack pointer contains value of 07.
Memory in 8051
It have complex memory organization. Because 8051 microcontroller have separate adress bus for program memory, Data memory and exteranl RAM. It is based on Harvard architecture developed by Harvard in 1944. It may consists of internal or external program memory. It can support upto 64k bytes of external memory. I have 128 bytes of internal data memory.
Microprocessor fetches data in different ways. The data usually stored in register, memory and can be used from immediate value. These different ways of accessing data is called addressing modes. Different microcontrollers have different addressing modes. It depends on design of manufacturers. 8051 has 5 addressing modes.
- Register indirect
8051 microcontroller I/O port programming
It has four input/output ports to interact with external devices. As shown in figure below, it has 40 pins but 32 pins are assigned to I/O 4 port. Port P0, P1, P2 and P3. Each port has 8 bits. Each bit can be used either as an input or output pin. Resetting these pins make them input ports. In other words they can be used as an input. But all ports can be configured either as an input or output.
To configure any port as an input port writes 0 to it and to configure any port as an output write 1 to it. But to use port 0 as an input or output each pin must be externally pulled up with 10K ohm resistor. Because port 0 is an open drain. Rest of the ports can be configured either as an input or output by writing either 0 or 1 to all the bits. One no needs to use pull up resistor with P1, P2 and P3 ports. Sometimes we may need to access only one or two bits of port. 8051 microcontroller provides facility to access individual bits. For example we want to access bit 0 of port 1, we can use P1.0 to access bit zero of port 1. Similarly we can access any bit of any port. We will see how to do it in programming in later part of this article.. Check this complete tutorial on How to use input output ports of 8051 microcontroller:
8051 microcontroller pin configuration
It comes in different packages like DIP (dual in line package), QFP (quad flat package) and LLC( lead less chip carrier). It is 40 pin microcontroller. Pin configuration of 8051 microcontroller is shown below:
Some manufactures also introduced 20 pin 8051 with less number of input /output pins. As shown in above figure. It has 40 pins out of which 32 pins are dedicated for four ports. We explained these four ports earlier. Brief explanation of all pins is given below:
- Vcc : It provides supply voltage to chip. The operating voltage is 5 volt.
- GND : It connect with ground of voltage supply
- XTAL1 and XTAL2 pin: Although 8051 have on chip crystal oscillator. But still it requires an external clock oscillator. External crystal oscillator is connected to XTAL1 and XTAL2 pins. It also requires two capacitors of 30pF as shown in figure below. Capacitors one terminal is connected with crystal oscillator and other terminal with ground. Processing speed of 8051 microcontroller depends on crystal oscillator frequency. But each microcontroller have maximum limit of operating frequency. We cannot connect crystal oscillator more than maximum operating limit frequency.
- RST pin number 9 is a reset pin. It is active high pin. It is used to reset. If we apply active high signal to this pin, 8051 microcontroller will reset and turn off all its functions. It will erase all values of registers and it will make all program counter values to zero. Figure below shows the power on reset circuitry. Rest input will be effective only, if we apply high pulse for more than two machines cycles. Otherwise it will not rest.
- EA Pin number 33 is used to store program. All family of 8051 microcontrollers comes with on chip ROM to store programs. For such purpose EA pin is connected with Vcc. EA stands for external access.
- PSEN Pin number 29 is an output pin. It is stands for “Program store enable”. It is also used for programming.
Input/output ports P0, P1, P2 and P3 use to interface 8051 microcontroller with external devices. I have already explained it above.
8051 microcontroller features
8051 microcontroller have following basic components inside it or it provides following features. Although we can connect additional components externally.
- It have 4k bytes of internal ROM
- It have 128 bytes of internal RAM
- It have foure 8 bit input/output ports
- One serial communicatiom port
- 210 bit address bus
- 64k bytes external memory for code
- 64K bytes external memory for data
- Two 16 bit timers and counters
- UART serial communication port
- Interrupts ( External and internal)
- Internal on chip clock
Block diagram of 8051 microcontroller
As I mentioned earlier 8051 microcontroller has 4 input output ports, 2 timers which can be used either as a timer and counter. It has one serial communication PORT or UART communication is possible with this microcontroller. All other features are also shown in block diagram. Block diagram of 8051 microcontroller is given below.
Timers in 8051 microcontroller
8051 microcontroller have two timers. Timer is kind of counter which increment its value by one every time an instruction is executed. Time of increment depends on frequency of crystal oscillator. I will post a separate article on how to use timers of 8051. For more information about how to use these two timers either as a timer or as counter you can check following article on timer working:
External interrupt of 8051 microcontroller
It has two external interrupt pin which can be used to monitor any external event as a interrupt. There are two methods which are usually use in microcontrollers to measure external events. One is polling and other is interrupts. To know how to use interrupts of 8051 microcontroller check this article:
How to measure analog values with 8051 microcontroller
It 8051 does not contain built in analog to digital converter as mostly microcontroller does. As you already know, Analog to digital converter has many applications. All microcontrollers or digital devices only deals with binary forms like 0’s and 1’s. So to interface any analog sensor with microcontroller, we need to use analog to digital converter. we can interface external analog to digital converter with 8051 microcontroller to measure external world analog signals. To know more about how to interface 8051 with Analog to digital converter check this complete guide:
8051 microcontroller tutorials
you may also like to check other 8051 microcontroller tutorials
- LCD interfacing with 8051
- keypad interfacing with 8051
- DC motor interfacing with 8051
- Stepper motor interfacing 8051
- Servo motor interfacing 8051
- Serial communication with 8051 microcontroller