2.SETB P3.4
3.MOV R1,#28
4.MOV TL0,#00H
5.MOV TH0,#00H
6.MOV TL1,#00H
7.MOV TH1,#00H
11.CLR TF1
12.CLR TR1
14.CLR TR0
15.CLR TR1

This program written above is to count the frequency of pulse which is present at the pin p3.4. we are using timer 0 as counter, and timer 1 as normal timer.in line 10, the control wastes around 35.75 ms, so in order to make timer 0 active for around 1 second, we are using line 10 for 28 times.

enter image description here

But here in the image in line 14 they referenced the DJNZ to line 8, why? What is the the point of refilling the register with 00 again? They could have simply clear the TF1 to start the timer again from 00 instead they are stopping the timer in line 13, and again restarting it after filling with 00.

What is the need of stopping the timer and refill it again with 00? Won't just clearing the TF1 (While keeping TR1 is set) make the timer again start counting from 00? Since the roll over value is already 00 and loaded in the timer after overflow. So isn't it that the first program will work better in terms of accuracy?

  • \$\begingroup\$ The long comment chain has exceeded what is reasonable for comments. Therefore it has been moved to chat and should be continued there (link below). --- As this bulk moving of comments to chat can only be done once per question, any further comments posted here which try to discuss the question, might be deleted without notice. Keep it in chat, please! When someone has got enough information from the chat to post an answer, then please do that. Any improvements / updates to the question which are decided during the chat, should be made via an edit to the question, as usual. Thanks. \$\endgroup\$
    – SamGibson
    Commented Jul 27, 2021 at 18:26
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – SamGibson
    Commented Jul 27, 2021 at 18:26

1 Answer 1


Depends on what's the intention of the user with timer.

If the user's intention was to implement a 16-bit timer that simply runs from 0x0 to 0xFFFF, overflow, and then cycle through again (say, to do some periodic task):

YEA, he didn't have to stop the timer after the overflow and then reload with 0x0. Since TR1 is still set, timer anyway after the overflow, starts from 0x0 and increments again. In this case, clearing TF1 would be enough.

Note that: clearing TF1 is not resetting/reloading the timer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.