In C programming I am writting a program that lights up LEDS
In C programming
I am writting a program that lights up LEDS, Below is part of my code.
my question is how do I explain |= and ^|
GPIOA_ODR |= 0xf000 >> counter;
GPIOB_ODR |= 0xf000 >> counter-16; //>>cause the shift to the right prperly
GPIOC_ODR |= 0xf000 >> counter-32;
GPIOD_ODR |= 0xf000 >> counter-48;
GPIOE_ODR |= 0xf000 >> counter-64;
// TURN OFF LEDs
GPIOE_ODR ^= 0x0f00 << counter-72; //<< causes the shift to the left prperly
//Add 16-8 bc treat port E as low we need
//to fast skip the high port to go quick jump back to port D low
//Add 16-8 to account for not having the low portion of port E
GPIOD_ODR ^= 0x000f << counter-80;
GPIOC_ODR ^= 0x000f << counter-96; //Continue to add 16 bits
GPIOB_ODR ^= 0x000f << counter-112;
GPIOA_ODR ^= 0x000f << counter-128;
Delay_ms(50);
Solution
|= is defined as bitwise inclusive OR and assignment operator.
GPIOA_ODR |= 0xf000 >> counter;
GPIOB_ODR |= 0xf000 >> counter-16; // can be written as
GPIOA_ODR = GPIOA_ODR | 0xf000 >> counter;
GPIOB_ODR = GPIOB_ODR | 0xf000 >> counter-16;
GPIOE_ODR ^= 0x0f00 << counter-72;
GPIOD_ODR ^= 0x000f << counter-80; // can be written as
GPIOE_ODR = GPIOE_ODR ^ 0x0f00 << counter-72;
GPIOD_ODR = GPIOD_ODR ^ 0x000f << counter-80;
| ^= is defined as bitwise exclusive OR and assignment operator. | ||
| |= is defined as bitwise inclusive OR and assignment operator. GPIOA_ODR |= 0xf000 >> counter; GPIOA_ODR = GPIOA_ODR | 0xf000 >> counter; GPIOE_ODR ^= 0x0f00 << counter-72; GPIOD_ODR ^= 0x000f << counter-80; // can be written as GPIOE_ODR = GPIOE_ODR ^ 0x0f00 << counter-72; GPIOD_ODR = GPIOD_ODR ^ 0x000f << counter-80; |
