Keil C51 8051 Port 0 I/O

548 Views Asked by At

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 program

case 2 peripheral window while debugging

Target Device 89S52 -- 8051 Based microcontroller

1

There are 1 best solutions below

0
On

I checked with different values instead of 0x00 for P0 before writing 0xFF. In all cases previous value is read in the final stage.

P0=0x10;
P0=0xFF;

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.

P0=0x07;
P0=0xF1;

Result: P0 pins = 0x01 ,P0 registers = 0xF1 (Bits corresponding to 1s in register remained same)

P0=0x13;
P0=0xC3;

Result: P0 pins = 0x03 ,P0 registers = 0xC3