From fa41ddb97732028920fadbfabb30706911c21139 Mon Sep 17 00:00:00 2001 From: Sanyog Date: Fri, 20 Sep 2024 21:32:19 +0530 Subject: [PATCH] add GPIOF interrupt handler --- main.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 9ec13b9..97869be 100644 --- a/main.c +++ b/main.c @@ -23,18 +23,34 @@ void GPIO_PORT_F_init(void) GPIO_PORTF_IEV_R = 0x00; // Falling edge event GPIO_PORTF_IM_R |= 0x11; // Unmask interrupts for PF0 and PF4 } -void systick_setting(void) // SYSTICK SETUP FUNCTION +void systick_setting(void) // SYSTICK SETUP FUNCTION { - STRELOAD = SYSTICK_RELOAD_VALUE(1000); // RELOAD VALUE FOR 1ms - STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick with system clock - STCURRENT = 0; // Clear current value + STRELOAD = SYSTICK_RELOAD_VALUE(1000); // RELOAD VALUE FOR 1ms + STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick with system clock + STCURRENT = 0; // Clear current value } -void delay(int us) //DEFINING DELAY FUNCTION +void delay(int us) //DEFINING DELAY FUNCTION { - STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY - STCURRENT = 0; // Clear STCURRENT - STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick - while ((STCTRL & (1 << 16)) == 0); // Wait until flag is set - STCTRL &= 0x0; // Stop the timer + STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY + STCURRENT = 0; // Clear STCURRENT + STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick + while ((STCTRL & (1 << 16)) == 0); // Wait until flag is set + STCTRL &= 0x0; // Stop the timer +} + +void GPIOF_interruptHandler(void) // Interrupt handler for GPIO Port F +{ + delay(200000); // DEBOUNCE DELAY + if (GPIO_PORTF_RIS_R & 0x10) // CHECK IF SWITCH 1 CAUSED INTERRUPT + { + GPIO_PORTF_DATA_R ^= 0x02; // TOGGLE RED LED + GPIO_PORTF_ICR_R = 0x10; // CLEAR INTERRUPT FLAG FOR SWITCH 1 + } + + if (GPIO_PORTF_RIS_R & 0x01) // CHECK IF SWITCH 2 CAUSED INTERRUPT + { + GPIO_PORTF_DATA_R ^= 0x02; // TOGGLE RED LED + GPIO_PORTF_ICR_R = 0x01; // CLEAR INTERRUPT FLAG FOR SWITCH 1 + } }