/*********************************TIM0时钟配置初始化************************************/
void Timer0_init(void)
{
TCON1 = 0x00; //Tx0定时器时钟为Fosc
TMOD = 0x00; //16位重装载定时器/计数器
//Tim0计算时间 = (65536 - 0xFACB) * (1 / (Fosc /Timer分频系数)) = 1333 / (16000000 / 12) = 1 ms
//定时1ms 反推初值 = 65536 - ((1/1000) / (1/(Fosc / Timer分频系数)))
// = 65536 - ((1/1000) / (1/(16000000 / 12))) = 65536 - 1333 = 0xFACB
TH0 = 0xFA;
TL0 = 0xCB; //T0定时时间1ms
IE |= 0x02; //打开T0中断
TCON |= 0x10; //使能T0
EA = 1; //打开总中断
}
|