Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TM 4 C 1 2 9 4 After clicking the button, why does the led stay on continuously, or I may not notice it because

TM4C1294 After clicking the button, why does the led stay on continuously, or I may not notice it because it flashes too fast, I need to fix this, for example, if I reduce the time the led flashes to 2 seconds (ie 2 seconds on -2 seconds off) this will be much better
#include #include
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "drivers/buttons.h"
#include
#include "driverlib/timer.h"
#define LED_PIN GPIO_PIN_1// Define LED pin mask
#define LED_PIN2 GPIO_PIN_2
uint32_t g_ui32SysClock;
bool g_ledBlinking = false; // Global variable to track LED blinking state
volatile uint32_t g_ui32Mode;
#ifdef DEBUG
void __error(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void LedBlinkingTask(){
if (g_ledBlinking){
UARTprintf("LED OFF
");
GPIO_PORTN_DATA_R &= ~LED_PIN;
g_ledBlinking = false;
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
} else {
UARTprintf("LED ON
");
GPIO_PORTN_DATA_R |= LED_PIN;
g_ledBlinking = true;
}
}
void TimerBegin(){
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerIntRegister(TIMER0_BASE, TIMER_A, LedBlinkingTask);
TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock *4);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerEnable(TIMER0_BASE, TIMER_A);
}
void SysTickIntHandler(void){
uint8_t ui8Buttons;
uint8_t ui8ButtonsChanged;
//
// Grab the current, debounced state of the buttons.
//
ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0);
// Toggle the pin mode.
// g_ui32Mode ^=1;
if(BUTTON_PRESSED(USR_SW1, ui8Buttons, ui8ButtonsChanged))
{
g_ledBlinking = true;
TimerBegin();
}
else { g_ledBlinking = false;}
}
void ConfigureUART(void){
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0| GPIO_PIN_1);
UARTStdioConfig(0,115200, g_ui32SysClock);
}
int main(void){
MAP_SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480,120000000);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0| GPIO_PIN_1);
MAP_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0| GPIO_PIN_1);
MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0| GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
MAP_GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// g_ui32SysClock = SysCtlClockGet();
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480),120000000);
MAP_SysTickPeriodSet(g_ui32SysClock /1000);
MAP_SysTickEnable();
MAP_SysTickIntEnable();
ConfigureUART();
// TimerBegin();
GPIO_PORTN_DATA_R &= ~LED_PIN; // Birinci LED'i sndr
while (1){
SysCtlDelay(100000);
}
}

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Continuation. Show that always p seDk.

Answered: 1 week ago