[Keil51]51单片机定时器的方式0使用注意

当 51单片机工作模式寄存器 设置为

    TMOD.M1M0 = 00  工作方式0 

    TMOD.C/T = 0 定时工作模式

定时器/计数器0 将工作在 13bit 定时器模式。。

与想当然的 13 bit = 5bit(TH0 ) + 8bit (TL0)的搞法不同的是。。(谁让你不看规格)

13bit = 8bit(TH0) + 5bit(TL0)  

TL0的高三位没有用到。。

假设定时器工作频率为2M,那么中断服务程序定长1ms的写法应该是。。

 1 /*
 2  *  @Func: void TIMER0_IRQHandler(void) interrupt 1
 3  *  @Usage: timer0 interrupt sevices routine
 4  *  @parameter: none
 5  *  @retval:  none
 6  *  @version: 2013-03-07 11:37:50
 7  * */
 8 void TIMER0_IRQHandler(void) interrupt 1{
 9     
10     TH0 =(8192 - 2*1000)/32;
11     TL0 =(8192 - 2*1000)%32;
12 
13          // do what you need to do 
14          return;          
15 }
原文地址:https://www.cnblogs.com/alimy/p/2947740.html