用于 simplisity studio 中 LED 闪烁问题的 GPIO 命令
GPIO commands for Blinking LED problem in simplisity studio
我有以下命令
GPIO_PinOutClear(LED_PORT_E,15)
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0)
GPIO_PinOutSet(LED_PORT_E,15)
我知道我应该将 ON 值延迟 OFF 值放在一个循环中,以使 LED 不断闪烁。我试图实现它,但它不起作用。
我哪里错了?
#include <stdint.h>
#include <stdbool.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "bsp.h"
#include "bsp_trace.h"
#define LED_PORT_E gpioPortE
#define LED_PIN_E 15
#define LED_PORT_A gpioPortA
#define LED_PIN_A 15
volatile uint32_t msTicks; /* counts 1ms timeTicks */
void Delay(uint32_t dlyTicks);
/***************************************************************************//**
* @brief SysTick_Handler
* Interrupt Service Routine for system tick counter
******************************************************************************/
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}
/***************************************************************************//**
* @brief Delays number of msTick Systicks (typically 1 ms)
* @param dlyTicks Number of ticks to delay
******************************************************************************/
void Delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) ;
}
/***************************************************************************//**
* @brief Main function
******************************************************************************/
int main(void)
{
/* Chip errata */
CHIP_Init();
CMU_ClockEnable(cmuClock_GPIO,true);
/* If first word of user data page is non-zero, enable Energy Profiler trace */
BSP_TraceProfilerSetup();
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
while (1) ;
}
/* Initialize LED driver */
BSP_LedsInit();
BSP_LedSet(0);
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0);
Delay(1000);
GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0);
while (1) {
GPIO_PinOutClear(LED_PORT_E,15);
GPIO_PinOutSet(LED_PORT_E,15);
}
}
在 while 循环中给出延迟。
while (1) {
GPIO_PinOutClear(LED_PORT_E,15);
Delay(1000);
GPIO_PinOutSet(LED_PORT_E,15);
Delay(1000);
}
如果引脚配置正常,则 LEDS 开始闪烁。
我有以下命令
GPIO_PinOutClear(LED_PORT_E,15)
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0)
GPIO_PinOutSet(LED_PORT_E,15)
我知道我应该将 ON 值延迟 OFF 值放在一个循环中,以使 LED 不断闪烁。我试图实现它,但它不起作用。 我哪里错了?
#include <stdint.h>
#include <stdbool.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "bsp.h"
#include "bsp_trace.h"
#define LED_PORT_E gpioPortE
#define LED_PIN_E 15
#define LED_PORT_A gpioPortA
#define LED_PIN_A 15
volatile uint32_t msTicks; /* counts 1ms timeTicks */
void Delay(uint32_t dlyTicks);
/***************************************************************************//**
* @brief SysTick_Handler
* Interrupt Service Routine for system tick counter
******************************************************************************/
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}
/***************************************************************************//**
* @brief Delays number of msTick Systicks (typically 1 ms)
* @param dlyTicks Number of ticks to delay
******************************************************************************/
void Delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) ;
}
/***************************************************************************//**
* @brief Main function
******************************************************************************/
int main(void)
{
/* Chip errata */
CHIP_Init();
CMU_ClockEnable(cmuClock_GPIO,true);
/* If first word of user data page is non-zero, enable Energy Profiler trace */
BSP_TraceProfilerSetup();
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
while (1) ;
}
/* Initialize LED driver */
BSP_LedsInit();
BSP_LedSet(0);
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0);
Delay(1000);
GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0);
while (1) {
GPIO_PinOutClear(LED_PORT_E,15);
GPIO_PinOutSet(LED_PORT_E,15);
}
}
在 while 循环中给出延迟。
while (1) {
GPIO_PinOutClear(LED_PORT_E,15);
Delay(1000);
GPIO_PinOutSet(LED_PORT_E,15);
Delay(1000);
}
如果引脚配置正常,则 LEDS 开始闪烁。