OKI单片机——ML610Q4XX 定时器
1.8位定时器
void Time0_8Bit_Init(Clock_Timer_TypeDef TClock,uint8 TData)
{
DTM0 = 1;//初始化寄存器
DTM0 = 0; //Enable operating Timer 0 (initial value)
TM0D = TData-1; //赋值要减一
//TM0C为计数器;
TM0CON0 = TClock;
ETM0 = 1;//ETM0 is the enable flag for the timer 0 interrupt (TM0INT).
T0RUN = 1;//定时器启动
}
2.16位定时器
16位定时器是由两个8位定时器组成的,Timer0和Timer1为一组,Timer2和Timer3为一组。
如例程中用定时器0和1作为16位定时器时,则只能用定时器1的中断。
void Time0_16Bit_Init(Clock_Timer_TypeDef TClock,uint16 TData)
{
DTM0 = 1;//初始化寄存器
DTM0 = 0;//Enable operating Timer 0 (initial value)
DTM1 = 1;//初始化寄存器
DTM1 = 0;//Enable operating Timer 1 (initial value)
//TM0C为计数器;
//TM1C为计数器;
TM0D = (TData-1); //数据寄存器
TM1D = (TData-1)>>8;//
TM0CON0 = TClock;
T01M16 = 1;//16-bit timer mode
ETM1 = 1;//ETM1 is the enable flag for the timer 1 interrupt (TM1INT).
T1RUN = 0;//In 16-bit timer mode, be sure to set this bit to “0”.
T0RUN = 1;//定时器启动
}