如何使timer0在16位模式下使用1:64的预分频器?

时间:2013-07-11 17:51:47

标签: c timer microcontroller pic microchip

我真的对定时器没有很好的理解,但是我试图更改timer0以使其在16位模式下使用1:64的预分频器?我从Microchip获得了Timer代码,它使用的是8位模式,没有预分频器。 Download Files

这是我怀疑必须处理Prescalers的代码的一部分。

TMR_CON = 0b00000000 | CLOCK_DIVIDER_SETTING;
TMR_IP = 1;
TMR_IF = 0;
TMR_IE = 1;
TMR_ON = 1;

这是PIC18F87J11 DATASHEET关于Prescalers

的一些信息
T0PS2:T0PS0: Timer0 Prescaler Select bits   
111 = 1:256 Prescale value
110 = 1:128 Prescale value
101 = 1:64   Prescale value
100 = 1:32   Prescale value
011 = 1:16   Prescale value
010 = 1:8     Prescale value
001 = 1:4     Prescale value
000 = 1:2     Prescale value

我假设使用1:64预分频器,代码必须更改为以下内容,这是正确的吗?

TMR_CON = 0b00000101 | CLOCK_DIVIDER_SETTING;
TMR_IP = 1;
TMR_IF = 0;
TMR_IE = 1;
TMR_ON = 1;

现在,请告诉我如何将其从8位模式更改为16位模式?就像我说我是初学者一样,所以请按照我的理解水平解释一下。

我提前感谢!

1 个答案:

答案 0 :(得分:0)

来自Microchip数据表:

T0CON: TIMER0 CONTROL REGISTER   

bit 7 TMR0ON: Timer0 On/Off Control bit
  1 = Enables Timer0
  0 = Stops Timer0
bit 6 T08BIT: Timer0 8-Bit/16-Bit Control bit
  1 = Timer0 is configured as an 8-bit timer/counter
  0 = Timer0 is configured as a 16-bit timer/counter
bit 5 T0CS: Timer0 Clock Source Select bit
  1 = Transition on T0CKI pin input edge
  0 = Internal clock (FOSC/4)
bit 4 T0SE: Timer0 Source Edge Select bit
  1 = Increments on high-to-low transition on T0CKI pin
  0 = Increments on low-to-high transition on T0CKI pin
bit 3 PSA: Timer0 Prescaler Assignment bit
  1 = TImer0 prescaler is not assigned; Timer0 clock input bypasses prescaler
  0 = Timer0 prescaler is assigned; Timer0 clock input comes from prescaler output
bit 2-0 T0PS<2:0>: Timer0 Prescaler Select bits
  111 = 1:256 Prescale value
  110 = 1:128 Prescale value
  101 = 1:64 Prescale value
  100 = 1:32 Prescale value
  011 = 1:16 Prescale value
  010 = 1:8 Prescale value
  001 = 1:4 Prescale value
  000 = 1:2 Prescale value
  1. 清除T08BIT位以选择16位模式。
  2. 如果您不将内部时钟(FOSC / 4)作为Timer0 /预分频器输入,则清零T0CS位。
  3. 清除PSA位以选择预分频器。
  4. 设置T0PS&lt; 2:0&gt;选择预分频率。
  5. 将TMR0ON设置为1 ro enable timer0。
  6. 这是平等的:

    T0CON =b'10000nnn' //where nnn is Prescaler value
    

    如果需要中断Timer0溢出,还要使能Timer0中断位(GIE / GIEH,PEIE / GIEL,TMR0IE,TMR0IF)。