#include #include #include "tm4c123gh6pm.h" void GPIO_PORT_F_init(void) { SYSCTL_RCGC2_R |= 0x00000020; // ENABLE CLOCK TO GPIOF GPIO_PORTF_LOCK_R = 0x4C4F434B; // UNLOCK COMMIT REGISTER GPIO_PORTF_CR_R = 0x1F; // MAKE PORTF0 CONFIGURABLE GPIO_PORTF_DEN_R = 0x1F; // SET PORTF DIGITAL ENABLE GPIO_PORTF_DIR_R = 0x0E; // SET PF0, PF4 as input and PF1, PF2 and PF3 as output 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 } void UART1_WRITE(char data) { while (UART1_FR_R & 0x20); // Wait until TX FIFO is not full UART1_DR_R = data; // Write data to UART data register } char UART1_READ(void) { while (UART1_FR_R & 0x10); // Wait until RX FIFO is not empty return (char)UART1_DR_R; // Return received data } 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 { //GPIO_PORTF_DATA_R |= 0x02; // Toggle RED LED (PF1) //delay(500000); UART1_WRITE(0xF0); STATUS_LED(UART1_READ()); //GPIO_PORTF_DATA_R = 0x00; // Toggle RED LED (PF1) 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 { //GPIO_PORTF_DATA_R |= 0x04; // Toggle RED LED (PF1) //delay(500000); UART1_WRITE(0xAA); //GPIO_PORTF_DATA_R = 0x00; STATUS_LED(UART1_READ()); GPIO_PORTF_ICR_R = 0x01; // Clear interrupt flag for PF0 } } int main(void) // MAIN FUNCTION { GPIO_PORT_F_init(); // GPIO INITIALISATION FUNCTION while (1) { } }