How can I read a value from an I/O line of the 8052?
Submitted By: Craig Steiner FAQ Last Modified: 07/10/06
- You may read a value by reading the corresponding SFR or bit. For example, if you wish to read the value on P1.3, you may either use the assembly instruction MOV A,P1 (which reads the value of all bits on P1) or you may read just the bit itself with the MOV C,P1.3. Either way, make sure you've previously written a "1" to the bit(s) you wish to read. That is, if you want to be able to read all lines of P1, you must first be sure that P1 has been initialized to FFh (MOV P1,#0FFh). This is the default condition, so unless you've changed the value of the port lines you should be able to read all bits on start-up. Initializing to FFh is always a good idea, though.
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.