PUYA LED — LED

PUYA PY32F0xx_Firmware V1.5.0 LED LED 示例教学

LED — LED

固件库: PY32F0xx_Firmware V1.5.0
芯片: PUYA
源文件: PUYA/PY32F0xx_Firmware_V1.5.0/Projects/PY32F030-STK/Example/LED/LED/Src/main.c


功能简介

本示例演示 LED 的基本用法。

完整代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "main.h"

int main(void)
{
  /* Reset of all peripherals, Initializes the Systick */
  HAL_Init();

  /* LED initialization */
  hled.Instance = LED;
  hled.Init.ComNum = 4 - 1;                                 /* Enable 4 COM ports */
  hled.Init.ComDrive  = LED_COMDRIVE_HIGH;                  /* LED COM output */
  hled.Init.Prescaler = 10 - 1;                             /* Fpclk/(PR+1) */
  hled.Init.LightTime = 240;                                /* Time each LED is illuminated (240*fLED, where fLED is the LED module counting clock frequency)  */
  hled.Init.DeadTime = 10;                                  /* Interval time between two LED switches, must not be zero */
  HAL_LED_Init(&hled);

  while (1)
  {
    HAL_LED_SetComDisplay(&hled, LED_COM0, LED_DISP_8);       /* Display number 8 */
    HAL_Delay(200);

    HAL_LED_SetComDisplay(&hled, LED_COM1, LED_DISP_8);       /* Display number 8 */
    HAL_Delay(200);

    HAL_LED_SetComDisplay(&hled, LED_COM2, LED_DISP_8);       /* Display number 8 */
    HAL_Delay(200);

    HAL_LED_SetComDisplay(&hled, LED_COM3, LED_DISP_8);       /* Display number 8 */
    HAL_Delay(200);

    HAL_LED_SetComDisplay(&hled, LED_COM_ALL, LED_DISP_NONE); /* Turn off display */
    HAL_Delay(200);
  }
}

代码讲解

板级初始化:初始化开发板上的 LED、按键等基础外设。

最后更新于 Sep 08, 2026 16:03 +0800
世界是你们
使用 Hugo 构建
主题 StackJimmy 设计