From e16552b4bc79fd92e40b1543fc5b0681d44d85be Mon Sep 17 00:00:00 2001 From: hugo LAMY Date: Mon, 10 Mar 2025 18:38:24 +0100 Subject: [PATCH] mod04 ex00 ok --- module04/ex00/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module04/ex00/main.c b/module04/ex00/main.c index 9b9e6ca..2a85dc7 100644 --- a/module04/ex00/main.c +++ b/module04/ex00/main.c @@ -13,10 +13,10 @@ typedef enum { volatile uint8_t button_state = UP; // Table 13-2 : interrupt types -#define INT0_LOW ((0 << ISC01) | (0 << ISC01)) -#define INT0_LOGICAL ((0 << ISC01) | (1 << ISC01)) -#define INT0_FALLING ((1 << ISC01) | (0 << ISC01)) -#define INT0_RAISING ((1 << ISC01) | (1 << ISC01)) +#define INT0_LOW ((0 << ISC01) | (0 << ISC00)) +#define INT0_LOGICAL ((0 << ISC01) | (1 << ISC00)) +#define INT0_FALLING ((1 << ISC01) | (0 << ISC00)) +#define INT0_RAISING ((1 << ISC01) | (1 << ISC00)) // use interruption to change led1 state when button1 is pressed int main() { @@ -27,17 +27,17 @@ int main() { SREG |= ENABLE_GLOBAL_INTERRUPT; - EIMSK = (1 << INT0); // 13.2.2 : Enable INT0 interrupt (EIMSK – External Interrupt Mask Register) - EICRA = INT0_LOGICAL; // Table 13-2 : trigger type (EICRA – External Interrupt Control Register A) + EIMSK = (1 << INT0); // 13.2.2 : Enable INT0 interrupt (EIMSK – External Interrupt Mask Register) + EICRA = INT0_LOGICAL; // Table 13-2 : trigger type (EICRA – External Interrupt Control Register A) while (1); } ISR(INT0_vect) { - _delay_ms(50); button_state = (button_state == UP) ? DOWN : UP; if (button_state == UP) { TOGGLE_ELEM(LED1); } - // EIFR = (1 << INTF0); // 13.2.3 : clear flag, why ? i think it only indicates that a trigger event has occured + _delay_ms(50); // for debounce, bad idea to put it here in more complexe codes, it is blocking + EIFR |= (1 << INTF0); // 13.2.3 : clear flag, when the flag is set it triggers the interrupt, and eventhough it should be clear by the trigger, it can be set again by the bouncing }