#include #include #include "tm4c123gh6pm.h" void UART7_init(void); void UART7_write(char data); char UART7_read(void); void PortE_init(void); void LED_Control(char); int main(void) { char recievedchar; UART7_init(); // UART 7 Initialization PortE_Init(); // PORT E Initialization while(1) { recievedchar = UART7_read(); // Read a character from the UART UART0_Write(receivedChar); // Give the character back to UART LED_Control(receivedChar); // LED Control based on UART input } } void UART7_init(void) { SYSCTL_RCGCUART_R |= 0x80; // Enable clock to UART7 SYSCTL_RCGCGPIO_R |= 0x10 // Enable clock to Port E for UART7 // UART7 TX/RX on PE1/PE0 GPIO_PORTE_AFSEL_R |= 0x03; // Enable alt function on PE0, PE1 GPIO_PORTE_DEN_R |= 0x03; // Enable digital on PE0, PE1 GPIO_PORTE_PCTL_R |= 0x11; // Configure PE0 and PE1 for UART GPIO_PORTE_AMSEL_R &= ~0x03; // Disable analog on PE0, PE1 // UART7 initialization UART0_CTL_R &= ~0x01; // Disable UART0 UART0_IBRD_R = 104; // Baud rate = 9600, Integer Baud Rate Divisor UART0_FBRD_R = 11; // Fractional Baud Rate Divisor UART0_LCRH_R = 0x70; // 8-bit, no parity, 1-stop bit, enable FIFOs UART0_CTL_R |= 0x301; // Enable UART0, TX, RX } char UART0_Read(void) { while((UART0_FR_R & 0x10) != 0); // Wait until RXFE is 0 (receive FIFO not empty) return UART0_DR_R & 0xFF; // Read the received character } void UART0_Write(char data) { while((UART0_FR_R & 0x20) != 0); // Wait until TXFF is 0 (transmit FIFO not full) UART0_DR_R = data; // Transmit the data } void PortF_Init(void) { SYSCTL_RCGCGPIO_R |= 0x20; // Enable clock to Port F GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock Port F for commit GPIO_PORTF_CR_R |= 0x0E; // Allow changes to PF1, PF2, PF3 (RGB LEDs) GPIO_PORTF_DIR_R |= 0x0E; // Set PF1, PF2, PF3 as outputs GPIO_PORTF_DEN_R |= 0x0E; // Enable digital on PF1, PF2, PF3 } void LED_Control(char receivedChar) { switch(receivedChar) { case 'R': GPIO_PORTF_DATA_R = 0x02; // Turn on RED LED (PF1) break; case 'B': GPIO_PORTF_DATA_R = 0x04; // Turn on BLUE LED (PF2) break; case 'G': GPIO_PORTF_DATA_R = 0x08; // Turn on GREEN LED (PF3) break; default: GPIO_PORTF_DATA_R = 0x00; // Turn off all LEDs break; } }