Keil Logo

bit

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

bit name <[>= value<]>;

Where

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 8051-compatible internal memory area of the 251. Because this area is only 16 bytes long, a maximum of 128 bit variables may be declared within any one scope.

Note

  • Accesses to the 251's extended bits generate more code than accesses to the standard 8051-compatible bit area. Therefore, you should use the standard 8051-compatible bit area as much as possible to maximize performance.

The 251 supports an extended bit-addressable area that is located in the data memory address range 0x20-0x7F. This extended bit area supports a maximum of 768 bit variables. To locate a bit in the extended bit area, specify bit ebdata as shown in the example below.

bit ebdata state1;          /* bit in 251 extended space         */
bit function (bit flag)  {  /* parameters are only in 8051 space */
  bit ebdata  local_bit;    /* local bit in 251 space            */

  local_bit = flag;

  return (local_bit);       /* return 251 extended bit           */
}

Note

  • It is not possible to locate bit function parameters in the extended 251 bit space.

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 C251 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.