Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the GPIO pin 5 as output.
Embedded C
GPIO_DIR |= (1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number in the shift operation.
Forgetting to use the bitwise OR operator.
✗ Incorrect
Pin 5 is set as output by shifting 1 left by 5 positions.
2fill in blank
mediumComplete the code to clear GPIO pin 2 output.
Embedded C
GPIO_DATA &= ~([1] << 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong value to shift.
Not using the bitwise NOT operator.
✗ Incorrect
To clear pin 2, shift 1 by 2 and invert the bits to clear that bit.
3fill in blank
hardFix the error in setting GPIO pin 4 high.
Embedded C
GPIO_DATA [1] (1 << 4);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using &= which clears bits instead of setting.
Using = which overwrites the entire register.
✗ Incorrect
Use bitwise OR assignment (|=) to set pin 4 high without affecting other pins.
4fill in blank
hardFill both blanks to configure pin 3 as input and enable pull-up resistor.
Embedded C
GPIO_DIR [1]= ~(1 << 3); GPIO_PUR [2]= (1 << 3);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using |= to set direction bit instead of clearing it.
Not enabling pull-up resistor correctly.
✗ Incorrect
Use &= with inverted mask to clear pin 3 direction (input), and |= to enable pull-up resistor.
5fill in blank
hardFill all three blanks to toggle pin 6 output safely.
Embedded C
if (GPIO_DATA & (1 << [1])) { GPIO_DATA [2]= ~(1 << [3]); } else { GPIO_DATA |= (1 << 6); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin number in the mask.
Using |= instead of &= to clear the bit.
✗ Incorrect
Check pin 6 status, clear it with &= ~mask if set, else set it with |=.