From 5b4d235ad86c682b74969279570c0af3dfdf802d Mon Sep 17 00:00:00 2001 From: Vikram Rajput Date: Tue, 29 Oct 2024 00:59:51 +0530 Subject: [PATCH] Initialized PORT E and also added code for LED control --- main.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 89f3f7a..c3977b0 100644 --- a/main.c +++ b/main.c @@ -67,9 +67,36 @@ void UART0_Write(char 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; + } + }