This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Bit fileds and logic operation

Hello!

Here is my problem. I have 3 LEDs and 1 button. Let's LEDs are connected to GPIO0, GPIO1 and GPIO2. I want when the button is pressed, the LEDs light up in accordance with a binary code (i.e. 000 -> 001 -> 010 -> 011 -> 100 -> 101 -> 110 ->111 -> 000 -> 001 -> ...)

And my LEDs light up when GPIO is in low level. So I must write in GpioDataRegs inverse information (i.e. 111 -> 110 -> 101 -> 100 -> 011 -> 010 -> 001 ->000 -> 111 -> 110 -> ...).

I created bit field like this:

struct LED_bits
{

Uint32 LEDs :3;
Uint32 x :2; //
Uint32 y :2;
Uint32 z :1;
....

....

};

union LED_union

{

Uint32 all;
struct LED_bits bit;

};

struct LED_REG

{

union LED_union LED;

};


Now when I press the button, simple instruction

LED_REG.LED.bit.LEDs++;

does almost all work. I mean it counting from 0 to 7 and then again 0.

Then I must latch GPIOs. If i wrote

GpioDataRegs.GPADAT.all = ~LED_REG.LED.bit.LEDs;

then all works and my LEDs light up in right sequence. But all others GPIOs go to high state. And it's bad.

Then I tried to use mask and wrote

GpioDataRegs.GPADAT.all &= (0xFFF8 | (~LED_REG.LED.bit.LEDs));

and it doesn't work at all.
In Code Composer Expressions "0xFFF8 | (~LED_REG.LED.bit.LEDs)" always equals to constant. While LED_REG.LED.bit.LEDs is changing from 0 to 7.

I tried different versions of expressions, but none of them worked. How can I create right mask to use in this situation.