Question.3
Which of the following statements is true? (After executing the code)
Code
#include <avr/sleep.h> // Include library for sleep functions
// Function to disable Brown-Out Detection (BOD) and put MCU into Power-down Sleep Mode
void disableBODAndSleep() {
cli(); // Disable global interrupts to avoid unintended execution during configuration
sleep_enable(); // Enable sleep mode
// Disable Brown-Out Detection (BOD)
MCUCR |= (1 << BODS) | (1 << BODSE); // Set BODS and BODSE bits to enable BOD disable feature
MCUCR &= ~(1 << BODSE); // Clear BODSE within 4 clock cycles to disable BOD
sei(); // Re-enable global interrupts to allow wake-up sources to function
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set Power-down mode
sleep_mode(); // Put the MCU into sleep mode
sleep_disable(); // Disable sleep mode after waking up
}
void setup() {
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), wakeUp, FALLING);
}
void loop() {
disableBODAndSleep(); // Put MCU into deep sleep, will wake up on external interrupt
}
// Interrupt Service Routine (ISR) to handle the wake-up event
void wakeUp() {
// Empty ISR: Execution resumes after sleep_mode() when an interrupt occurs
}