Keil Logo

C51: READING FROM AN INPUT PORT


Information in this article applies to:

  • C51 Version 5.50a
  • C51 Version 6.01

QUESTION

How do I read from one of the I/O ports on the 8051?

ANSWER

To read an I/O port on the 8051, you must ensure that the internal latch state is at a high level. To ensure that the port bit is high, write a 1 to it. Then you may simply read the port or port bit.

For example:

sbit P1_1 = 0x91;

P1_1 = 1;    // Set port for input
var = P1_1;  // Read P1_1 into var

SEE ALSO

Last Reviewed: Saturday, June 24, 2000


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.