我真的不太了解计时器,但我正在尝试更改计时器0,使其在16位模式下使用1:64的预分频器?我从微芯片上得到定时器代码,它使用8位模式,没有预分频器。Download Files
这是代码的一部分,我怀疑必须处理预分频器。
TMR_CON = 0b00000000 | CLOCK_DIVIDER_SETTING;
TMR_IP = 1;
TMR_IF = 0;
TMR_IE = 1;
TMR_ON = 1;
这是PIC18F87J11 DATASHEET关于预分频器的一些信息
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位模式就像我说的,我是初学者,所以请向我的理解水平解释。
我事先很感激!
最佳答案
来自微芯片数据表:
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
清除T08BIT以选择16位模式。
如果您不想将内部时钟(FOSC/4)作为定时器0/预分频器输入,请清除T0CS位。
清除PSA位以选择预分频器。
设置T0PS以选择预分频器速率。
将TMR0ON设置为1 ro enable timer0。
这是相等的:
T0CON =b'10000nnn' //where nnn is Prescaler value
如果您需要在定时器0溢出时中断,也可以启用定时器0中断位(GIE/GIEH、PEIE/GIEL、TMR0IE、TMR0IF)。