Why are the port pins high in 8051

The outputs and inputs of the 2051

The output configuration of an 8051-compatible is quite peculiar. If a 0 is written to an I / O port, a transistor opens, which pulls the pin responsible for this directly to GND. This transistor is specified for 20mA, but not protected by a resistor. If you switch the pin to Vcc with a consumer that needs more than 20mA, this transistor will burn out: the controller is damaged.
A pin can be used as a guideline never with less than 330 ohms to switch directly to Vcc. If you want to operate a light-emitting diode directly on the chip, the voltage drop through the diode must of course be subtracted beforehand. The series resistor for a standard LED at 5V is therefore around 180 ohms.

Another limit value has to be observed: for the AT89C2051 the manufacturer only guarantees a total load of 80mA for all pins in total. A 7 segment display with 7x20mA would clearly exceed the maximum value with 140mA. However, in my experience, you shouldn't take this limit value so narrowly, in contrast to the 20mA per pin. The 80mA apply to a maximum working temperature of 125 ° C. If you don't install the chip in your heating system or in your car, you can safely demand a lot more performance at normal room temperature. A 7 segment display with a decimal point can therefore also be implemented without additional power drivers.

If you write a 1 to an I / O port, a transistor (or FET) generates a weak pull-up, as shown in the diagram Depletion Mode FET called, connected to Vcc. This can easily be pulled from a circuit to GND, and thereby also realizes the input function. If this pull-up is loaded with 80µA, the output voltage drops from 5V to 2.4V. Because this one pull-up is too weak to realize fast signals with steep edges, there is a second one, called Enhancement Mode FET designated transistor. With each low-to-high transition of the output, this is only activated for two oscillator cycles, at 24MHz for 83ns, and is designed to be much stronger.

One thing in particular follows from this: The high state of the pin is quite unsuitable for applications beyond digital technology, as it is very weak and designed with wide tolerances, and it also changes shortly after activation. If you are not operating with FET circuits that have a very high input resistance, you should use the low state for switching, the 20mA of which is also sufficient for more power-hungry circuits. Apart from that, there is another point that speaks in favor of switching with the 0 instead of the 1:
The reset state for all pins is the logical 1. If 1 were to be used for switching, the motors, pumps or lamps that are controlled with it would start up briefly each time for the moment of the reset, until the program takes control and switches it off again. If a large capacitor is installed in the + 5V supply for support, which is loaded by this brief start-up of the consumer, then under unfavorable circumstances the input voltage can collapse immediately after the reset due to the not yet fully charged capacitor, so that the chip immediately again crashes or gets stuck in reset.