8051 bit variables

  • Bob Armstrong

    Bob Armstrong - 2008-10-18

      In SDCC, I know about the __bit storage class, but is there a way to declare a byte variable, tell the linker to place it in the 8051's bit addressible segment, and then address individual bits within that byte?  For example (using the Keil syntax)

    unsigned char bdata X;

      X.1 = 1;  X.2 = 0; ...
      if (X.3) ...
      X = 0;

    ... etc   ..

      With the __bit storage class I can allocate individual bits, but I need to be able to allocate 8 bits, force them to be grouped together into a byte, and then also address that byte as a byte value as well as individual bits.

    Bob Armstrong

    • Ronald Marcus

      Ronald Marcus - 2008-10-20

      You can hard code the bit variables to the start if bit ram 0x20?. Bit 0 starts here. Then declare a byte variable with the address 0x20.Both variable sets should occupy the same ram space.
      PS. Check that it is in fact 0x20 in your system.


Log in to post a comment.