使用TIMER的寄存器配置
void Timer_Init(Timer_Base_TypeDef timer_base)
{
U8 timerx = timer_base.timerx;
if (timer_base.timerx == TIMER0 || timer_base.timerx == TIMER1)
{
TCFG0 &= ~0xff;
TCFG0 |= timer_base.prescaler;
}
else if (timer_base.timerx == TIMER2 \
|| timer_base.timerx == TIMER3 \
|| timer_base.timerx == TIMER4 )
{
TCFG0 &= ~0xff00;
TCFG0 |= (timer_base.prescaler << 8);
}
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