add comments
This commit is contained in:
parent
896914490e
commit
7169a51106
24
main.c
24
main.c
|
@ -1,3 +1,9 @@
|
|||
/*
|
||||
Problem Statement:
|
||||
Write a program where the press of a switch is detected by a GPIO interrupt. On each button press the interrupt handler should toggle the state of RED LED.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "tm4c123gh6pm.h"
|
||||
|
@ -18,10 +24,10 @@ void GPIO_PORT_F_init(void)
|
|||
GPIO_PORTF_PUR_R = 0x11; // PORTF PF0 and PF4 IS PULLED UP
|
||||
|
||||
NVIC_EN0_R |= 1 << 30;
|
||||
GPIO_PORTF_IS_R = 0x00; // Make it edge-sensitive
|
||||
GPIO_PORTF_IBE_R = 0x00; // Trigger on one edge
|
||||
GPIO_PORTF_IEV_R = 0x00; // Falling edge event
|
||||
GPIO_PORTF_IM_R |= 0x11; // Unmask interrupts for PF0 and PF4
|
||||
GPIO_PORTF_IS_R = 0x00; // INTERRUPT SENSE EDGE SENSITIVE
|
||||
GPIO_PORTF_IBE_R = 0x00; // INTERRUPT GENERATION IS CONTROLLED BY THE GPIO INTERRUPT EVENT
|
||||
GPIO_PORTF_IEV_R = 0x00; // INTERRUPT EVENT FALLING EDGE
|
||||
GPIO_PORTF_IM_R |= 0x11; // INTERRUPT MASK ENABLE FOR SWITCH1 AND SWITCH2
|
||||
}
|
||||
void systick_setting(void) // SYSTICK SETUP FUNCTION
|
||||
{
|
||||
|
@ -30,7 +36,7 @@ void systick_setting(void) // SYSTICK SETUP FUNCTION
|
|||
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
|
||||
|
@ -44,14 +50,14 @@ void GPIOF_interruptHandler(void) // Interrupt handler for GPIO Port
|
|||
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
|
||||
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
|
||||
GPIO_PORTF_DATA_R ^= 0x02; // TOGGLE RED LED
|
||||
GPIO_PORTF_ICR_R = 0x01; // CLEAR INTERRUPT FLAG FOR SWITCH 1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue