0
0
Embedded Cprogramming~10 mins

Configuring pin as input or output in Embedded C - Interactive Practice

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

Complete the code to set pin 5 as an output.

Embedded C
DDRB |= (1 << [1]);
Drag options to blanks, or click blank then click option'
A3
B5
C7
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number in the bit shift.
Forgetting to use the bitwise OR operator.
2fill in blank
medium

Complete the code to configure pin 2 as an input.

Embedded C
DDRD &= ~(1 << [1]);
Drag options to blanks, or click blank then click option'
A1
B3
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR instead of AND to clear the bit.
Shifting by the wrong pin number.
3fill in blank
hard

Fix the error in the code to set pin 7 as output.

Embedded C
DDRC [1] (1 << 7);
Drag options to blanks, or click blank then click option'
A|=
B&=
C^=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which overwrites the entire register.
Using '&=' which clears bits instead of setting.
4fill in blank
hard

Fill both blanks to configure pin 4 as input and enable pull-up resistor.

Embedded C
DDRB [1] ~(1 << 4);
PORTB [2] (1 << 4);
Drag options to blanks, or click blank then click option'
A&=
B|=
C^=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '&=' or '|='.
Not enabling the pull-up resistor after setting input.
5fill in blank
hard

Fill all three blanks to configure pin 3 as output, set it high, and clear pin 6 as input.

Embedded C
DDRD [1] (1 << 3);
PORTD [2] (1 << 3);
DDRD [3] ~(1 << 6);
Drag options to blanks, or click blank then click option'
A|=
C&=
D^=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^=' which toggles bits instead of setting or clearing.
Mixing up PORTD and DDRD registers.