GD32F303CBT6
配置句柄
开启时钟函数:void rcu_periph_clock_enable(rcu_periph_enum periph)
int i =0;
void tick_init (uint_fast16_t prescaler,uint_fast16_t period)
{
timer_parameter_struct timer_struct;
rcu_periph_clock_enable(RCU_TIMER2);
timer_struct.period = period;
timer_struct.counterdirection = TIMER_COUNTER_UP;
timer_struct.prescaler = prescaler;
timer_struct.clockdivision = 0;
timer_struct.alignedmode = 0;
timer_init(TIMER2,&timer_struct);
timer_interrupt_enable(TIMER2,TIMER_INT_UP);
nvic_irq_enable(TIMER2_IRQn,2,2);
timer_enable(TIMER2);
}
void TIMER2_IRQHandler (void)
{
if ( timer_interrupt_flag_get(TIMER2,TIMER_INT_FLAG_UP)!=RESET)
{
i++;
timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_UP);
}
}
int main(void)
{
systick_config();
tick_init(5000-1,12000-1);
rcu_periph_clock_enable(RCU_GPIOC);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
while(1)
{
gpio_bit_reset(GPIOC, GPIO_PIN_13);
if(i>=3)
{
gpio_bit_set(GPIOC, GPIO_PIN_13);
delay_1ms(1000);
i = 0;
}
}
}