MPMC - 4.1 8051 IO Ports
MPMC - 4.1 8051 IO Ports
MPMC - 4.1 8051 IO Ports
1 8051 IO Ports
Mohammad Ali Mazidi, Janice G. Mazidi, Rolin D. McKinlay, The 8051 Microcontroller and
Embedded Systems, 2014, 2nd Edition, Pearson, India.
4.1 8051 IO Ports
1. 8051: IO Ports
4.1 8051 IO Ports
4.1 8051 IO Ports
4.1 8051 IO Ports
1. 8051: IO Ports
• All 8051 microcontrollers have 4 I/O ports each comprising 8 bits
which can be configured as inputs or outputs.
• In total of 32 input/output pins enabling the microcontroller to be
connected to peripheral devices are available for use.
• Pin configuration, i.e. whether it is to be configured as an input (1) or an
output (0), depends on its logic state.
• When the first 0 is written to a port, it becomes output port.
For reconfiguring it as input, 1 must be sent to the port (programmed)
• All the ports upon RESET are configured as input, ready to be used as
input ports
4.1 8051 IO Ports
1.1 PORT - 0
• Port 0 occupies a total of 8 pins (pins 32-39). It can be used for
input or output.
• To use the pins of port 0 as both input and output ports, each pin
must be connected externally to a 10K ohm pull-up resistor. This
is due to the fact that P0 is an open drain, unlike P1, P2, and P3.
• Dual role of port-0: Port 0 is also designated as AD0-AD7, allowing
it to be used for both address and data. When ALE = 0, it provides
data D0-D7, but when ALE =1 it has address and data with the help
of a 74LS373 latch.
4.1 8051 IO Ports
1.1 PORT - 0
4.1 8051 IO Ports
1.2 PORT - 1
• Port 1 occupies a total of 8 pins (pins 1 through 8). ‰
Port 1 can be
used as input or output
• In contrast to port 0, this port does not need any pull-up resistors
since it already has pull-up resistors internally
• Upon reset, port 1 is configured as an input port
• To make port 1 an input port, it must be programmed as such by
writing 1 to all its bits
4.1 8051 IO Ports
1.3 PORT - 2
• Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as
input or output. Upon reset, Port 2 is configured as an input port.
• Just like P1, P2 does not need any pull-up resistors since it
already has pull-up resistors internally.
• In many 8051-based system, P2 is used as simple I/O
but in 8031-based systems, port 2 must be used along with P0 to
provide the 16-bit address for the external memory
• Port 2 is also designated as A8 –A15, indicating its dual function
and Port 0 provides the lower 8 bits via A0 –A7.
4.1 8051 IO Ports
1.4 PORT - 3
• Port 3 occupies a total of 8 pins, pins 10 through 17.
• It can be used as input or output.
Upon reset, Port 3 is configured as an input port.
• P3 does not need any pull-up resistors, the same as P1 and P2
did not.
• Port 3 has the additional function of providing some extremely
important signals such as interrupts.
4.1 8051 IO Ports
1.4 PORT - 3
4.1 8051 IO Ports
PORT 1 BITS P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
BIT ADDRESS 97H 96H 95H 94H 93H 92H 91H 90H
PORT 2 BITS P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
BIT ADDRESS A7H A6H A5H A4H A3H A2H A1H A0H
PORT 3 BITS P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0
BIT ADDRESS B7H B6H B5H B4H B3H B2H B1H B0H
4.1 8051 IO Ports
IO Program: 01
4.1 8051 IO Ports
IO Program: 02
• The following code will continuously send out to port 1 the
alternating value 55H and AAH.
4.1 8051 IO Ports
IO Program: 03
4.1 8051 IO Ports
IO Program: 04
4.1 8051 IO Ports
IO Program: 05
4.1 8051 IO Ports
IO Program: 06
4.1 8051 IO Ports
IO Program: 07