GD32f103介绍第二章

GD32f103介绍第二章

前言

为了偏于后期移植,会对相应的功能进行API封装,留出对外接口函数,方便调用。

1. 定时器

仅展示和介绍作者在项目中测试和使用过的代码:

  1. 普通定时 ,定时0.1s:
/*!
    \brief      configure the TIMER1 peripheral
    \param[in]  none
    \param[out] none
    \retval     none
*/
void ConfigTimer1(void)
{
   
	/* ----------------------------------------------------------------------------
    TIMER1 Configuration: 
    TIMER1CLK = SystemCoreClock/7200 = 10KHz, the period is 1s(1000/10000 = 0.1s).
    ---------------------------------------------------------------------------- */
	timer_parameter_struct timer_initpara;

    rcu_periph_clock_enable(RCU_TIMER1);

    timer_deinit(TIMER1);
    /* initialize TIMER init parameter struct */
    timer_struct_para_init(&timer_initpara);
    /* TIMER1 configuration */
    timer_initpara.prescaler         = 7199;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = 999;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
    timer_init(TIMER1, &timer_initpara);

    timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
    timer_interrupt_enable(TIMER1, TIMER_INT_UP);
    timer_enable(TIMER1);
	
	/* configure the TIMER1 interrupt */
	nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
    nvic_irq_enable(TIMER1_IRQn, 1, 1);
}

中断函数为:

/*!
    \brief      this function handles TIMER1 interrupt request.
    \param[in]  none
    \param[out] none
    \retval     none
*/
void TIMER1_IRQHandler(void)
{
   
    if(SET == timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_UP)){
   
        /* clear channel 0 interrupt bit */
        timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
//		功能实现
    }
}
  1. 读取PWM输入占空比和频率
/*!
    \brief      configure the TIMER3 peripheral
    \param[in]  none
    \param[out] none
    \retval     none
*/
void ConfigTimer3(void)
{
   
 /* TIMER3 configuration: PWM input mode ------------------------
     the external signal is connected to TIMER3 CH0 pin(PB6)
     the rising edge is used as active edge
     the TIMER3 CH0CV is used to compute the frequency value 
     the TIMER3 CH1CV is used
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值