Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the microcontroller to sleep mode.
Embedded C
MCUCR = (1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong bit like SE instead of SM1.
Confusing SM bits with SE bit.
✗ Incorrect
The SM1 bit in MCUCR register selects the sleep mode.
2fill in blank
mediumComplete the code to enable sleep mode by setting the sleep enable bit.
Embedded C
MCUCR |= (1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the wrong bit like SM0 instead of SE.
Not using bitwise OR to set the bit.
✗ Incorrect
The SE bit enables the sleep mode when set.
3fill in blank
hardFix the error in the code to correctly put the MCU to sleep.
Embedded C
sleep_cpu(); MCUCR &= ~(1 << [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Clearing the wrong bit like SM0 instead of SE.
Not clearing the bit after waking up.
✗ Incorrect
After waking up, the SE bit should be cleared to disable sleep mode.
4fill in blank
hardFill both blanks to create a dictionary of power modes and their descriptions.
Embedded C
const char* power_modes[] = {"Idle", "Power-down", "Power-save", "Standby"};
const char* descriptions[] = {"CPU stopped", "Most devices off", "Timer running", [1];
const char* mode = power_modes[2];
const char* desc = descriptions[[2]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index for descriptions array.
Mixing descriptions for different power modes.
✗ Incorrect
The description for "Standby" mode is "Lowest power mode" and index 2 corresponds to "Power-save" mode.
5fill in blank
hardFill all three blanks to complete the function that configures and enters sleep mode.
Embedded C
void enter_sleep_mode() {
MCUCR = (1 << [1]); // Set sleep mode
MCUCR |= (1 << [2]); // Enable sleep
[3](); // Enter sleep
MCUCR &= ~(1 << [2]); // Disable sleep after wakeup
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong bits for sleep mode selection.
Forgetting to disable sleep after waking.
Not calling the correct function to enter sleep.
✗ Incorrect
Set SM1 bit to select sleep mode, set SE bit to enable sleep, call sleep_cpu() to enter sleep, then clear SE after waking.