We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 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.
for each SFR there will be a reset value listed
Erik
Thanks for the reply.
By further playing with the simulator, I have concluded following. Please correct me if I am wrong.
"In order to read the value of a port (pin), the corresponding latch (pin) should first be set. This doesn't affect the value being read from the PORT itself as the initialization is performed before the value is read off it."
Thanks and sorry for bothering you again.
" href= "http://www.8052.com/faqs.phtml?FAQ=119915">www.8052.com/faqs.phtml " href= "http://www.8052.com/faqs.phtml?FAQ=119917">www.8052.com/faqs.phtml " href= "http://www.8052.com/faqs.phtml?FAQ=121619">www.8052.com/faqs.phtml
Thanks a lot Erik.
Aaron.