# 8051 compute delay

#### kawtar

Apr 15, 2016
4
Hi
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.
Code:
 CLR P2.3
MOV TMOD, #01H
HERE: MOV TL0, #3EH
MOV TH0, #0B8H
SETB P2.3
SETB TR0
AGAIN: JNB TF0, AGAIN
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

#### Amar Dhore

Dec 2, 2015
129
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

Jul 16, 2012
8
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.

Replies
1
Views
981
Replies
1
Views
2K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
1
Views
910