ARM-TIMER使用

使用TIMER的寄存器配置

void Timer_Init(Timer_Base_TypeDef timer_base)
{
    U8 timerx = timer_base.timerx;
    //Timer input clock Frequency = PCLK / {prescaler value+1} / {divider value}
    //{prescaler value} = 0~255
    //{divider value} = 2, 4, 8, 16

    /*根据选择的timer0~4进行不同bit位的预分频设置*/
    if (timer_base.timerx == TIMER0 || timer_base.timerx == TIMER1)
    {
  
  //TCFG0-bit[7,0]for Timer 0 and 1.
        TCFG0 &= ~0xff;
        TCFG0 |= timer_base.prescaler;
    }
    else if (timer_base.timerx == TIMER2 \
             || timer_base.timerx == TIMER3 \
             || timer_base.timerx == TIMER4 )
    {
  
  //TCFG0-bit[15,8]for Timer 2 and 3 and 4.
        TCFG0 &= ~0xff00;
        TCFG0 |= (timer_base.prescaler << 8);
    }

    /*配置分频系数*/
    //timer_base.timerx在这里用于控制多少位
    TCFG1 &= ~(0xf << (timer_base.timerx * 4));
    TCFG1 |= (timer_base.mux << (timer_base.timerx * 4));

    /*定时器的初值配置*/
    switch(timerx)
    {
        case TIMER0:
            TCNTB0 = timer_base.timer_count ;
            break;
        case TIMER1:
            TCNTB1 = timer_base.timer_count ;
            break;
        case TIMER2:
            TCNTB2 = timer_base.timer_count ;
            break;
        case TIMER3:
            TCNTB3 = timer_base.timer_count ;
            brea
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值