do power down

This commit is contained in:
2025-10-25 14:30:43 +02:00
parent 35c66787de
commit e0781257a6

19
main.c
View File

@ -65,6 +65,9 @@ ISR(PORTA_PORT_vect)
*/ */
int main(void) int main(void)
{ {
// MCU resumes execution here after reset
sleep_disable(); // Disable sleep
// Configure LED pins as outputs // Configure LED pins as outputs
VPORTA.DIR = (PA1_SET_MASK | PA2_SET_MASK | PA3_SET_MASK | PA6_SET_MASK | PA7_SET_MASK); VPORTA.DIR = (PA1_SET_MASK | PA2_SET_MASK | PA3_SET_MASK | PA6_SET_MASK | PA7_SET_MASK);
@ -108,19 +111,17 @@ int main(void)
blinkLed(true); // reset blink state machine blinkLed(true); // reset blink state machine
leds_off(); leds_off();
_delay_ms(BUTTON_IGNORE_DURATION_MS * 2);
// TODO: activate the interrupt for PA0 // TODO: activate the interrupt for PA0
PORTA.PIN0CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; PORTA.PIN0CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc;
sei(); // Enable global interrupts set_sleep_mode(SLEEP_MODE_STANDBY); // Deepest sleep mode (standby)
while (1) sleep_enable(); // Enable sleep
{
leds_off();
_delay_ms(BUTTON_IGNORE_DURATION_MS / 20);
leds_on();
_delay_ms(BUTTON_IGNORE_DURATION_MS / 20);
}
// TODO: add a isr that disabled all leds and loops in while(1); cli(); // Disable global interrupts
sei(); // Re-enable interrupts
sleep_cpu(); // MCU sleeps here
} }
else else
{ {