Question
Microprocessor: using Tiva C Series TM4C123G board and Kiel uVision5 IDE the project is: when I press lightly on SW1(PF4), RED LED(PF1) should toggle and
Microprocessor: using Tiva C Series TM4C123G board and Kiel uVision5 IDE
the project is: when I press lightly on SW1(PF4), RED LED(PF1) should toggle and when I press lightly on SW2(PF0), GREEN LED(PF3) should toggle and when I press both switches together, no LED should turn on and when I release both switches, it should remember the last state and toggle that colored LED.
The code I wrote below works when I press switches harder. It won't change colors if I press softly.
#include
#define RED_MASK 0x02 #define GREEN_MASK 0x08 //***************************************************************************** void PortFunctionInit(void) { // // Enable Peripheral Clocks // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
// // Enable pin PF4 for GPIOInput // GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
// // Enable pin PF1 for GPIOOutput // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
// // Enable pin PF3 for GPIOOutput // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
// // Enable pin PF0 for GPIOInput // GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); // //First open the lock and select the bits we want to modify in the GPIO commit register. // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;
// //Now modify the configuration of the pins that we unlocked. // GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIO_PORTF_PUR_R |= 0x11; }
int main(void) { PortFunctionInit(); //SysCtlDelay(2666666); while(1) { // SysCtlDelay(2666666);
if((GPIO_PORTF_DATA_R&0x01)==0x00 && ((GPIO_PORTF_DATA_R&0x10)==0x00)){ GPIO_PORTF_DATA_R &= ~0xA; } else if((GPIO_PORTF_DATA_R&0x10) == 0x00){ GPIO_PORTF_DATA_R &= ~0xA; // SysCtlDelay(2666666);
while((GPIO_PORTF_DATA_R&0x01) != 0x00){ SysCtlDelay(2666666); GPIO_PORTF_DATA_R ^= RED_MASK;
} } else if((GPIO_PORTF_DATA_R&0x01) == 0x00){ GPIO_PORTF_DATA_R &= ~0xA; // SysCtlDelay(2666666);
while((GPIO_PORTF_DATA_R&0x10) != 0x00){ SysCtlDelay(2666666); GPIO_PORTF_DATA_R ^= GREEN_MASK;
} } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started