Discussion in "8051 Discussion Forum" started by    cenadius    Oct 5, 2007.
Fri Oct 05 2007, 03:14 am
#1
ajay,give me the example on how to write delay assembly code by using both method,timer and register,thanks
Fri Oct 05 2007, 11:47 am
#2
In timers... there are few things to take care of.. first.. amount of time you want delay for, second which timer mode is suitable for that delay.
Timer increment a count every single machine cycle. so if you are using a clock of say.. 12Mhz then.. no. of times timer count is incremented is:
12000000/12 = 1000000
i.e. timer will be incremented 1,000,000 times in a sec.
Lets say you want a delay of 10mS (0.01S)
and you have to calculate the count which is to be loaded in Timer registers (THx and TLx) to find the count to be loaded.. simply multiply the required delay with the count per sec..
i.e. 0.01 x 1,000,000 = 10,000
so we need to count from 0 to 10,000. Maximum count for 16 bit timer is 65536. So if we load 65536-10000 = 55536 in timer registers it till automatically count 10000 times..
So final value is 55536 (DF80H)
so THx = DFH and TLx = 80H
this will give you the required delay...

in case of registers.. you need to add all the time delay required for an instruction to execute and then multiply it by the loop count.. that will give you the time delay..
e.g. the commonly used instructions in register delay are.. djnz Rx,label (2 machine cycles)
loading value using MOV instruction also need 2 machine cycles. RET instuction and Acall instuction both need 2 machine cycles.
Lets say you want a delay of 100uS then.. you are running a clock of 12Mhz, so 1 machine cycle will be of 1uS. you can divide this according to the instructions as...
100 - 2(RET) - 2(lcall) - 2 (load) = 94uS left
94/2 (for DJNZ) = 47 (the count)

so required loop for 100uS delay is..

delay100uS:
      mov R7,#47
wait:
      djnz r7,wait
      ret
 youth69shaikmajoka like this.
Tags 8051 time delaytime delay calculationdelay using timersdelay using registers8051 timers
Sat Oct 06 2007, 10:26 am
#3
ok,thanks,i need this in my exam,thanks for ur explaination :-)
Fri Apr 15 2011, 08:59 pm
#4
wow ajay! Nice explaination <3
Sat Apr 16 2011, 02:20 pm
#5
you can also use this simple program to help you in delay with assembly code from here
Tue Apr 19 2011, 01:50 am
#6
@MAAM this program is also available here on website

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm