Discussion in "8051 Discussion Forum" started by    cenadius    Oct 4, 2007.
Thu Oct 04 2007, 09:44 PM
#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, 06:17 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, 04:56 AM
#3
ok,thanks,i need this in my exam,thanks for ur explaination :-)
Fri Apr 15 2011, 03:29 PM
#4
wow ajay! Nice explaination <3
Sat Apr 16 2011, 08:50 AM
#5
you can also use this simple program to help you in delay with assembly code from here
Mon Apr 18 2011, 08:20 PM
#6
@MAAM this program is also available here on website

Get Social

Information

Powered by e107 Forum System

Conversation

Sat Jul 20 2019, 05:38 AM
charmdatexvo
cooking
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 07:44 PM
@praveen123. Can you give a link to the project ?
Thu Jul 11 2019, 04:47 PM
ramos
buenos dias alguien podria ayudarme necesito saber como descargar la libreria del l298n para proteus
Thu Jul 11 2019, 11:11 AM
praveen123
anyone can help me
Thu Jul 11 2019, 11:11 AM
praveen123
i need source code for 8051 -smart trolley rfid
Thu Jul 11 2019, 11:10 AM
praveen123
hii
ExperimenterUK
Thu Jun 27 2019, 09:14 PM
Hi.. good to see you again
۞ TPS ۞
Thu Jun 27 2019, 07:31 AM
Hello
AdiGhazi
Tue Jun 18 2019, 11:21 AM
Hlo Dear , I've to program AT89C51AC3 RT-LUM using flip but I'm getting time out error for RS232. Will you please suggest me which programmer will be supportable to program this Chip.

Downloads

Comments

rpels7707
Fri Jul 19 2019, 11:31 AM
ameya123
Fri Jul 19 2019, 07:36 AM
anhsieuno
Thu Jul 18 2019, 11:39 AM
zxcvbnm1234
Sat Jul 13 2019, 07:09 AM
surajghayal
Wed Jul 10 2019, 01:17 PM
figureyang
Fri Jul 05 2019, 04:25 AM
mousompal
Sat Jun 29 2019, 05:02 PM
AdiGhazi
Tue Jun 18 2019, 11:15 AM

Online

Guests: 32, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38080
Newest member: rpels7707
Forum Activity
ameya123 Avatar
Posted By ameya123
Fri Jul 19 2019, 07:42 AM
Hello,Please share 8051 Assembly language code for...
figureyang Avatar
Posted By figureyang
Fri Jul 05 2019, 04:37 AM
here is the source code prepared for you download ...
figureyang Avatar
Posted By figureyang
Fri Jul 05 2019, 04:30 AM
Cheap_Flash_FS(Normal Version)--Embedded FAT16/32 ...
wimac Avatar
Posted By wimac
Sat Jun 22 2019, 01:26 PM
I’ve use the AT89C51ED2 which has a similar progra...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jun 20 2019, 10:08 PM
baud rate is 9600 at stop bits of 2. AdiGhaziThe u...
AdiGhazi Avatar
Posted By AdiGhazi
Thu Jun 20 2019, 05:24 AM
Dear,I'm using RS232 serial port cable to use flip...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 18 2019, 10:19 PM
Okay.. I have never programmed the AT89C51AC3 or ...
AdiGhazi Avatar
Posted By AdiGhazi
Tue Jun 18 2019, 11:20 AM
Hlo Dear ,I've to program AT89C51AC3 RT-LUM using ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu May 30 2019, 08:32 PM
It occurs to me that although the P89LPC921 and P8...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed May 29 2019, 09:05 PM
I would suggest a fresh approach.The Keil compile...