Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Ports in 8051 microcontroller

To work with 8051 microcontroller we should have complete knowledge about ports in 8051 microcontroller. We have to clear some basic question like how can we use different ports of 8051 microcontroller? How can we configure them? will we use every ports for every works? What are the special functions we can done by using 8051 microcontroller specified port?

Ports in 8051 microcontroller

In this post i think you will find the answer of those questions.  So to starts with ports in 8051 microcontroller we should know it has four ports. Those are port0, port1, port2 and por3.

Port 0

Port-0 can be used as a normal bidirectional I/O port or it can be used for address/data interfacing for accessing external memory. When control is ‘1’, the port is used for address/data interfacing. When the control is ‘0’, the port can be used as a bidirectional I/O port.


PORT 0 as an Input Port

Let us assume that control is ‘0’. When the port is used as an input port, ‘1’ is written to the latch. In this situation both the output MOSFETs are ‘off’. Hence the output pin have floats hence whatever data written on pin is directly read by read pin.

PORT 0 as an Output Port

Suppose we want to write 1 on pin of Port 0, a ‘1’ written to the latch which turns ‘off’ the lower FET while due to ‘0’ control signal upper FET also turns off as shown in fig. above. Here we wants logic ‘1’ on pin but we getting floating value so to convert that floating value into logic ‘1’ we need to connect the pull up resistor parallel to upper FET . This is the reason why we needed to connect pull up resistor to port 0 when we want to initialize port 0 as an output port .

If we want to write ‘0’ on pin of port 0 , when ‘0’ is written to the latch, the pin is pulled down by the lower FET. Hence the output becomes zero.

When the control is ‘1’, address/data bus controls the output driver FETs. If the address/data bus (internal) is ‘0’, the upper FET is ‘off’ and the lower FET is ‘on’. The output becomes ‘0’. If the address/data bus is ‘1’, the upper FET is ‘on’ and the lower FET is ‘off’. Hence the output is ‘1’. Hence for normal address/data interfacing (for external memory access) no pull-up resistors are required.Port-0 latch is written to with 1’s when used for external memory access.


Port-1 dedicated only for I/O interfacing. When used as output port, not needed to connect additional pull-up resistor like port 0. It have provided internally pull-up resistor as shown in fig. below. The pin is pulled up or down through internal pull-up when we want to initialize as an output port. To use port-1 as input port, ‘1’ has to be written to the latch. In this input mode when ‘1’ is written to the pin by the external device then it read fine. But when ‘0’ is written to the pin by the external device then the external source must sink current due to internal pull-up. If the external device is not able to sink the current the pin voltage may rise, leading to a possible wrong reading.

ports in 8051 microcontroller



Port-2 we use for higher external address byte or a normal input/output port. The I/O operation is similar to Port-1. Port-2 latch remains stable when Port-2 pin are used for external memory access.

Here again due to internal pull-up there is limited current driving capability.

ports in 8051 microcontroller


Following are the alternate functions of port 3:


 P3.1—– TXD

 P3.2—– INT0 BAR

 P3.3—– INT1 BAR

 P3.4—– T0

 P3.5—– T1

 P3.6—– WR BAR

 P3.7—– RD BAR

It works as an IO port same like Port 2 as well as it can do lots of alternate work which are discuss above. Only alternate function of port 3 makes its architecture different than other ports.

ports in 8051 microcontroller Hope this discussion will help to earn knowledge on ports in 8051 microcontroller if you have any doubt regarding different ports in 8051 microcontroller you can ask on reply of this post.

Not Enough, Need More

E-Mail Subscription

E-Mail Subscription

Table of Contents
Subham Dutta

Subham Dutta

Hi myself Subham Dutta, having 15+ years experience in filed of Engineering. I love to teach and try to build foundation of students. Try to make them imagine what they learn.

Need more this type of content in your E-Mail?