In the development of embedded software, the more common operation is register operation.
For the more lack of hardware knowledge of computer software professionals born, sometimes become a headache, so I summed up a little about register operation of some common usage
Assignment operation Method of register
For illustration convenience, define the following 3 8-bit registers:
#define REG 0XFFFFFF10
1, assigning values to a single bit
(1) Place the Register Reg's 5th position "1"
REG |= (1 << 5);
(2) clearing the Register Reg's 5th digit
REG &= ~ (1 << 5);
(3) The Register reg 3rd, 5 position "1"
REG |= (1 << 5) | (1 << 3);
(4) Clearing the Register Reg's 3rd and 5 digits
REG &= ~ ((1 << 5) | (1 << 3));
2, Direct assignment
(1) Register Reg 0, 1, 2, 3, 5, 7 position "1"
REG = 0x5f;
(That is, give the register REG1 to 1010 1111, this method is more in the initialization of the use)
(2) Register Reg 1, 3, 5, 7 location "1", 0, 2 position "0"
UInt32 temp;
TMEP = REG;
temp &= ~0x01;
Temp |= (1 << 1);
Temp &= ~ (1 << 2);
temp |= (1 << 3);
temp |= (1 << 5);
temp |= (1 << 7);
REG = temp;