Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

When a port data register (I/O Address 00H, 01H, 02H, 03H) is written and then immediately read back, why are the values different?

When a port data register (I/O Address 00H, 01H, 02H, 03H) is written and then immediately read back, why are the values different?

Anonymous
Not applicable
Question: When a port data register (I/O Address 00H, 01H, 02H, 03H) is written and then immediately read back, why are the values different?  This question applies to: CY7C64013, CY7C64113, CY7C65013, CY7C65113, CY7C66013, CY7C66113.

 

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.

0 Likes
1726 Views
Contributors