Keil Logo


The bit type defines a single-bit variable. It is used as follows:

bit name <[>= value<]>;


name is the name of the bit variable.
value is the value to assign to the bit.

The bit type may be used for variable declarations, argument lists, and function-return values. A bit variable is declared like other C data types. For example:

static bit done_flag = 0;    /* bit variable */

bit testfunc (               /* bit function */
  bit flag1,                 /* bit arguments */
  bit flag2)
return (0);                  /* bit return value */

All bit variables are stored in a bit segment located in the internal memory area of the 8051. Because this area is only 16 bytes long, a maximum of 128 bit variables may be declared within any one scope.

Memory types may be included in the declaration of a bit variable. However, because bit variables are stored in the internal data area of the 8051, data and idata memory types only may be included in the declaration. Any other memory types are invalid.

The following restrictions apply to bit variables and bit declarations:

  • A bit cannot be declared as a pointer. For example:
    bit *ptr;         /* invalid */
  • An array of type bit is invalid. For example:
    bit ware [5];     /* invalid */
  • Functions that disable interrupts (#pragma disable) and functions that are declared using an explicit register bank (using n) cannot return a bit value. The Cx51 Compiler generates an error message for functions of this type that attempt to return a bit type.
  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.