1.资料的获取
官网获取GD32F310K-START板的资料,如图1-1
2.解压压缩文件,该文件的路径如图2-1
3.用KEIL5打开工程的路径
,然后GD32F310K_START.uvproj修改成GD32F310K_START.uvprojx,编译是没有问题,烧录方式是通过DAP烧录,把mini AB的USB线接好,就可以烧录!
如下是外部的初始化,如下:
void exti_config(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_CFGCMP);
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_4);
nvic_irq_enable(EXTI4_15_IRQn, 1U, 0U);
syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN4);
exti_init(EXTI_4, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
exti_interrupt_flag_clear(EXTI_4);
}
紧接着是定时器2的初始化:
void timer_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
timer_initpara.prescaler = 719;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 49999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2,&timer_initpara);
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 24999);
timer_channel_output_mode_config(TIMER2, TIMER_CH_0, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
timer_auto_reload_shadow_enable(TIMER2);
timer_enable(TIMER2);
}
gdio的初始化如下:
void gpio_config(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_6);
}
main函数部分:
int main(void)
{
gd_eval_key_init(KEY_WAKEUP, KEY_MODE_EXTI);
led_config();
systick_config();
led_flash(1);
exti_config();
gpio_config();
timer_config();
while(1){
}
}
按下KEY_WAKEUP按键,就会触发相应的中断和定时器。
审核编辑:住在12楼的小哥