embedded - 简单工作室中用于闪烁 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);
}
}
解决方案
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.
推荐阅读
- javascript - Vue.js:如何更改 Vue2-slider 组件的颜色
- python - Tensorflow 未在 RTX 3060 Ti 上检测到 GPU
- python - 是否可以将另一级键迭代地添加到字典中以生成嵌套字典?
- android - 在片段中实现 setOnClickListener 时出现空指针异常
- python - Python Dictionary - 如何找到具有最少唯一值的所有键?
- excel - 使用 .Net 核心将数据表导出到 Excel
- r - 当 HTML 文件已存在时,Rmd 输出格式未在 blogdown 中正确编译
- javascript - 按 id 或 Date JavaScript 排序 JSON
- microsoft-graph-api - 备用更新日历事件未显示 Microsoft 团队链接
- javascript - JS:函数运行太快但不想使用 setTimeout 的快速补丁