ARM Technical Support Knowledge Articles

READING PORT INPUT VERSUS PORT LATCH

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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 that I need to get.

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

Article last edited on: 2007-01-31 11:55:40

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