Maker Pro
Maker Pro

8051 compute delay

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
 
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
 
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.
 
Top