0
0
Embedded Cprogramming~10 mins

Why registers control hardware in Embedded C - Test Your Understanding

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

Complete the code to define a hardware register at address 0x4000.

Embedded C
volatile unsigned int* reg = (volatile unsigned int*) [1];
Drag options to blanks, or click blank then click option'
A0x6000
B0x4000
C0x5000
D0x3000
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect memory address for the register.
2fill in blank
medium

Complete the code to write the value 0xFF to the hardware register.

Embedded C
*reg = [1];
Drag options to blanks, or click blank then click option'
A0xFF
B0xF0
C0x0F
D0x00
Attempts:
3 left
💡 Hint
Common Mistakes
Writing a wrong value that doesn't set all bits.
3fill in blank
hard

Fix the error in the code to read the value from the hardware register correctly.

Embedded C
unsigned int value = [1];
Drag options to blanks, or click blank then click option'
Areg*
Breg
C&reg
D*reg
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pointer variable instead of dereferencing it.
4fill in blank
hard

Fill in the blank to set bit 3 of the register without changing other bits.

Embedded C
*reg = *reg [1] (1 << 3);
Drag options to blanks, or click blank then click option'
A|
B&
C<<
D>>
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise AND instead of OR to set bits.
5fill in blank
hard

Fill in the blanks to clear bit 2 and set bit 5 of the register.

Embedded C
*reg = (*reg [1] (1 << 2)) [2] (1 << 5);
Drag options to blanks, or click blank then click option'
A& ~
B|
C&
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using XOR (^) instead of OR to set bits.
Not negating the mask when clearing bits.