4. Introduction :
• Number of 8051 ports : The microcontroller 8051
has four ports P0,P1,P2 & P3.The four ports are
require for i/o operations. Out of the 40 pin,32 pins
are set aside for the four ports P0,P1,P2&P3.Each
port takes 8 pins.
• All the ports are configured as input upon Reset.
• When zero is written to a port , it becomes an
output. To configure it as an input port, 1 needs to
be sent to the port.
6. Port ‘0’
• Port 0 is multi functioned port of microcontroller
8051.Its SFR address is 80H.It is bit addressable port.
• Function and use : It can be used as simple input
/ output mode or for generating data and lower
order address bus for external memory (AD0 –
AD7).
• In order to use the pins of the port 0 as input and
output each pin must be connected to 10KΩ pull up
resistor as shown in figure.
7.
8. Port 0 as simple input port
• When port 0 is used as an input port, ‘1’ must be
written to the corresponding zero latch that will
cause both the output transistor to switch off and
the pin “floats” in a high impedance state. When
configured input port the microcontroller provides
two facilities :
• 1. Read logic level on physical pin by asserting read
pin signal.
9. • 2. Read contents of internal latch by asserting the
read latch signal. The latch is read when the
instruction is read-modify-write type instruction. A
read-modify-write signal is one, wherein the
instruction reads the data from the port modifies it
and writes to the port.
10. Port 0 as simple output
• When port 0 is configured as an output port, the
latch pins that are programmed to 0 will cause the
lower FET to turn ON and pin is grounded.
• If a ‘1’ is written on to the latch pin the FET will turn
off and the pin is pulled HIGH by external pull up
resistors.
12. Port ‘1’
• Port 1 is a one bit simple i/o port of microcontroller.
Its SFR address is 90H.It does not have any extra /
alternate function like port 0.
13. Port 1 as simple input port
• When port 1 is used as an input port, ‘1’ must be
written to the corresponding port 1 latch bit.This
causes the lower FET turn off.The pin and input to pin
buffer are pulled to logic HIGH by the internal pull uo
load.
• Port is called as ‘quasi-bidirectional’ port as its
output is pulled high with pull up resister.
14. Port 1 as simple output port
• When port 1 is used as an output port, the latch pins
that are programmed to 0, will cause the lower FET
turn on, the internal pull up to turn off and input to
the circuit is logic 0.
• If ‘1’ is written onto the latch pin then it will drive the
input of external circuit high through the pull up.The
lower FET turns off.
16. Port ‘2’
• Port 2 of microcontroller 8051 is 8 bit multifuntional
port. Its SFR address is A0H. It is bit addressable port.
• Function and use : It can be used as simple input /
output or for generating the upper order address bus
for the external memory (A8 –A15).
17. Port ‘2’as simple input port
• When port 2 is used as an input port,’1’ must be
written to the corresponding latch bit. This cause the
FET turn off. The pin and input to pin buffer are
pulled to logic high by the internal pull up load.
• Port 2 is called as “quasi-bidirectional port” as its
output is pull up resistors.
18. Port 2 as simple output port
• When port 2 is used as output port, the latch pins
that are programmed to 0, will cause the lower FET
turn off and input to the circuit logic 0.
• If “1” is written onto the latch pin then it will drive
the input of external circuit high through the oull up.
The lower FET turns off.
20. Port “3”
• It is 8 bit multifunctional port.
• Its SFR address is B0H. It is bit addressable port.
• Use : Port 3 is a multifunctional port it can be used as
simple input / output port.
• The port 3 pins have three special functions.this
functions are listed in table.
22. Port 3 as simple input port
• When port 3 is used as input port, “1” must be
written to the corresponding port 3 latch bit.
• This causes the FET turn off.
• The pin and input to the pin buffer are to
pulled to logic HIGH by internal pull up load.
23. Port 3 as simple output port
• When port 3 is used as output port, the latched pins
that are programmed to 0, will cause the lower FET
to turn on, the internal pull up to turn off and input
to the circuit is logic 0.
• If ‘1’ is written onto the latch pin that it will drive the
input external circuit high through the pull up. The
lower FET turns off.
24. Port 3 as one of the alternate function
• For achieving any one of the output function,
another control signal called as “alternate output
function” is available on port 3. Depending on the
logic level present on line “alternate output function”
the FET will turn ON or OFF.
• When the latch bit of port 3 is logic 1, the output is
controlled by the control input.
25. Port 3 loading and interfacing
• The output buffers of ports 1,2&3 can each drive 4 LS
TTL inputs. Port 0 when used in external bus mode
output buffer can drive 8 LS TTL inputs.
• In order to drive inputs these ports as port pins
require external pull ups to drive any inputs.