Skip to main content

8051 Ports

The 8051 micro-controller comes in different shapes and sizes, depending on the model (variant) that you choose. I talked about the most common pin configuration for 8051 in my previous post.  These pins can serve as either input or output to the micro-controller. They can be used independently or in groups. When few pins are combined together to form a group, it’s called a port. Let’s discuss the ports available in 8051.


 

The 8051 is an 8-bit micro-controller so it makes sense when I say that each port has actually eight pins. Sure, you can play around and define your own custom ports through code (perhaps I’ll talk about it someday) but the original architecture of 8051 offers four ports which gives you a total of thirty-two pins (four times eight) to work with.

 

8051 block diagram
8051 Block Diagram

 

Have a look at the block diagram above. You’ll notice four ports as

  • Port-0 (P0.0 – P0.7)
  • Port-1 (P1.0 – P1.7)
  • Port-2 (P2.0 – P2.7)
  • Port-3 (P3.0 – P3.7)

They are each 8-bit wide thus capable of handling 8-bit data at a time. These ports are normally referred to as

  • P0
  • P1
  • P2
  • P3

We can use these short names while writing codes for the 8051.
 

USING PORTS FOR INPUT/OUTPUT

When I say input/output, it simply means either sending data to the micro-controller or receiving data from it. You can use a single pin (signaling, switching etc.) or you can utilize a whole port (sending one byte of data, parallel switching etc.) for this purpose, depending on what you’re trying to build.

While using these ports, it must be noted that they’re all configured as INPUT by default upon RESET. You don’t need to configure anything if you intend to use them as input. However, using them as OUTPUT would require initialization. Don’t worry, it’ll get clear as we progress through this course. It will be sufficient for now if you’re able to distinguish between pins & ports, the number of pins & ports available in 8051 and their names/functionalities etc.

It is also important to mention here that except Port-0 (P0), all ports have built-in (internal) 10KΩ resistors. The P0 is actually open drain unlike P1, P2, and P3. If you don’t understand the concept behind this, don’t bother. Just remember that

You need to attach 10KΩ resistor with P0 only if you intend to use it as input/output.

 

port0 pullup resistors
Port-0 Pull-up resistors

 

And if you’re using any other port for input/output, you don’t need to attach these resistors.

 

DUAL NATURE

8051 offers many basic functionalities through different pins and ports. You can notice in the pin diagram that each pin has some unique functionality that you can access in your code. I’ll be discussing all these useful features in my future posts but for the present, you need to understand that each pin actually has dual nature. For instance, P3.0 (Pin#10) can be used for input/output as well as the receiving pin for serial transmission (RXD).

 

8051 Pin Configuration
8051 Pin Configuration

Don’t worry about the dual nature if you’re using pins or ports for simple input/output.

You need to use the dedicated hardware pin if you want to utilize some feature. For instance you can use only P3.1 (Pin#11) for transmission in serial communication.

It can be seen from the pin diagram that

  • Port0 & Port2 offers support for address lines (when external memory is connected).
  • Port1 has no dual nature.
  • Port3 offers some exquisite features such as serial transmission, interrupts, and timers.

This concludes a general introduction to how ports are organized in the 8051 architecture. I hope you grabbed the basic idea and concepts. Feel free to leave comments and feedback.

 

Have a nice day!

 

Faizan

Muhammad Faizan Khan is an Electrical Engineer and a Computer Geek. He is a technical guy and has more than 3 years of experience in Embedded Systems, Digital Logic Design, Computer Programming and everything else that’s logical. He mostly writes tutorials related to microcontrollers for beginners in his blog, PhaseWire.

Leave a Reply

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