gpt4 book ai didi

c - 如何使timer0使用1 :64 in 16 bit mode?的预分频器

转载 作者:太空宇宙 更新时间:2023-11-04 00:07:29 25 4
gpt4 key购买 nike

我对定时器确实不太了解,但我正在尝试更改 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 位模式?就像我说的我是初学者,所以请根据我的理解水平解释事情。

提前致谢!

最佳答案

来自 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)。

关于c - 如何使timer0使用1 :64 in 16 bit mode?的预分频器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17600157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com