for 8051s , you can write to the port registers (P0 , P1...) the data required and it will reflect on the output port pins.
when you read the port registers (PO, P1..) you are reading the actual port .
only precaution for 8051s are this:
whwnever you want to read the ports , fist write to the port a 1.
then read the port.
otherwise , the port pin may get damaged.
for writing(output) , no restrictions.
for reading(input) , write a 1 first and then read the port.