Keil™, An ARM® Company

C166 User's Guide

Using the bdata Type

Some users have reported difficulties in using the bdata memory type. Using bdata is similar to using the sfr modifier. The most common error is encountered when referencing a bdata variable defined in another module. For example:

extern char bdata xyz_flag;

sbit xyz_bit1 = xyz_flag^1;

In order to generate the appropriate instructions, the compiler must have the absolute value of the reference to be generated. In the above example, this cannot be done, as the address of xyz_flag is not known until after the linking phase has been completed. Follow the rules below to avoid this problem.

  • A bdata variable (defined and used in the same way as an sfr) must be defined in global space and not within the scope of a procedure.
  • A bdata bit variable (defined and used in the same way as an sbit) must also be defined in global space and cannot be located within the scope of a procedure.
  • The definition of the bdata variable and the creation of its sbits must be accomplished within a single source module.

For example, declare the bdata variable and the bit component in the same source module:

char bdata xyz_flag;
sbit xyz_bit1 = xyz_flag^1;

Then, declare the bit component external:

extern bit xyz_bit1;

As with any other declared and named C variable that reserves space, simply define your bdata variable and its component sbits in a module. Then, use the extern bit specifier to reference it as the need arises.