Of course, a sequence of the following two commands:
A |= 0x02; A &= 0x02;
Equally:
A = 0x02;
If A not a variable, but a hardware register. In this case, you need to refer to the manual of the MCU / CPU (or reconfigured peripherals) to check why this sequence is required.
UPDATE
Variable vs Hardware register
In the comments above, the OP asked a question about how to distinguish between variables and registers.
This is pretty easy. All you have to do is look at the definition. Although a typical variable will be defined as something like:
unsigned char A;
A hardware register definition will look like this:
Here A defined as the value of the hardware register displayed at 0x1234 . Each microcontroller or processor has its own set of hardware registers, and it will vary not only between different types of architectures and models, but also between different manufacturers. If the source code is poorly documented, the only way to tell what exactly is a hardware register is to study the technical description of the hardware. In addition, some advanced architectures can map hardware registers from some peripherals to the address space of the processor, so you can access the hardware registers of external components in the same way.
Pay attention to the volatile keyword. From the wiki :
This keyword does not allow the optimizing compiler to optimize subsequent reads or writes, and thus it is incorrect to use an obsolete value or to omit records. Volatile values mainly occur when accessing hardware (I / O with memory), where reading or writing to memory is used to communicate with peripheral devices and in streaming, where another thread can change the value.
Andrejs Cainikovs
source share