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

### Information

#### Conversation

Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 07:08 AM
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 01:44 PM
Devangi
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 10:30 AM
Andrius
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
Sat Oct 12 2019, 10:23 PM
Sat Oct 12 2019, 10:18 AM
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details

### Recent

wounder
Sat Jan 25 2020, 12:09 PM
brucewilliams20
Thu Jan 23 2020, 11:47 AM
Nippy56
Sun Jan 19 2020, 02:13 AM
usb5962
Sat Jan 11 2020, 10:42 AM
elt
Tue Jan 07 2020, 06:53 PM
mg3914697
Tue Jan 07 2020, 12:42 PM
afds43
Sun Dec 29 2019, 05:54 AM
Rupeshpatil
Fri Dec 27 2019, 06:14 PM

#### Online

Guests: 37, Members: 0 ...

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

Members: 38118
Forum Activity
##### Posted By ExperimenterUK
Sun Jan 26 2020, 04:05 AM
For a 12MHz crystal using a normal divided by 12 c...
##### Posted By wounder
Sat Jan 25 2020, 12:14 PM
I have a 8051 micro controller ,it has timer0,1,2,...
##### Posted By brucewilliams20
Sat Jan 25 2020, 08:25 AM
Also, does anyone knows a platform where I can liv...
##### Posted By brucewilliams20
Sat Jan 25 2020, 08:17 AM
Hi Mirza,That match and the politics, both are fin...
##### Posted By ExperimenterUK
Fri Jan 17 2020, 10:24 PM
We will need the circuit diagram.A Proteus simulat...
##### Posted By Billz
Sat Jan 11 2020, 05:43 PM
hi everyone please attached files are my c code fo...
##### Posted By ExperimenterUK
Tue Jan 07 2020, 08:18 PM
Not a stupid question.Setting up "Eclipse" can be...
##### Posted By elt
Tue Jan 07 2020, 07:06 PM
So i have just began learning programming micros a...
##### Posted By Billz
Mon Jan 06 2020, 09:22 PM
I think it would be better if you guys try to come...
##### Posted By ExperimenterUK
Mon Jan 06 2020, 12:22 AM
Can you post a circuit diagram and any code you ha...