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
This is an 8052 specific statement. The 8052 has pseudo bi-direction port pins (on standard versions). if you want to read a pin you must have first written a '1' to it (the reset state) this is because the port has the equivalent of a weak pull-up and a strong pull down. so an external signal can overcome a a port with a 1, but not a zero (in fact trying to put a 1 into a pin that has a 0 written to it can damage the pin)