0
0
Embedded Cprogramming~10 mins

GPIO register configuration in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A1
B3
C7
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number in the shift operation.
Forgetting to use the bitwise OR operator.
2fill in blank
medium

Complete the code to clear GPIO pin 2 output.

Embedded C
GPIO_DATA &= ~([1] << 2);
Drag options to blanks, or click blank then click option'
A0
B2
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong value to shift.
Not using the bitwise NOT operator.
3fill in blank
hard

Fix 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'
A&=
B|=
C^=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using &= which clears bits instead of setting.
Using = which overwrites the entire register.
4fill in blank
hard

Fill 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'
A&
B|
C~
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using |= to set direction bit instead of clearing it.
Not enabling pull-up resistor correctly.
5fill in blank
hard

Fill 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'
A6
B&=
C~
D|=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin number in the mask.
Using |= instead of &= to clear the bit.