Check this two cases in Keil C51 and observe P0 peripheral option in debugger for both cases. The result is different in two cases.Why P0=0xFF; instruction doesn't produce same result?
case 1)
main()
{P0=0x00;
P0=0xFF;
while(1);
}
case 2)
main()
{
P0=0xFF;
while(1);
}
case 1 program
case 1 peripheral window while debugging
case 2 peripheral window while debugging
Target Device 89S52 -- 8051 Based microcontroller
I checked with different values instead of 0x00 for P0 before writing 0xFF. In all cases previous value is read in the final stage.
Result:P0 pins = 0x10 ,P0 registers = 0xFF
Since P0 doesn't have pull up resistors for I/O operation,when we write 0xFF, the pins are in high impedance state. So,in the software debugger, variable corresponding to P0 pin value contains the previous value.Its not changing. But in the hardware, pins with coressponding latch value 1 will be floating.
Different cases checked.
Result: P0 pins = 0x01 ,P0 registers = 0xF1 (Bits corresponding to 1s in register remained same)
Result: P0 pins = 0x03 ,P0 registers = 0xC3