This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading from a port

Hi,

I have just started learning embedded programming on my own. The book I am using (Embedded C Book by Micheal Pont) says:
"because of the underlying hardware, we can only read from a pin if the
corresponding latch contains a '1'."
This line is confusing me as I have been able to read values of the port without initializing it first.
This is my code:

#include <reg52.h>
sbit pin = P2 ^ 1;
void main(void)
{ P2 = 0; while(1) { pin ^= 1; }
}

Debugging shows that it is working just as anticipated. Can someone please explain what's going on here? I am using the Keil C51 simulator (device selected is 8052), could that be the problem?

Thanks in advance.

Aaron

Parents
  • This line is confusing me as I have been able to read values of the port without initializing it first.

    You've been deluding yourself. Nothing in that program of yours reads the port pin at all. You only use write and read-modify-write instructions. The former doesn't read at all, the latter reads the latch, not the pin.

Reply
  • This line is confusing me as I have been able to read values of the port without initializing it first.

    You've been deluding yourself. Nothing in that program of yours reads the port pin at all. You only use write and read-modify-write instructions. The former doesn't read at all, the latter reads the latch, not the pin.

Children