When a port data register (00H  01H  and 02H)  is written and then immediately read back  why are the values differen...

Question: When a port data register (00H, 01H, and 02H)  is written and then immediately read back, why are the values different?  This question applies to: CY7C63221, CY7C63231A, CY7C63722, CY7C63723, CY7C63742, CY7C63743.

 

Answer:

When performing an IORD on the port data registers, you are actually reading the voltage on the port pins themselves, not the value written to the register.

CYDB uses an IORD instruction to display register values in the I/O Register window, so again the value displayed for the data port registers pertains to the voltage on the port pins.

When using the ByteCraft C compiler you need to pay special attention to the following:

When writing C code and you try to set a bit in a port data register i.e. PORT0.0 = 1, the code has no way of reading the Port0 register's present value and only manipulating a single bit.  You can't say Port0 = Port0 | 0x01 for example.  What would really happen instead is Port0 = (Voltages on Port0 pins) | 0x01.  

Instead you should keep a shadow register of the port data registers.