As we all know in order to make a port input in 8051 we have to write FFH to that. That is,


after this execution does it mean all the pins of the port is set to high? In other word at that moment if I connect 8 LEDs to those pins will they turn on (though I know they have been configured as input port hence we should not try to use them as output port)? If no, then why


is making the accumulator FFH?

  • 2
    \$\begingroup\$ please don's say As we all know because it is not true, we don't all know \$\endgroup\$
    – jsotola
    Commented Jul 18, 2021 at 20:03
  • 2
    \$\begingroup\$ if I connect 8 LEDs to those pins ... please draw a diagram of how the LEDs are connected \$\endgroup\$
    – jsotola
    Commented Jul 18, 2021 at 20:17
  • \$\begingroup\$ Positive pin of the LED is attached to the port pin, and negative pin is grounded. \$\endgroup\$
    – Sayan
    Commented Jul 18, 2021 at 20:19
  • 1
    \$\begingroup\$ imagine a switch between the output pin and ground ... that is how the output is wired ... the LED would not light .... the LED has to be connected between output and Vcc ..... google open collector LED ...... duckduckgo.com/… \$\endgroup\$
    – jsotola
    Commented Jul 18, 2021 at 20:22
  • 2
    \$\begingroup\$ Which 8051? If you really mean the ancient original Intel 8051, then maybe, because it has open-drain IO pins. \$\endgroup\$
    – Justme
    Commented Jul 18, 2021 at 20:22

1 Answer 1


The standard 8051 has a quite simple port circuit on P1. Is it made from an open-drain output and a pull-up circuit. For example:

(C)1995 Copyright Siemens

The open-drain output is realized by n3. This transistor is capable to drain some current, refer to the data sheet of your controller. It drives the output "low" when you output a 0.

n1 and n2 form the pull-up, providing some stronger current (n1) and some weaker current (n2) to a sink at the port pin. This way a "high" is output.

What is the reason for n1 and its driving circuit? Well, if the output has to change from "low" to "high", it drives for 2 system clock cycles some more current. This way the raising edge at the output is shorter, because the inevitable parasitic capacitance is charged faster.

To use the pin as input, you will output a 1. This opens n3 and (after the 2 cycles mentioned above) lets n2 provide the "high" level. If you leave the pin unconnected or floating, if will be read as 1. If you source it with a "high", it will also be read as 1. To input "low", your external signal source needs to drive the pin to ground. Refer to the data sheet to find out how much current you will need to safely get under the 0 threshold.

(C)1995 Copyright Siemens

In short:

  • Output 0: strong "low" to external circuit
  • Output 1: weak "high" to external circuit
  • Output 1, input "floating": read 1
  • Output 1, input "high": read 1
  • Output 1, input "low": read 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.