help me fix this code, please ( ASM )

Status
Not open for further replies.

trungbeca

Newbie level 4
Joined
Feb 26, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,326
8051_help me check this delay ( ASM )

i wanna delay 1 second, but it isn't true.
this is my code:

delay:
mov TMOD,#01H ; mode 16bit, timer 0
mov TH0,#00H ; N0=0
mov TL0,#00H ;
mov r1,#0FH ; repeated 15 times
setb TR0 ; start timer
wait:
jnb TF0,wait
djnz r1,wait
ret


thanks!
 
Last edited:

You didn't specified the crystal value and the microcontroller you are using...
But it seems MCS 51.
So lets assume you have 12MHz clock with an old 8051...

For 12 MHz,
12 Mhz/12= 1MHz (Effective clock to the core)
( 1 / 1MHz ) = 1us (minimum time for single execution)

(65536-xx)*1us= 50 ms (50ms is the perfect round figure 'with' highest delay by timer MODE 1)
(65536-xx)=50,000 (50ms = 50,000 microsecond)
xx=15536
in hex it is
xx=3CB0H
You can use window calculator for conversion from decimal to hexadecimal
now
TH0=03CH
TL0=0B0H

Now you got the timer high and low values...
For 1s delay, write code in the following manner..

Code:
delay:
mov TMOD,#01H ; mode 16bit, timer 0
mov TH0,#03CH ; 
mov TL0,#0B0H ;
mov r1,#20 ; repeated 20 times (50ms x 20 = 1s)
setb TR0	 ; start timer
wait:
jnb TF0,wait
clr TF0 
clr TR0 
mov TH0,#03CH
mov TL0,#0B0H 
setb TR0 
djnz r1,wait
.
.
.
.
 
thanks
have a nice day
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…