Timer design based on 51 microcontrollers

Updated on technology 2024-03-27
5 answers
  1. Anonymous users2024-02-07

    The above answer is fine.

  2. Anonymous users2024-02-06

    When using timer method 1, the calculated value of (65536-x) exceeds 256, that is, the 16-bit timing mode of the timer, so it is necessary to send 8 bits higher to th0 and lower bits to tl0, so to calculate the high 8 bits and the low 8 bits of (65536-x), (65536-x) 256 is to calculate the high 8 bits, and (65536-x)%256 is to calculate the low 8 bits, so it is written.

    th0 = (65536-x) 256 (or th1).

    tl0 = (65536-x)%256 (or tl1).

  3. Anonymous users2024-02-05

    This is actually very simple, you only need to know one condition: crystal frequency.

    Because the machine cycle calculation formula of 51 single-chip microcomputer is 12 crystal oscillator frequency MHz, if the crystal oscillator is 12mhz, then the machine cycle is 12 (12 10 6) = 1us, that is to say, the counter does not count once 1us.

    Generally speaking, under the 12MHz crystal oscillator, the full count of the 16-bit timer is 65536 times, each time 1us, the maximum can be timed, then 65536 minus how much is the timing, such as (65536-x) 256, that is, the timing x microseconds.

    So if the crystal oscillator is not 12MHz, multiply the above x by 12 crystal oscillator, and the value obtained is the timing duration. The principle is the same.

    Feel free to reply to me if you don't understand something.

  4. Anonymous users2024-02-04

    That's right. Although the timer timing is more accurate than the program delay, it does not mean that there are no errors. In any case, errors are always objective. Here are two additional points:

    1. There is an error in the original program. The maximum count value of timer mode 0 is 2 13=8192us, and the initial installation value is e018h=57368us, that is, the initial loading value of timing is much greater than the maximum counting value.

    If you want to time 1ms=1000us in mode 0, the initial installation value should be 8192-1000=7192=1c18h, and the execution of other statements can be ignored because it is 2 3us level (the three statements in the factor interrupt program take only 6us). You may ask: why not convert these times into the initial value of the timer?

    The answer is that it is not necessary. No matter how it is converted, there are errors, not to mention that the time of the machine cycle is also estimated.

    2. If you want to be more accurate, you can use method 2 (automatic reload of the initial value).

  5. Anonymous users2024-02-03

    You're right about what you understand.

    Regarding the reloading of the 51 timer, the typical solution is dynamic reloading. That is, when you renew the initial value of the count, you should subtract the count from the total number to be loaded from the time when the previous overflow was ready to perform the initial value of the reload.

    For example, if the interrupt interval is 1000 counts, the initial value of the reload is -1000. In the interrupt, -1000 cannot be reloaded directly, but -(1000-th tl), that is, the reload value is -1000+th tl.

    isr_t0:

    push psw

    clr tr0

    xch a, tl0

    add a, #low(-1000+7)

    xch a, tl0

    xch a, th0

    addc a, high(1000+7) tr0 has been paused for 7 periods and needs to be added.

    xch a, th0

    set tr0

    CPL can execute the events that the user wants to do, but it keeps taking too long.

    pop psw

    RetiOf course, it can't be completely said that the book is wrong, only that the examples in the book are not rigorous.

Related questions
6 answers2024-03-27

2] Basketball game scorer series.

1] Infrared wireless remote control basketball game scorer. >>>More

5 answers2024-03-27

With DDS chip AD9850 10 yuan a piece, program control.

16 answers2024-03-27

Scheduled interrupts, external interrupts?

12 answers2024-03-27

If the timer count value is not enough, you can first set the sum number of 1, such as 1ms, and then add another number to 10 to 100ms to get the 1s time.