This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Difference between making P1 I/O or sending data on it

I want to assign value 0x0f to port P1 of 8051(which is to be configured as an output port).

If I give the instruction
P1 = 0x00

it assigns P1 as output port. Now suppose I want to out data 0x0f on it, then will the subsequent instruction
P1 = 0x0f
out the required data on P1 or will it again initialise the P1 pins 0-3 as input and pins 4-7 as output pins?

How can we distinguish whether the statement is assigning data on the output port or initialising port as input/output?

Regards,

Mohit

  • Ports are always outputs. If you write a '0' to a port bit, the appropriate pin is switched to low level. If you write a '1' to a port bit, the pin is switched to high level. There is a strong pullup in the controller which is active for 2 clock cycles when the output is switched from '0' to '1'. The steady state after switching is held by a weak pullup. This weak pullup may be overridden by an external source and so the port pin can be used as in input.

    Care must be taken if inputs and outputs share one port. Some instructions access all bits of the port. Incorrect handling by the programmer may result in inputs stuck at zero.

    HHK