本帖最后由 eltonchang2001 于 2022-11-9 11:36 编辑
看了开发板资料后,开始学习,开发环境使用MDK,直接安装库包里面的pack文件,就可以直接打开工程文件了。
一、硬件
要测试的开发板电路图,LED部分电路。使用端口PC14。
二、软件
2.1、led.c
- #include "ht32.h"
- #include "ht32_board.h"
- void __Delay(u32 count)
- {
- while (count--)
- {
- __NOP(); // Prevent delay loop be optimized
- }
- }
- void init_led(void)
- {
- CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
- CKCUClock.Bit.AFIO = 1;
- CKCUClock.Bit.PC = 1;
- CKCU_PeripClockConfig(CKCUClock, ENABLE);
-
- AFIO_GPxConfig(GPIO_PC, AFIO_PIN_1, AFIO_FUN_GPIO);
- GPIO_DirectionConfig(HT_GPIOC, GPIO_PIN_14, GPIO_DIR_OUT);
- GPIO_PullResistorConfig(HT_GPIOC, GPIO_PIN_14, GPIO_PR_UP);
- GPIO_WriteOutBits(HT_GPIOC, GPIO_PIN_14, RESET);
- }
- void GPIO_OutputBit(void)
- {
- GPIO_SetOutBits(HT_GPIOC, GPIO_PIN_14); // GPIO = HIGH
- __Delay(5000000);
- GPIO_ClearOutBits(HT_GPIOC, GPIO_PIN_14); // GPIO = LOW
- __Delay(5000000);
- }
2.2、main.c- #include "ht32.h"
- #include "ht32_board.h"
- #include "led.h"
- void NVIC_Configuration(void);
- void CKCU_Configuration(void);
- void GPIO_Configuration(void);
- #if (ENABLE_CKOUT == 1)
- void CKOUTConfig(void);
- #endif
- int main(void)
- {
- s32 input;
- NVIC_Configuration(); /* NVIC configuration */
- CKCU_Configuration(); /* System Related configuration */
- GPIO_Configuration(); /* GPIO Related configuration */
- RETARGET_Configuration(); /* Retarget Related configuration */
-
- init_led();
- while(1)
- {
- GPIO_OutputBit();
- }
- }
2.3、程序中有关端口选择的寄存器,这个之前使用其他的芯片有点区别。
端口默认端口是AF0复用功能,有些端口使用GPIO功能要复用的AF1。
时钟使能配置位
三、程序运行
|