Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago