ARM Technical Support Knowledge Articles

HOW DO I READ A LATCH?

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

How I can read the latch for an I/O port instead of reading the pins (from C)?

ANSWER

There is no way to read the latch value of an 8051 I/O port. However, there are instructions that allow you to read, modify, and write back the new value to the port latch. Basically, the ANL, ORL, and XRL instructions support this READ-MODIFY-WRITE feature.

If you must have access to the port latch you can create a shadow variable that contains the latch value. For example:

sfr P1 = 0x90;
unsigned char P1_shadow = 0xFF;   // same reset as P1
.
.
.
P1 &= 0xF0;
P1_shadow &= 0xF0;
.
.
.
P1 |= 0x03;
P1_shadow |= 0x03;

Then, when you need to know how the latch is set you can read the P1_shadow variable.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-09-22 11:34:32

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential