ARM Technical Support Knowledge Articles

ACCESSING SPECIAL FUNCTION REGISTERS IN C

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

How do I access the 8051's Special Function Registers (SFRs) in my C programs?

ANSWER

The C51 Compiler offers 3 extensions to the C programming language that allow you to access the SFRs of the 8051. These keywords are:

You use these keywords to define the name and address for an SFR. The name may be any valid C variable name. The address must be the address that is associated with the desired SFR. Refer to your databook for the SFR addresses.

The following example defines the SFR for Port 1. P1 is used as the name and 0x90 is the address.

sfr P1 = 0x90;

The following example defines the SFR bit for Port 1.1. P1_1 is the name and 0x91 is the address of P1.1.

sbit P1_1 = 0x91;

The following example defines the 16-bit SFR for Timer 2. T2 is the name and 0xCC - 0xCD is the address.

sfr16 T2 = 0xCC;

MORE INFORMATION

SEE ALSO

Article last edited on: 2006-03-12 09:12:12

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