Connect with us

8051 compute delay

Discussion in 'Microcontrollers, Programming and IoT' started by kawtar, May 3, 2017.

Scroll to continue with content
  1. kawtar


    Apr 15, 2016
    I need help here I found this problem on the internet
    Can somebody please explain to me this program ( line by line if possible)
    Find the delay generated by timer 0 in the following code.
     CLR P2.3
     MOV TMOD, #01H
     HERE: MOV TL0, #3EH
     MOV TH0, #0B8H
     SETB P2.3
     SETB TR0
     CLR TR0
     CLR TF0
     CLR P2.3
    I didnt understand the code and the result (FFFF-B83E+1)*1.085 = 47C2 (hex) *1.085 = 18370 (decimal) *1.085 = 19.93145ms where did the. Where did the number ffff come from
    thank you
  2. Amar Dhore

    Amar Dhore

    Dec 2, 2015
    Its simple timer program. You have to check the specs on the micro to get more understanding and specifically check timer registers.
    This program is initializing timer with TMOD register. It is putting the the counts in the timer registers TL0 and TH0.
    The program is waiting for a timer expire flag (TF0). It stays in the loop (AGAIN: JNB TF0, AGAIN)

    and finally (FFFF-B83E+1) where did this come from? Look into the micro specifications, you will get your answer and if you dont post back here.
    Hope it helps
    Harald Kapp likes this.
  3. Josh Bensadon

    Josh Bensadon

    Jul 16, 2012
    The FFFF number comes from the fact that this is a 16 bit timer that counts up, and the TF flag (timer overflow) gets set when the counter rolls over from FFFF to 0000.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day