首页 > 解决方案 > 简单工作室中用于闪烁 LED 问题的 GPIO 命令

问题描述

我有以下命令

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);
  }
}

标签: embeddedgpio

解决方案


Give delay in while loop .

 while (1) {
          GPIO_PinOutClear(LED_PORT_E,15);
          Delay(1000);
          GPIO_PinOutSet(LED_PORT_E,15);
          Delay(1000);
          }

If configuration of pins is ok then LEDS start blinking.


推荐阅读