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 #include #include "lab5.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_gpio.h" #include "driverlib/sysctl.h" #include "driverlib/pin_map.h" #include "driverlib/rom_map.h" #include "driverlib/gpio.h" #include "inc/tm4c123gh6pm.h"

#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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!