Keil Logo

C51: Reading Port Input Versus Port Latch


Information in this article applies to:

  • C51 Version 5.50a and later

QUESTION

How can I create a program that reads and modifies a port pin using the values of the input pins rather than the values of the output latch?

The ORL instruction will let me set a pin on a port, however, it reads the value of the output latch rather than the values of the input pins.

The MOV, ORL, MOV instruction sequence is what I'm looking for.

ANSWER

This is easily done in C using the Keil compiler. The following example demonstrates this:

unsigned char P1_copy;

P1 |= 0x80;     // Generate ORL P1, 0x80

P1_copy = P1;   // Generate MOV, ORL, MOV sequence
P1 = P1_copy | 0x02;

The generated code is shown below:

0000 439080            ORL     P1,#080H

0003 AF90              MOV     R7,P1
0005 EF                MOV     A,R7
0006 4402              ORL     A,#02H
0008 F590              MOV     P1,A

MORE INFORMATION

  • Refer to ORL in the 8051 Instruction Set Manual.

Last Reviewed: Thursday, February 25, 2021


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.