0
0
Embedded Cprogramming~10 mins

Pull-up and pull-down resistor 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 enable the pull-up resistor on the input pin.

Embedded C
GPIO_PORT->PULLUP_EN = [1];
Drag options to blanks, or click blank then click option'
A0x10
B0xFF
C0x00
D0x01
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0x00 disables the resistor.
Using 0xFF enables all pins, not just the input pin.
2fill in blank
medium

Complete the code to configure the pin as input with pull-down resistor enabled.

Embedded C
GPIO_PORT->DIR &= ~[1];  // Set pin as input
GPIO_PORT->PULLDOWN_EN = [1];
Drag options to blanks, or click blank then click option'
A0x04
B0x08
C0x02
D0x01
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the pin as output by mistake.
Using different masks for DIR and PULLDOWN_EN.
3fill in blank
hard

Fix the error in the code to correctly enable pull-up resistor on pin 5.

Embedded C
GPIO_PORT->PULLUP_EN |= [1];  // Enable pull-up on pin 5
Drag options to blanks, or click blank then click option'
A0x10
B0x40
C0x08
D0x20
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0x10 which is bit 4.
Using 0x40 which is bit 6.
4fill in blank
hard

Fill both blanks to configure pin 3 as input.

Embedded C
GPIO_PORT->DIR [1]= [2]0x08;  // Configure pin 3 as input
Drag options to blanks, or click blank then click option'
A&
B|
C~
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of AND (&).
Not inverting the pin mask (~).
5fill in blank
hard

Fill all three blanks to create a dictionary mapping pin numbers to their pull-up status (1 for enabled, 0 for disabled) for pins 1, 2, and 3.

Embedded C
int pullup_status[] = { [1], [2], [3] };
Drag options to blanks, or click blank then click option'
AGPIO_PORT->PULLUP_EN & 0x02 ? 1 : 0
BGPIO_PORT->PULLUP_EN & 0x04 ? 1 : 0
CGPIO_PORT->PULLUP_EN & 0x08 ? 1 : 0
DGPIO_PORT->PULLUP_EN & 0x10 ? 1 : 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong bit masks for pins.
Not using ternary operator for boolean to int conversion.