官方固件库用户指南 对固件库函数和结构体有解释
led.c
#include "led.h"
#include "gd32vf103.h"
#include "gd32vf103_libopt.h"
// ************************************************************************************************************** //
//LED灯初始化
void LED_Init()
{
rcu_periph_clock_enable(LED0_CLK); //开启GPIOA时钟
gpio_init(LED0_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED0_PIN); //配置 PA7 为输出,,50MHz
gpio_bit_reset(LED0_PORT, LED0_PIN); //默认为低
}
led.h
#ifndef __LED_H__
#define __LED_H__
#include "gd32vf103.h"
#include "systick.h"
// ************************************************************************************************************** //
#define LED0_CLK RCU_GPIOA
#define LED0_PORT GPIOA
#define LED0_PIN GPIO_PIN_7
#define LED0_L gpio_bit_reset(LED0_PORT, LED0_PIN)
#define LED0_H gpio_bit_set(LED0_PORT, LED0_PIN)
#define LED0_T if(gpio_input_bit_get(LED0_PORT,LED0_PIN) == 1)\
gpio_bit_reset(LED0_PORT, LED0_PIN);\
else\
gpio_bit_set(LED0_PORT, LED0_PIN);
// ************************************************************************************************************** //
void LED_Init(void);
#endif
main.c
#include "gd32vf103.h"
#include "gd32vf103c_start.h"
#include "systick.h"
#include "led.h"
// ************************************************************************************************************* //
//主函数
int main(void)
{
LED_Init(); //LED灯初始化
while(1)
{
LED0_T;
delay_1ms(100);
}
}
个人见解,感谢阅读。