ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


Information in this article applies to:


The IAR C Compiler supports a construct PORT.BIT that lets me set, clear, or test a bit of an SFR port as follows:

P2.3 = 1;       /* Set Bit */
P2.3 = 0;       /* Clear Bit */

if (P2.3 == 1)  /* Test Bit */

Is there a way to do this with the Keil C compiler?


Yes. However, the Keil compiler doesn't support the dot ('.') method of accessing bits within an SFR.

In the Keil compiler, you declare the SFRs and bits as variables and access them that way. For example:

sfr P1 = 0x90;     /* Declare an SFR for Port 1 */
sbit P1_1 = P1^1;  /* Declare a BIT for P1.1 */

void func (void)
P1_1 = 0;       /* Clear Bit */
P1_1 = 1;       /* Set Bit */

if (P1_1 == 1)  /* Test Bit */

Article last edited on: 2000-09-12 00:00:00

Rate this article

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