Add comments

This commit is contained in:
Sanyog Nevase Nevase 2024-10-10 20:27:33 +05:30
parent 73455674fa
commit b5e4501940
1 changed files with 44 additions and 53 deletions

19
main.c
View File

@ -55,9 +55,10 @@ char UART1_READ(void)
#define STRELOAD *((volatile uint32_t *) 0xE000E014) // reload value #define STRELOAD *((volatile uint32_t *) 0xE000E014) // reload value
#define STCURRENT *((volatile uint32_t *) 0xE000E018) // current value #define STCURRENT *((volatile uint32_t *) 0xE000E018) // current value
#define CLOCK_HZ 16000000 // CLOCK FREQUENCY OF EK-TM4C123GXL #define CLOCK_HZ 16000000 // CLOCK FREQUENCY
#define SYSTICK_RELOAD_VALUE(us) ((CLOCK_HZ / 1000000) * (us) - 1) // SYSTICK RELOAD VALUE #define SYSTICK_RELOAD_VALUE(us) ((CLOCK_HZ / 1000000) * (us) - 1) // SYSTICK RELOAD VALUE
void systick_setting(void) // SYSTICK SETUP FUNCTION void systick_setting(void) // SYSTICK SETUP FUNCTION
{ {
STRELOAD = SYSTICK_RELOAD_VALUE(1000); // RELOAD VALUE FOR 1ms STRELOAD = SYSTICK_RELOAD_VALUE(1000); // RELOAD VALUE FOR 1ms
@ -66,7 +67,7 @@ void systick_setting(void) // SYSTICK SETUP FUNCTION
} }
void delay(int us) //DEFINING DELAY FUNCTION void delay(int us) // DEFINING DELAY FUNCTION
{ {
STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY
STCURRENT = 0; // Clear STCURRENT STCURRENT = 0; // Clear STCURRENT
@ -81,7 +82,6 @@ void STATUS_LED(char received_data)
{ {
GPIO_PORTF_DATA_R |= 0x08; // Turn on Green LED (PF3) GPIO_PORTF_DATA_R |= 0x08; // Turn on Green LED (PF3)
GPIO_PORTF_DATA_R &= ~0x04; // Turn off Blue LED (PF2) GPIO_PORTF_DATA_R &= ~0x04; // Turn off Blue LED (PF2)
} }
else if (received_data == 0xF0) else if (received_data == 0xF0)
{ {
@ -92,37 +92,28 @@ void STATUS_LED(char received_data)
{ {
GPIO_PORTF_DATA_R |= 0x02; GPIO_PORTF_DATA_R |= 0x02;
} }
//delay(500000);
//GPIO_PORTF_DATA_R &= 0x00; // Turn on Green LED (PF3)
} }
void GPIOF_interruptHandler(void) // Interrupt handler for GPIO Port F void GPIOF_interruptHandler(void) // Interrupt handler for GPIO Port F
{ {
//delay(200000); // Debounce delay
// Check PF4 (Switch 2)
if (GPIO_PORTF_RIS_R & 0x10) // Check if PF4 caused the interrupt if (GPIO_PORTF_RIS_R & 0x10) // Check if PF4 caused the interrupt
{ {
//GPIO_PORTF_DATA_R |= 0x02; // Toggle RED LED (PF1)
//delay(500000);
UART1_WRITE(0xF0); UART1_WRITE(0xF0);
STATUS_LED(UART1_READ()); STATUS_LED(UART1_READ());
//GPIO_PORTF_DATA_R = 0x00; // Toggle RED LED (PF1)
GPIO_PORTF_ICR_R = 0x10; // Clear interrupt flag for PF4 GPIO_PORTF_ICR_R = 0x10; // Clear interrupt flag for PF4
} }
// Check PF0 (Switch 1)
if (GPIO_PORTF_RIS_R & 0x01) // Check if PF0 caused the interrupt if (GPIO_PORTF_RIS_R & 0x01) // Check if PF0 caused the interrupt
{ {
//GPIO_PORTF_DATA_R |= 0x04; // Toggle RED LED (PF1)
//delay(500000);
UART1_WRITE(0xAA); UART1_WRITE(0xAA);
//GPIO_PORTF_DATA_R = 0x00;
STATUS_LED(UART1_READ()); STATUS_LED(UART1_READ());
GPIO_PORTF_ICR_R = 0x01; // Clear interrupt flag for PF0 GPIO_PORTF_ICR_R = 0x01; // Clear interrupt flag for PF0
} }
} }
int main(void) // MAIN FUNCTION int main(void) // MAIN FUNCTION
{ {
GPIO_PORT_F_init(); // GPIO INITIALISATION FUNCTION GPIO_PORT_F_init(); // GPIO INITIALISATION FUNCTION