合泰HT32F52352初次使用之LED闪烁
最近合泰芯片刚来,照常还是先做点灯操作,刚开始是使用的自带的例程里面的过程点了灯,发现里面的东西太多了对于初次接触并不友好,虽然和stm32的差异不大,但我还是比较喜欢基于模板化的编程,从易到难,从简单的点灯到复杂的大项目。
所以就简化出了和stm32相类似的库文件模板的开发方式
工程链接需要自取
链接:https://pan.baidu.com/s/19MA49Zb3s3W21SYDHMkwmg
提取码:9adx
–来自百度网盘超级会员V4的分享
实验效果
HT32点灯
led.h
#ifndef _LED_H_
#define _LED_H_
#include "ht32f5xxxx_ckcu.h"
#include "ht32f5xxxx_gpio.h"
//端口号定义
#define HT_GPIO_PORT HT_GPIOC
//LED引脚定义
#define HT_GPIO_PIN (GPIO_PIN_14|GPIO_PIN_15)
//LED1 LED2 宏定义开和关
#define LED1_ON() GPIO_WriteOutBits(HT_GPIO_PORT,GPIO_PIN_14,RESET)
#define LED1_OFF() GPIO_WriteOutBits(HT_GPIO_PORT,GPIO_PIN_14,SET)
#define LED2_ON() GPIO_WriteOutBits(HT_GPIO_PORT,GPIO_PIN_15,RESET)
#define LED2_OFF() GPIO_WriteOutBits(HT_GPIO_PORT,GPIO_PIN_15,SET)
void Led_Init(void);
#endif
led.c
#include "led.h"
void Led_Init(void)
{
CKCU_PeripClockConfig_TypeDef LEDCLOCK ={{0}};
LEDCLOCK.Bit.PC = 1; //使用PC
//CKCU_PeripClockConfig(CKCU_PeripClockConfig_TypeDef Clock, ControlStatus Cmd);
CKCU_PeripClockConfig(LEDCLOCK,ENABLE); //使能时钟
//GPIO_DirectionConfig(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, GPIO_DIR_Enum GPIO_DIR_INorOUT);
GPIO_DirectionConfig(HT_GPIO_PORT,HT_GPIO_PIN,GPIO_DIR_OUT); //配置GPIO PC15为输出模式
//GPIO_WriteOutBits(HT_GPIO_TypeDef* HT_GPIOx, u16 GPIO_PIN_nBITMAP, FlagStatus Status);
GPIO_WriteOutBits(HT_GPIO_PORT,HT_GPIO_PIN,SET); //将LED1 LED2 熄灭
}
main.c
#include "ht32.h"
#include "ht32_board.h"
#include "led.h"
#include "delay.h"
/**********************TH32 点灯**********************
Author:小殷
Date:2022-4-17
******************************************************/
int main()
{
Led_Init();
while(1)
{
// GPIO_WriteOutBits(HT_GPIOC,GPIO_PIN_14,RESET);
// delay_ms(500);
// GPIO_WriteOutBits(HT_GPIOC,GPIO_PIN_14,SET);
// delay_ms(500);
LED1_ON();
LED2_ON();
delay_ms(500);
LED1_OFF();
LED2_OFF();
delay_ms(500);
}
}