8051 Microcontroller Pin Diagram and Pin Description

Whenever I hear the word ‘8051 Microcontroller,’ my mind immediately pictures a 40-pin DIP IC. If you ask me about the pin configuration of the 8051 Microcontroller, I would explain it pin-by-pin, even in my sleep. I cannot say the same thing will happen for any ‘modern’ microcontroller, say an STM32. But why is it important to learn the 8051 Microcontroller Pin Diagram and Pin Description (or any microcontroller for that matter)?

However complex the internal architecture of a microcontroller is, the only way to control the hardware is through the pins. They are your gateway to all the blackmagic that happens on the inside of a microcontroller. If you understand the functions of these pins, then your job as an embedded system designer becomes much simpler. You can easily assign specific functions to a pin depending on the application.

In this introductory series on 8051 Microcontroller, let us understand the Pin Configuration (Pin Diagram and Pin Description) of the 8051 Microcontroller. In the process, we will learn the functions of each and every pin of the 8051 microcontroller.

8051 Microcontroller Packaging

Before looking at the pin diagram of the 8051 Microcontroller, let us quickly understand the different IC Packages of the 8051 Microcontroller. IC Packaging is a phase in the semiconductor fabrications that adds a protective enclosure to the silicon die. It also provides the electrical connectivity between the Integrated Circuit and other components (on a circuit board).

The 40-pin Dual-in-Line Package or DIP is by far the most common type of package for the 8051 Microcontroller. It is a through-hole type packaging. Most of the modern Dual-in-Line Packages are made from plastic, so they are known as Plastic DIP (PDIP).

Apart from this, some modern versions of the 8051 Microcontroller are also available in a couple of SMT (Surface Mount Technology) packages as well. The most common ones are the 44-lead PLCC (Plastic-leaded Chip Carrier) and the 44-lead TQFP (Thin Quad Flat Package).

8051 Microcontroller Pin Diagram

With that information aside, let us now take a look at the Pin Diagram of the 8051 Microcontroller. The following image shows the pin diagram of a typical 40-pin DIP 8051 Microcontroller.

8051-Microcontroller-Pin-Diagram-40-Pin-DIP

The DIP is a popular package for through-hole components. In case of a 40-Pin DIP, each side consists of 20 Pins (as you can see from the image).

As a bonus, I also designed the 8051 Microcontroller Pin Diagrams for the 44-lead TQFP and the 44-lead PLCC packages.

8051-Microcontroller-Pin-Diagram-44-Lead-PLCC

Even though these 44-lead packages have 4 extra pins/leads compared to the standard 40-pin DIP, the usable pins are still the same 40 pins.

8051-Microcontroller-Pin-Diagram-44-Lead-TQFP

The extra 4 pins are either GND or NC (Not Connected Internally). 

8051 Microcontroller Pin Description

Let us now understand the function of each and every pin of the 8051 Microcontroller. For the sake of convenience, I will be using the standard 40-pin DIP IC as a reference for the pin numbers. For instance, when I say Pin 40, I mean the Pin 40 of the DIP 8051 (which is the VCC).

Pins 1 to 20

  • Pins 1 to 8: These 8 Pins are the Port 1 Pins of the 8051 Microcontroller. I will talk more about all the Ports (P0, P1, P2, and P3 in a separate section).
  • Pin 9: This is the Reset Pin. It is an Active HIGH Pin i.e., for the microcontroller to reset, this pin must be held high for a minimum of two machine cycles (which means the 8051 Microcontroller must have its oscillator running). For normal operation, this pin is pulled LOW. I will show the Reset Circuit a bit later. 
  • Pins 10 to 17: There are the Port 3 Pins of the 8051 Microcontroller.
  • Pins 18 and 19: We must connect an external crystal (usually 11.0592MHz) to the XTAL1 and XTAL2 Pins of the 8051 Microcontroller for the Internal Oscillator to work. XTAL1 is the input of the internal Inverting Amplifier, while XTAL2 is its output. Additionally, we have to connect two load capacitors (usually 33pF) at these Pins. We will see the clock circuit later.
  • Pin 20: This is the Ground Pin (we have to connect 0V of the Power Supply here). Name of this pin can be GND or VSS.

Pins 21 to 40

  • Pins 21 to 28: There are the Port 2 Pins of the 8051 Microcontroller.
  • Pin 29: PSEN stands for Program Store ENable. It is one of the External Bus Control Pins. If we use external Program Memory (ROM), this pin must be LOW if the Microcontroller wants to read a Byte from external memory. It is usually connected to the Output Enable (OE) of the EPROM Module. 
  • Pin 30: ALE means Address Latch Enable. The 8051 microcontroller uses a multiplexed address/data bus (AD0–AD7) for external memory interfacing. During the first clock cycle of a memory operation, the lower 8 bits of the address (A0–A7) are placed on the AD0–AD7 lines. In the subsequent cycles, these lines are used to transfer data. To separate the address from the data, the ALE pin generates a pulse. This pulse enables an external latch (like 74LS373 or 74HC373) to capture and hold the lower address bits while the bus switches to data mode. The ALE pin outputs a pulsating signal during each machine cycle, except when the microcontroller is in idle mode or fetching data exclusively from internal memory. This signal is high for a portion of the cycle, indicating when the address is valid on the multiplexed bus (AD0–AD7). In some variants of 8051, the PROG Pin is used as a Program Pulse Pin during flash programming.
  • Pin 31: EA stands for External Access Enable Pin. If the microcontroller executes code exclusively from the Internal Memory, this pin is Pulled HIGH (Important). In case the Microcontroller executes the program from external memory, then this pin must be LOW. This Pin (VPP) receives the Programming Power Supply during Flash Programming (the voltage, 12V or 21V is dependent on the manufacture).
  • Pins 32 to 39: There are the Port 0 Pins of the 8051 Microcontroller.
  • Pin 40: This is the main Power Supply Pin. Since most 8051 Microcontrollers operate at 5V, this Pin (VCC) is usually connected to +5V of the power supply.

I/O Ports of 8051 Microcontroller

The 8051 Microcontroller has 32 I/O Pins that are grouped into four Ports of 8 Pins each; Port 0, Port 1, Port 2, and Port 3 (P0, P1, P2, and P3 in short). Since the 8051 is an 8-bit Microcontroller, the advantage of this ‘Port’ structure is that you can control all the 8 Pins of a particular port in a single instruction. Additionally, all these Pins are Individually Addressable. You can control each pin independently without interfering with the other pins of that Port.

All the four Ports of the 8051 Microcontroller are Bidirectional i.e., they can act as INPUT or OUTPUT (data can come IN or go OUT). Also, all the ports have an 8-bit Latch accessible in the form of a Special Function Register (P0 for Port 0, P1 for Port 1, P2 for Port 2, and P3 for Port 3).

Let us take a closer look at each Port of the 8051 Microcontroller.

Port 0

Pins 32 to 39 are the Port 0 Pins. They have two modes of operation. When there is no external memory, the Port 0 Pins act as regular I/O Pins. However, they have an ‘Open Drain’ configuration. So, in order to use Port 0 Pins as either input or output, you have to connect these pins to external pull-up resistors (usually 10KΩ). To configure the Port 0 Pins as INPUT, we have to write 1s to the P0 SFR (at the corresponding bits).

If you connect the 8051 Microcontroller to an external memory, then Port 0 becomes a multiplexed address and data bus. It acts as the lower order byte of the Address (A0 to A7) and the Data Byte (D0 to D7). The ALE pin determines if the Port 0 acts as Address or Data Bus (Address when ALE – HIGH and Data when ALE – LOW).

The pins of Port 0 are designated P0.x, where x can be anything from 0 to 7 (P0.0, P0.1, and so on). This applies to other ports as well. 

Port 1

Pins 1 to 8 of the 8051 Microcontroller are the Port 1 Pins. These pins have internal pull-ups. In the original 8051 Microcontroller, Port 1 is purely an I/O Port without any alternate functions. When you write 1s to the Port 1 Pins, they are pulled HIGH and you can use them as INPUTs (this is true for the other two ports as well i.e., P2 and P3).

In some later models (such as 8052, for instance), the first two pins i.e., P1.0 and P1.1 have alternate functions. Pin P1.0 is the Timer/Counter 2 Pin while the pin P1.1 is the Timer/Counter 2 Capture/Reload Trigger and Direction Control.

Additionally, some models (AT89S52, for example) use Pins P1.5 to P1.7 for flash programming (Serial Mode).

Port 1 PinNameAlternate Function
P1.0T2Timer/Counter 2
P1.1T2EXTimer/Counter 2 Capture/Reload Trigger and Direction Control
P1.5MOSIData IN for In-system Programming
P1.6MISOData OUT for In-system Programming
P1.7SCKClock for In-system Programming

Port 2

Pins 21 to 28 are the Port 2 Pins of the 8051 Microcontroller. Port 2 is also a bidirectional Port with internal pull-ups. For normal operation, the Port 2 Pins act as regular I/O pins.

Additionally, if you are using an external memory with the 8051 microcontroller, the Port 2 acts as the higher order byte of the Address Bus (A8 to A15) when the Address is 16-bit wide.

Port 3

Pins 10 to 17 of the 8051 Microcontroller are the Port 3 Pins. Like the previous two ports i.e., P1 and P2, even the Port 3 is a bidirectional Port with internal pull-ups and acts as an I/O Port under normal operation.

Port 3 PinNameAlternate Function
P3.0RXDReceive Data for Serial Port
P3.1TXDTransmit Data for Serial Port
P3.2INT0External Interrupt 0
P3.3INT1External Interrupt 1
P3.4T0Timer/Counter 0 External Input
P3.5T1Timer/Counter 1 External Input
P3.6WRExternal Data Memory Write Strobe
P3.7RDExternal Data Memory Read Strobe

8051 Microcontroller Clock Circuit

Internally, the 8051 Microcontroller has an inverting amplifier that acts as the on-chip oscillator. The XTAL1 and XTAL2 pins are the input and output of this inverting amplifier. We can either connect a quartz crystal across the XTAL1 and XTAL2 pins or alternatively if you have an external clock source, you can connect it at XTAL1 (XTAL2 is left open).

In addition to the Quartz Crystal, you need two Load Capacitors (whose value depends on the frequency of the Quartz Crystal). Since 11.0592MHz is the popular Quartz Crystal frequency for the 8051 Microcontroller, 22pF or 33pF Load Capacitors are quite common.

The following image shows the typical clock circuit of an 8051 Microcontroller.

8051-Microcontroller-Clock-Circuit

8051 Microcontroller Reset Circuit

As I said previously, a logic HIGH on the RST pin for a minimum of two machine cycles (and returning it LOW) will reset the 8051 Microcontroller. After a successful reset, the following things will happen:

  • Program Counter is cleared
  • Stack Pointer is loaded with 07H (as system stack starts from 08H)
  • Register Bank 0 is active
  • All Ports are set to FFH (acts as INPUT)

You can design two types of Reset Circuits for the 8051 Microcontroller. They are:

  • Power-on Reset
  • Manual Reset

The Power-on Reset consists of an RC (Resistor-Capacitor) network at the Reset pin. A 10µF Capacitor and an 8.2KΩ Resistor are the standard values. The resistor will pull the RST pin low. As the microcontroller powers on, the capacitor pulls the RST pin HIGH (until the capacitor charges) and resets the microcontroller.

The problem with this circuit is you have to power off and on every time you want to reset the microcontroller. You can add a simple push button in series with a small current limiting resistor, say a 100Ω (optional, though) in parallel to the capacitor (between the RST pin and the VCC). Whenever you press the button for a second or two, it will reset the microcontroller.

8051-Microcontroller-Reset-Circuit

The following table shows the contents of all the SFRs of the 8051 Microcontroller after a reset.

SFRReset Value (B)Notes
A00000000
B00000000
DPTR00000000 00000000
IE0XX00000All Interrupts Disabled
IPXXX00000
P0, P1, P2, P311111111Outputs FFH, All are INPUTs
PC00000000 00000000Address of First Instruction
PCON0XXXXXXXTimer 1 is set as Baud Generator
PSW00000000
SBUFXXXXXXXX
SP0000011107H – Stack Starts from 08H
TCON00000000
TH0, TH1, TL0, TL100000000
TMOD00000000

You will understand these values better when you learn the Registers and Special Function Registers (SFRs) of the 8051 Microcontroller.

8051 Microcontroller Minimal Circuit

Now that we have seen the Clock and Reset Circuits of the 8051 Microcontroller, let us quickly build a bare minimum configuration for the 8051 Microcontroller that is necessary for the basic operation.

The following image shows the minimal configuration circuit of the 8051 microcontroller with a 11.0592MHz Quartz Crystal, a Manual Reset, and both code and data memories are internal.

8051-Microcontroller-Basic-Circuit

If you recall, the EA pin must be pulled HIGH to enable internal memory access. The rest of the circuit elements are pretty much self explanatory.

Conclusion

This was a complete guide on the 8051 Microcontroller Pin Diagram and Pin Description. Additionally, we saw some of the essential parts of an 8051 Microcontroller (the Clock and Reset Circuits). In the next guide, I will start the 8051 Microcontroller Architecture.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top