<?xml version="1.0" encoding="utf-8"?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rss  version="2.0">
				<channel>
				<title>8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes : Forum / topic</title>
				<link>http://www.8051projects.net/</link>
				<description>Learn to make simple microcontroller projects, pic, 8051, avr and arm projects. download 8051 projects, tutorials, libraries, sample codes. join the microcontroller discussion forum and ask doubts regarding electronics. the best source for 8051 over internet.</description>

<language>en-gb</language>
				<copyright>2008 Rickey's World</copyright>
				<managingEditor>contact@nospam.com (Ajay Bhargav)</managingEditor>
				<webMaster>contact@nospam.com (Ajay Bhargav)</webMaster>
				<pubDate>Wed, 07 Jan 2009 13:33:53 -0800</pubDate>
				<lastBuildDate>Wed, 07 Jan 2009 13:33:53 -0800</lastBuildDate>
				<docs>http://backend.userland.com/rss</docs>
				<generator>e107 (http://e107.org)</generator>
				<ttl>60</ttl>
				<textInput>
				<title>Search</title>
				<description>Search 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes</description>
				<name>query</name>
				<link>http://www.8051projects.net/search.php</link>
				</textInput>
						<item>
						<title>delay subroutine</title>
<link>http://www.8051projects.net/forum-t2751.html</link>
<description><![CDATA[ajay,give me the example on how to write delay assembly code by using both method,timer and register,thanks]]></description>
<pubDate>Thu, 04 Oct 2007 14:44:45 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t2751.html</guid>
</item>
						<item>
						<title>Re: delay subroutine</title>
<link>http://www.8051projects.net/forum-t2751.html</link>
<description><![CDATA[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.<br />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:<br />12000000/12 = 1000000<br />i.e. timer will be incremented 1,000,000 times in a sec.<br />Lets say you want a delay of 10mS (0.01S)<br />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..<br />i.e. 0.01 x 1,000,000 = 10,000<br />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..<br />So final value is 55536 (DF80H)<br />so THx = DFH and TLx = 80H<br />this will give you the required delay... <img src='http://www.8051projects.net/e107_images/emotes/yahoo/1.gif' alt='' style='vertical-align:middle; border:0' /> <br /><br />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..<br />e.g. the commonly used instructions in register delay are.. djnz Rx,label (2 machine cycles)<br />loading value using MOV instruction also need 2 machine cycles. RET instuction and Acall instuction both need 2 machine cycles.<br />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...<br />100 - 2(RET) - 2(lcall) - 2 (load) = 94uS left<br />94/2 (for DJNZ) = 47 (the count)<br /><br />so required loop for 100uS delay is..<br /><br /><div class='code_asm'>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;">delay100uS:<br />&nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> <span style="color: #46aa03; font-weight:bold;">R7</span>,#<span style="color: #ff0000;">47</span><br /><span style="color: #00007f; font-weight:bold;">wait</span>:<br />&nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">djnz</span> <span style="color: #46aa03; font-weight:bold;">r7</span>,<span style="color: #00007f; font-weight:bold;">wait</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ret</span></div></div>]]></description>
<author>contact@nospam.com (Ajay Bhargav)</author>
<pubDate>Thu, 04 Oct 2007 23:17:41 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t2751.html</guid>
</item>
						<item>
						<title>Re: delay subroutine</title>
<link>http://www.8051projects.net/forum-t2751.html</link>
<description><![CDATA[ok,thanks,i need this in my exam,thanks for ur explaination <img src='http://www.8051projects.net/e107_images/emotes/yahoo/1.gif' alt='' style='vertical-align:middle; border:0' />]]></description>
<author>contact@nospam.com (Ajay Bhargav)</author>
<pubDate>Fri, 05 Oct 2007 21:56:12 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t2751.html</guid>
</item>
				</channel>
				</rss>