Port Structure of 8051 Microcontroller

All 8051 microcontrollers have 4 input-output (IO) ports each of 8-bits which can be configured as inputs or outputs. The four ports are port 0, port 1, port 2 and port 3. Let’s understand the port structure of 8051 microcontroller for each port.

Input/Output Ports in 8051 Microcontroller

  • In order to configure a microcontroller pin as an output, it is necessary to apply a logic zero (0) to appropriate I/O port bit. In this case, voltage level on appropriate pin will be 0.
  • Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the case with any TTL input).
  • By default, the port is defined as output port.

Port 0 Structure of 8051

Port 0 Structure of 8051 microcontroller
  • Port 0 has dual function as I/O port and Address/Data bus for external memory. When external memory is not used, port 0 is used as simple I/O port.
  • When external memory is used, port 0 is used as address bus and data bus. Lower byte address and data are multiplexed in this port.
  • ALE signal is used to demultiplex the address from this port. ALE goes high, when this port contains address. After addressing ALE goes low and the port become data bus.
  • To read the data from external memory logic 1 is written to all port SFR latches.

Note:

  • The Special Function Register (SFR) for each port is made up of eight latches, which can be address for that port. The port latches should not be confused with the port pins.
  • The data in the latches does not have to be the same as that on port pins. The data in latch buffer and the data of ports pins can be read independently.

Port 1 Structure of 8051

Port Structure of 8051 Microcontroller
  • Port 1 -only port in 8051 -used exclusively for input and output operation.
  • The output of the port latch is connected to the port pin through a transistor driver with internal pull up resistor. The port can be operated as an input after writing 1 to all the bits of port 1 latch.
  • 8051 ports are organized such that most instructions read the data from the pin for read operation and some instructions read the data from the latch.
  • So, the input buffer consists of the select logic and the related control signals – ‘Read Latch’, ‘Read Pin’ for discriminating this.

Port 2 Structure of 8051

Port 2 Structure of 8051 microcontroller, 8051 port 2 structure
  • Port 2 is similar to port 0 having dual function. In addition to I/O operation it can address external memory also.
  • When 64K external memory is connected, 16-bit address is required. Lower byte address is carried by port 0 and higher byte address is carried by port 2. Since data is 8-bit, only address is carried in this port.
  • I/O operation of this port is like port 0. By default, this port is an output port. To make this port as input port the port SFR latch buffer should be set to all 1s.

Port 3 Structure of 8051

Port 3 Structure of 8051 microcontroller,8051 port 3 structure
  • In terms of hardware, this port is similar to P0, with the difference that its pins have a pull-up resistor built-in.
  • Port 3 is different from the other ports in the aspect that individual port pins can be programmed for input and output operation.
  • Each pin of port 3 can be programmed – for input, output operation or alternate functions.
  • All the Port3 pins serve an alternate function according to the hardware signals and interfacing.
  • The alternate functions can be activated only if the port 3 bits are written with 1s in their position.
  • Alternate functions for port 3 are as follows.

 

PORT 3 Pin

Alternate Function

Description

P3.0

RXD

Serial input data

P3.1

TXD

Serial output data

P3.2

INT0

External interrupt 0

P3.3

INT1

External interrupt 1

P3.4

T0

External timer 0 clock

P3.5

T1

External timer 1 clock

P3.6

WR

External memory write enable

P3.7

RD

External memory read enable

 

 

 

Now let’s have a look over each port in a single diagram.

Port Structure of 8051 Microcontroller, 8051 port structure,
Figure: Port Structure of each port in 8051 Microcontroller

Recent posts

1 thought on “Port Structure of 8051 Microcontroller”

  1. Hi I am so happy I found your website, I really found you by accident, while I was searching on Yahoo for something else, Regardless I am here now and would just like to say thanks a lot for a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the awesome work.

Leave a Comment

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