C166 User's Guide

bdata

The bdata memory type may be used to declare variables only. You may not declare bdata functions. This memory is accessed using 16-bit addresses and is the on-chip bit-addressable memory of the C16x/ST10/XC16x. This memory (which is limited to 512 bytes) may be accessed as bytes or as bits.

Variables declared bdata are located in the SDATA group.

Declare bdata variables as follows:

unsigned int bdata ba_var;

Declare bits within a bdata variable as follows:

sbit ba_bit_0 = ba_var ^ 0;    /* Bit 0 of ba_var */
sbit ba_bit_8 = ba_var ^ 8;    /* Bit 8 of ba_var */

The C16x/XC16x/ST10 microcontrollers provide very efficient bit instructions. A bit-field structure that has single bit members is located in the BDATA address space by using the memory type bdata. In this case bit-fields are accessed with the efficient bit instructions. For example:

struct test {
  int bit0: 1;
  int bit1: 1;
  int bit2: 1;
  int bit3: 1;
  int bit4: 1;
  int bit5: 1;
};

struct test bdata t;

void main (void)  {
  t.bit0 = 1;
  if (t.bit1) {
    t.bit2 = t.bit0;
  }
}

You may use the HOLD directive to locate structures with single-bit bit-fields to the BDATA memory area. The compiler then generates bit instructions to access the bit-fields. For example:

C166 MYPROG.C HOLD (bdata 2, near 6)

locates all structures (smaller than 2 bytes) with bit-fields to the BDATA memory.

Note

  • sbit variables can only be defined at file level. It is impossible to define automatic sbit variables or to use sbit in local function variables. You may use instead bit-field structures.

Related Knowledgebase Articles