This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Bit variables

I want to define a 8 BIT variable and char variable that occoupy the same memory loaction in the memory.
so any change in the char variable should reflect the bit variable.
In C we can define a structure for bit
struct num
{

unsigned char X:1; unsigned char Y:1; unsigned char Z:1; unsigned char A:1; unsigned char B:1; unsigned char C:1; unsigned char D:1; unsigned char E:1;
};

struct num Axis_Move ;

How i can define a Union having one char and 8 BIT variable

Parents
  • We can do by following way also

    unsigned char bdata Flag;

    sbit One = Flag^0;
    sbit Two = Flag^1;
    sbit Three = Flag^2;
    sbit Four = Flag^3;
    sbit Five = Flag^4;
    sbit Six = Flag^5;
    sbit Seven = Flag^6;
    sbit Eight = Flag^7;

    but what if the controller dosent have the bdata

Reply
  • We can do by following way also

    unsigned char bdata Flag;

    sbit One = Flag^0;
    sbit Two = Flag^1;
    sbit Three = Flag^2;
    sbit Four = Flag^3;
    sbit Five = Flag^4;
    sbit Six = Flag^5;
    sbit Seven = Flag^6;
    sbit Eight = Flag^7;

    but what if the controller dosent have the bdata

Children
  • "We can do by following way also"

    Of course you can. Why did you ask for a union, then?

    "but what if the controller dosent have the bdata"

    What do you mean? All 8051 derivatives have bit-addressable memory. Whether you use it as such or not is up to you.