Lab8/main.c

64 lines
1.4 KiB
C
Raw Normal View History

#include <stdint.h>
#include <stdbool.h>
#include "tm4c123gh6pm.h"
2024-10-29 00:51:12 +05:30
void UART7_init(void);
void UART7_write(char data);
char UART7_read(void);
void PortE_init(void);
void LED_Control(char);
2024-10-28 16:55:07 +05:30
int main(void)
{
2024-10-28 17:23:07 +05:30
char recievedchar;
2024-10-29 00:51:12 +05:30
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
}
2024-10-28 16:55:07 +05:30
}
2024-10-29 00:51:12 +05:30
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
}