繁体   English   中英

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

[英]How to make timer0 use a prescaler of 1:64 in 16 bit mode?

我确实对定时器没有很好的了解,但是我试图更改timer0以使其在16位模式下使用1:64的预分频器吗? 我从Microchip那里获得了定时器代码,它使用的是8位模式,没有预分频器。 下载文件

这是我怀疑必须处理预分频器的部分代码。

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

这是来自PIC18F87J11数据手册中有关预分频器的一些信息

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位模式? 就像我说的我是初学者一样,所以请以我的理解水平进行解释。

提前感谢!

从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 <2:0>设置为选择预分频比。
  5. 将TMR0ON设置为1,使能定时器0。

等于:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM