add GPIOF interrupt handler

This commit is contained in:
Sanyog Nevase Nevase 2024-09-20 21:32:19 +05:30
parent 4fd7019fd3
commit fa41ddb977
1 changed files with 26 additions and 10 deletions

36
main.c
View File

@ -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
}
}