我真的不太了解计时器,但我正在尝试更改timer0,使其在16位模式下使用1:64的预分频器?我从Microchip得到了定时器代码,它使用的是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位模式?就像我说的,我是初学者,所以请向我的理解水平解释一下。
我提前感谢你了!
发布于 2013-07-12 16:47:03
摘自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/4)作为定时器0/预分频器输入,则
这是相等的:
T0CON =b'10000nnn' //where nnn is Prescaler value如果需要中断Timer0溢出,请同时启用Timer0中断位(GIE/GIEH、PEIE/GIEL、TMR0IE、TMR0IF)。
https://stackoverflow.com/questions/17600157
复制相似问题