0
0
Embedded Cprogramming~10 mins

Writing to a hardware register 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 write the value 0xFF to the hardware register.

Embedded C
volatile uint8_t *reg = (volatile uint8_t *)0x4000;
*reg = [1];
Drag options to blanks, or click blank then click option'
A255
B0x0F
C0x00
D0xFF
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0x00 which clears the register instead of setting it.
Using decimal 255 without 0x prefix which is valid but less common in embedded C.
2fill in blank
medium

Complete the code to set bit 3 of the hardware register without changing other bits.

Embedded C
volatile uint8_t *reg = (volatile uint8_t *)0x4000;
*reg |= [1];
Drag options to blanks, or click blank then click option'
A0x08
B0x04
C0x10
D0x01
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0x04 which sets bit 2 instead of bit 3.
Using 0x10 which sets bit 4 instead of bit 3.
3fill in blank
hard

Fix the error in the code to clear bit 2 of the hardware register without changing other bits.

Embedded C
volatile uint8_t *reg = (volatile uint8_t *)0x4000;
*reg &= [1];
Drag options to blanks, or click blank then click option'
A0x02
B0x04
C~0x04
D~0x02
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0x04 which would keep only bit 2 and clear others.
Using ~0x02 which clears bit 1 instead of bit 2.
4fill in blank
hard

Fill both blanks to toggle bit 1 of the hardware register using XOR.

Embedded C
volatile uint8_t *reg = (volatile uint8_t *)0x4000;
*reg [1]= [2];
Drag options to blanks, or click blank then click option'
A^
B|
C0x02
D0x01
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of XOR (^) which only sets bits.
Using 0x01 which toggles bit 0 instead of bit 1.
5fill in blank
hard

Fill all three blanks to write the value 0xAA to the register, then clear bit 7 and set bit 0.

Embedded C
volatile uint8_t *reg = (volatile uint8_t *)0x4000;
*reg = [1];
*reg &= [2];
*reg |= [3];
Drag options to blanks, or click blank then click option'
A0xAA
B~0x80
C0x01
D0xFF
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0xFF instead of 0xAA as initial value.
Using 0x80 instead of ~0x80 to clear bit 7.
Using 0x02 instead of 0x01 to set bit 0.