Please let me know what is the meaning of this command below.
" if((GPIO & 0x33) != 0x33)" // wait for switch to go low
The first part of the
if statement expression,
Code:
([COLOR="#FF0000"]GPIO & 0x33[/COLOR]) != 0x33
Masks the value of GPIO to the value of 0x33.
The bitwise AND operator (&) masks all the bits of first operand (GPIO) with the value of the second operand (0x33 or 0b00110011).
The operation essentially clears all corresponding bits which are not set and leaves any corresponding bits set unchanged.
Therefore bits 0, 1, 4 and 5 of the value in GPIO are left unchanged while all other bits are cleared.
The second part of
if statement expression,
Code:
(GPIO & 0x33) [COLOR="#FF0000"]!= 0x33[/COLOR]
Simply tests whether the results of the mask operation are not equal to the value 0x33.
Essentially if
any of the bits 0, 1, 4, or 5 are clear the expression is true, if they are
all set then the expression is false as the resulting is indeed 0x33.
Perhaps there are switches attached to the lines, GPIO0, GPIO1, GPIO4 and GPIO5, these lines are normally held high, however when a switch is closed the corresponding line goes low which causes the
if statement expression to become true, the contents of which handle the switch closure.
Mask (computing)
Bit Operations
BigDog