[开发板与模块] 【HT32F52352 Starter Kit测评】 GPIO驱动LED灯

[复制链接]
1866|13
 楼主| tlled 发表于 2022-4-26 09:42 | 显示全部楼层 |阅读模式
本帖最后由 eltonchang2001 于 2022-11-9 11:36 编辑

    看了开发板资料后,开始学习,开发环境使用MDK,直接安装库包里面的pack文件,就可以直接打开工程文件了。
    一、硬件

    要测试的开发板电路图,LED部分电路。使用端口PC14。
    001.png

    二、软件

    2.1、led.c

  1. #include "ht32.h"
  2. #include "ht32_board.h"

  3. void __Delay(u32 count)
  4. {
  5.   while (count--)
  6.   {
  7.     __NOP(); // Prevent delay loop be optimized
  8.   }
  9. }


  10. void init_led(void)
  11. {
  12.         CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
  13.         CKCUClock.Bit.AFIO = 1;
  14.         CKCUClock.Bit.PC = 1;
  15.         CKCU_PeripClockConfig(CKCUClock, ENABLE);
  16.         
  17.         AFIO_GPxConfig(GPIO_PC, AFIO_PIN_1, AFIO_FUN_GPIO);
  18.         GPIO_DirectionConfig(HT_GPIOC, GPIO_PIN_14, GPIO_DIR_OUT);
  19.         GPIO_PullResistorConfig(HT_GPIOC, GPIO_PIN_14, GPIO_PR_UP);
  20.         GPIO_WriteOutBits(HT_GPIOC, GPIO_PIN_14, RESET);
  21. }


  22. void GPIO_OutputBit(void)
  23. {
  24.   GPIO_SetOutBits(HT_GPIOC, GPIO_PIN_14); // GPIO = HIGH
  25.   __Delay(5000000);

  26.   GPIO_ClearOutBits(HT_GPIOC, GPIO_PIN_14); // GPIO = LOW
  27.   __Delay(5000000);
  28. }

       2.2、main.c
  1. #include "ht32.h"
  2. #include "ht32_board.h"
  3. #include "led.h"

  4. void NVIC_Configuration(void);
  5. void CKCU_Configuration(void);
  6. void GPIO_Configuration(void);
  7. #if (ENABLE_CKOUT == 1)
  8. void CKOUTConfig(void);
  9. #endif

  10. int main(void)
  11. {
  12.   s32 input;

  13.   NVIC_Configuration();               /* NVIC configuration                                                 */
  14.   CKCU_Configuration();               /* System Related configuration                                       */
  15.   GPIO_Configuration();               /* GPIO Related configuration                                         */
  16.   RETARGET_Configuration();           /* Retarget Related configuration                                     */
  17.         
  18.         init_led();

  19.         while(1)
  20.         {
  21.                 GPIO_OutputBit();
  22.         }
  23. }
  
    2.3、程序中有关端口选择的寄存器,这个之前使用其他的芯片有点区别。

    端口默认端口是AF0复用功能,有些端口使用GPIO功能要复用的AF1。
    002.png

    时钟使能配置位
    003.png
    004.png

    三、程序运行

    100.gif
antusheng 发表于 2022-6-26 14:49 | 显示全部楼层
非常好上手的样子。
caigang13 发表于 2022-7-1 19:20 来自手机 | 显示全部楼层
学习了,谢谢楼主分享。
天意无罪 发表于 2022-7-3 09:29 | 显示全部楼层
哈哈哈,学习单片机的第一步貌似都逃不了点灯试验啊,或者是Printf Hello World。
chenjun89 发表于 2022-7-3 09:39 来自手机 | 显示全部楼层
好歹做个高级点的点灯吧,比如呼吸灯。
quickman 发表于 2022-7-4 15:27 | 显示全部楼层
入门的首选,就是点灯  
sdCAD 发表于 2022-7-4 16:41 | 显示全部楼层
pack文件在哪里下载的   
sesefadou 发表于 2022-7-5 16:03 | 显示全部楼层
开发板资料在哪里下载的   
cemaj 发表于 2022-7-5 17:09 | 显示全部楼层
资料不错。   
i1mcu 发表于 2022-7-5 17:49 | 显示全部楼层
性能怎么样   
cehuafan 发表于 2022-7-5 18:31 | 显示全部楼层
keil自带这个pack吗  
adolphcocker 发表于 2022-7-5 19:22 | 显示全部楼层
官网提供个代码吗  
chenqianqian 发表于 2022-7-6 07:58 来自手机 | 显示全部楼层
搞个呼吸灯
妇女半边天 发表于 2022-7-7 09:58 | 显示全部楼层
哈哈,看到了很多点灯啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

132

主题

701

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部