When a port data register (00H 01H and 02H) is written and then immediately read back why are the values differen...
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
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.
-
This widget could not be displayed.Anonymous