<?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><a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank"><img alt="Creative Commons License" width="80" height="15" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/2.5/in/80x15.png" target="_blank" /></a>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank">Creative Commons Attribution-Noncommercial 2.5 India License</a>.<a href='http://www.8051projects.net/disclaimer.htm' target='_blank' />Rickey's World Disclaimer</a></copyright>
				<managingEditor>Ajay Bhargav - contact@nospam.com</managingEditor>
				<webMaster>contact@nospam.com</webMaster>
				<pubDate>Mon, 01 Dec 2008 13:33:10 -0800</pubDate>
				<lastBuildDate>Mon, 01 Dec 2008 13:33:10 -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>Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[I have heard many people on forum asking for learning AVR Microcontroller. So i got this idea to start a new thread where I will post step by step information which will help you get started with AVR microcontroller.<br />This thread not only help you understand AVR, but also it will cover all the details regarding interfacing and other stuff.. so you can say its a complete E-book for you to learn AVR.<br />We will also discuss problems you face while working on with the assignments. So i get started with the essentials of AVR.<br /><br />Note: The tutorials will be in assembly language. We can discuss about C later on.<br /><br /><div class='indent'><strong class='bbcode bold'>Lets Learn AVR - Step 1:</strong><br /><br />The first step in the development of any micrcontroller is to know about its architecture and instruction set. So i advice you all to keep a copy of instruction set and architecture manual. You can download them from the link below.<br /> <a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/dyn/resources/prod_documents/doc0856.pdf' rel='external'  target='_blank'>AVR Instruction Set   (User Guide, 150 pages)</a><br /> <a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/dyn/products/datasheets.asp?family_id=607#760' rel='external'  target='_blank'>Architecture Manual or Datasheet for your AVR Microcontroller</a><br /><br />The above document will help you to get familiar with the instruction set and to know about your AVR in a better way.<br />After this, we now have to decide the IDE on which you are going to work or write program for your AVR. I advice you to use AVR Studio 4 from Atmel Corporation, which is a free IDE for AVR and it has many features like programming, debugging etc.<br />You can get your free copy of AVR studio from link below.<br /> <a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/forms/software_download.asp?fn=dl_aStudio4b460.exe' rel='external'  target='_blank'>AVR Studio 4.12 (build 460)   (45 MB, updated 11/05)</a> - Registration needed<br /> <a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/dyn/resources/prod_documents/aStudio412SP4b498.exe' rel='external'  target='_blank'>AVR Studio 4.12 Service Pack 4 (build 498)  (25 MB, updated 10/06)</a> - No registration<br /> <a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/forms/software_download.asp?fn=dl_aStudio4b528.exe' rel='external'  target='_blank'>AVR Studio 4.13 (build 528)   (73 MB, updated 03/07)</a> - Registration needed<br /><br />So you can download any of the copy above as per your need more information about AVR studio can be obtained from <br /><strong class='bbcode bold'><a class='bbcode' href='http://www.8051projects.net/out.php?link=http://atmel.com/dyn/products/tools_card.asp?tool_id=2725' rel='external'  target='_blank'>AVR Studio 4</a> </strong><br /><br />All documents and IDE for writing program is ready.. only thing left is a programmer, with which we are going to program our AVR. As we know almost all AVR comes with ISP (In System Programmable) ports. So you don't need any special hardware to program your AVR. Please see the link below for ISP programmer for AVR.<br /><a class='bbcode' href='http://www.8051projects.net/out.php?link=http://www.lancos.com/ppwin95.html' rel='external'  target='_blank'>Download PonyProg - serial device programmer</a><br /><br />Interfacing Schematic:<br /><a class='bbcode' href='http://www.8051projects.net/out.php?link=http://www.lancos.com/e2p/betterSTK200.gif' rel='external'  target='_blank'><img src='http://www.lancos.com/e2p/betterSTK200-mini.gif' class='bbcode' alt=''  />	</a><br /><br />Note: Do not forget to run the setup after installing PonyProg.<br /><br /><strong class='bbcode bold'>Setup Information:</strong><br />In interface setup, select parallel and then from the drop down select AVR ISP I/O.<br />slect the LPT Port (parallel port) available on your PC. Then click ok!<br /><br /><strong class='bbcode bold'>To load Hex file:</strong><br />Go to File-> Open Program (FLASH) file<br />then from the drop down where ".e2p" is show, select ".hex" and load your hex file.</div><br /><br />The first step of our AVR tutorial is over... if you have any doubts please post in the link below<br /><a class='bbcode' href='http://www.8051projects.net/forum-t1700-last.html' rel='external'  target='_blank'><strong class='bbcode bold'>Doubts in AVR tutorial - Step 1</strong></a>]]></description>
<pubDate>Sat, 18 Aug 2007 05:26:32 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
						<item>
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[I hope you've all gone through the step 1 and ready to work on the AVR Microcontroller.<br /><br />So lets start with the programming and writing our first program which is "hello world" of microcontrollers..<br /><br /><div class='indent'><strong class='bbcode bold'>AVR Tutorial - Step 2</strong><br /><br /><div class='indent'>Note: The program i wrote is for ATMEGA8515 and there is not much difference in other AVRs except some has extra features.</div><br /><br />Before programming AVR, first you need to know few important programming tips and AVR registers.<br /><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span></div></div><br />This include the definition file for ATmega8515, so that we can directly address the registers with their names.<br />All AVRs have 32 general purpose registers from R0 - R32.<br />R0-R15 registers have certain restrictions of use, i.e. they are not allowed to load immediate value.<br />e.g. LDI R15, $35<br />the above statement will give you an error, saying "Invalid Register"<br />Where as registers from R16-R32 can be used for this purpose i.e.<br />LDI R16,$35 <br />is a valid statement.<br />You can move values from one register to other by using<br />MOV R15,R16<br /><br />Not only the registers from R0 to R15 has restriction on LDI but also other commands where the use of R0-R16 is not allowed. usually all commands having immediate operands are not allowed.<br />For the ease of programming, you can also give names to the register like<br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #0000ff;">.def</span> myregister = R16</div></div><br /><br />There are some special registers like X,Y and Z for 16-Bit operations. They are used to read and write to XRAM. They are also used for reading from program memory like reading from a lookup table (we will discuss about them when we use them). These special registers are actually combination of two 8-bit General purpose registers. i.e. X is actually R26:R27, Y is R28:R29 and Z is R30:R31.<br />The lower byte of the 16-bit-adress is located in the lower register, the higher byte in the upper register. Both parts have their own names, e.g. the higher byte of Z is named as ZH (R31) and the lower Byte is ZL (R30). Similarly for X (XL and XH) and for Y (YL and YH). These names are defined in the standard header file for the chips (which we include while writing program). Dividing these 16-bit-pointer-names into two different bytes is done like follows:<br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #00007f; font-weight:bold;">LDI</span> <span style="color: #46aa03; font-weight:bold;">YH</span>,<span style="color: #0000ff;">HIGH</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">LABEL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #adadad; font-style: italic;">; Set the MSB</span><br /><span style="color: #00007f; font-weight:bold;">LDI</span> <span style="color: #46aa03; font-weight:bold;">YL</span>,<span style="color: #0000ff;">LOW</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">LABEL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #adadad; font-style: italic;">; Set the LSB</span></div></div><br />where LABEL is address for any lookup table or any memory location.<br /><br /><strong class='bbcode bold'>Some important notes for using registers</strong><br /> <ol class='bbcode' style='list-style-type: numeric'><li class='bbcode'>Define names for registers with the .DEF directive, never use them with their direct name Rx. This helps you making better use of registers and you will never confuse yourself while using them.<br /></li><li class='bbcode'>If you need pointer access reserve R26 to R31 for that purpose.<br /></li><li class='bbcode'>16-bit-counter are best located R25:R24.<br /></li><li class='bbcode'>If you need to read from the program memory, e.g. fixed tables, reserve Z (R31:R30) and R0 for that<br />purpose.<br /></li><li class='bbcode'>If you plan to have access to single bits within certain registers (e.g. for testing flags), use R16 to<br />R23 for that purpose</li></ol><br /><br />Now coming to ports, The information about a specific port of a certain type of AVR can be easily obtained in the AVR Datasheet. Port names are defined in the include file of the CPU..<br />if you don't have an include file then you can define yourself as..<br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;">.<span style="color: #0000ff;">equ</span> <span style="color: #46aa03; font-weight:bold;">PORTA</span> = $<span style="color: #ff0000;">1B</span> <span style="color: #adadad; font-style: italic;">;incase of ATmega8515</span></div></div><br />So if you are not able to find an include file you can use the .EQU directive to define ports and other registers.<br />Making port as i/p or o/p is purely dependent on data direction register called DDRx (DDRA for port A etc.) The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written<br />logic one, Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configured<br />as an input pin.<br />for writing and reading data to Ports, PORTx registers are there. and to read from ports PINx registers are there.<br />for example..<br />writing to port<br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #0000ff;">.def</span> output = R16<br /><span style="color: #00007f; font-weight:bold;">LDI</span> output, $FF<br /><span style="color: #00007f; font-weight:bold;">OUT</span> <span style="color: #46aa03; font-weight:bold;">DDRA</span>, output <span style="color: #adadad; font-style: italic;">; making as o/p</span><br /><span style="color: #00007f; font-weight:bold;">LDI</span> output, $<span style="color: #ff0000;">00</span><br /><span style="color: #00007f; font-weight:bold;">OUT</span> <span style="color: #46aa03; font-weight:bold;">PORTA</span>, output <span style="color: #adadad; font-style: italic;">; clear all PORTA pins</span></div></div><br />Reading from port<br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #0000ff;">.def</span> input = R17<br /><span style="color: #00007f; font-weight:bold;">LDI</span> input, $<span style="color: #ff0000;">00</span><br /><span style="color: #00007f; font-weight:bold;">OUT</span> <span style="color: #46aa03; font-weight:bold;">DDRA</span>,input<br /><span style="color: #00007f; font-weight:bold;">IN</span> input, <span style="color: #46aa03; font-weight:bold;">PINA</span></div></div><br /><br /><br />We are finished with the basics of AVR, lets try programming with simplest program. Blinking an LED!<br /><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Include file</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">RJMP</span> MAIN&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Reset vector</span><br /><br />MAIN:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> R16,<span style="color: #0000ff;">low</span><span style="color: #66cc66;">&#40;</span>RAMEND<span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load stack with</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">out</span> <span style="color: #46aa03; font-weight:bold;">SPL</span>,R16&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;RAMEND - highest value</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> R16,<span style="color: #0000ff;">high</span><span style="color: #66cc66;">&#40;</span>RAMEND<span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;of internal SRAM</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">out</span> <span style="color: #46aa03; font-weight:bold;">SPH</span>,R16<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">SBI</span> <span style="color: #46aa03; font-weight:bold;">DDRA</span>,<span style="color: #ff0000;">0</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Make PORTA Pin 0 as o/p</span><br /><br />DO:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">SBI</span> <span style="color: #46aa03; font-weight:bold;">PORTA</span>,<span style="color: #ff0000;">0</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Set Pin 0 of PORTA</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">RCALL</span> DELAY&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Wait for some time</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">CBI</span> <span style="color: #46aa03; font-weight:bold;">PORTA</span>,<span style="color: #ff0000;">0</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Cleare Pin 0 of PORTA</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">RCALL</span> DELAY&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Wait for some time</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">RJMP</span> DO&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Forever loop!</span><br /><br />DELAY:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;The delay routine</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">LDI</span> R16,$<span style="color: #ff0000;">20</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load some delay value</span><br />LOOP1:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">SER</span> R17&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Make R17 as $FF</span><br /><span style="color: #00007f; font-weight:bold;">LOOP</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">DEC</span> R17&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Decrement R17</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">BRNE</span> <span style="color: #00007f; font-weight:bold;">LOOP</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Jump if not zero</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">DEC</span> R16&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Decrement R16</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">BRNE</span> LOOP1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Jump if not zero</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">RET</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Return</span></div></div><br /><br />Please post your problems in the forum <img src='http://www.8051projects.net/e107_images/emotes/yahoo/1.gif' alt='' style='vertical-align:middle; border:0' />  <br /><a class='bbcode' href='http://www.8051projects.net/forum-t1700-last.html' rel='external'  target='_blank'>Doubts in AVR tutorial</a></div>]]></description>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Mon, 20 Aug 2007 07:55:31 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
						<item>
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[I hope you are now familiar with the register set of AVR and instructions that deals with these registers.<br />So let move on to our next step of the tutorial. I named it as <br /><strong class='bbcode bold'>"Dealing with load and store instructions of AVR"</strong><br /><br /><div class='indent'>Lets learn AVR Tutorial - Step 3<br /><br />In this part of tutorial you will learn<br /><ol class='bbcode' style='list-style-type: numeric'><li class='bbcode'>Reading from Program memory<br /></li><li class='bbcode'>Reading from RAM<br /></li><li class='bbcode'>Writing to RAM<br /></li><li class='bbcode'>Practice programs</li></ol><br />Here is the summary of Load and store instructions that are used for dealing with SRAM of AVR Microcontroller<br /><ol class='bbcode' style='list-style-type: lower-roman'><li class='bbcode'>LD Rn,X/Y/Z<br />>either X or Y or Z register can be used<br />>this will load the value which is stored in memory location pointed by register X/Y/Z to the destination register Rn (can be R0, R1.. any etc)<br /></li><li class='bbcode'>LD Rn,X+/Y+/Z+<br />>This instruction will load the value which is stored in memory at location pointed by X/Y/Z registers and then increment the memory location by 1<br />>This is a post increment instruction<br /></li><li class='bbcode'>LD Rn, -X/-Y/-Z<br />>Load Rn with value stored at location pointed by pre-decrement of address stored in X/Y/Z<br /></li><li class='bbcode'>LDD Rn,Y/Z+displacement <br />>Load Rn with value at address Z or Y + displacement<br />>e.g. Z is 0x0090, Displacement is 0x10 so Rn will be loaded with value stored at 0x0090+0x10 = 0x0100<br /></li><li class='bbcode'>ST X/Y/Z, Rn<br />>Store the value of Rn to location pointed by X or Y or Z<br /></li><li class='bbcode'>ST X+/Y+/Z+, Rn<br />>Store the value in Rn to location pointed by X or Y or Z and increment the address pointer<br /></li><li class='bbcode'>STD Y/Z+displacement, Rn<br />>Store the value in Rn to location pointed by Y or Z + Displacement<br /></li><li class='bbcode'>LDS Rn, SRAM_Address<br />>Load value from SRAM Address to the Rn register<br />>SRAM Address is the immediate value e.g. LDS R0,0x0100<br /></li><li class='bbcode'>STS SRAM_Address, Rn<br />>Store Rn to immediate SRAM location</li></ol><br /><br />To read from Program memory we have special instructions like<br /><ol class='bbcode' style='list-style-type: lower-roman'><li class='bbcode'>LPM<br />>Load form program memory, This instruction is used in most of the AVRs and its hard coded in the architecture.<br />>This instruction will load R0 with the address specified by register Z [This is hardcoded]<br /></li><li class='bbcode'>LPM Rn, Z<br />>Load Rn from program memory pointed by register Z<br />>This instruction is not supported by all AVRs e.g ATMega8515, AT90S8515<br /></li><li class='bbcode'>LPM Rn,Z+<br />>Load Rn from program memory and increment the memory location pointed by Z<br />>This instruction is also not supported by all AVRs</li></ol><br /><br /><strong class='bbcode bold'>Note: load from program memory instructions are not supported by all AVR architectures. Most of the architectures support LPM instruction which is hard coded to load R0 from location in Z. where as in some AVR this is also not implemented.</strong><br /><br />Now we are done with the instructions overview.. now lets practice them.. <br /><strong class='bbcode bold'>Program 1: Copy 10 Bytes memory block stored in Program memory(ROM) to Data memory (SRAM)</strong><br /><div class='indent'><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;This program is to copy memory block from Program</span><br /><span style="color: #adadad; font-style: italic;">;memory to AVR RAM (10 Bytes)</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br />.<span style="color: #0000ff;">org</span> $<span style="color: #ff0000;">0</span><br /><span style="color: #0000ff;">.def</span> Temp = <span style="color: #46aa03; font-weight:bold;">R0</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Temprary variable</span><br /><span style="color: #0000ff;">.def</span> count = R17&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Byte Count</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,<span style="color: #0000ff;">HIGH</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">data</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load Z with address where</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,<span style="color: #0000ff;">LOW</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">data</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;our data is stored</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">XL</span>,$<span style="color: #ff0000;">60</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load Destination RAM location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">XH</span>,$<span style="color: #ff0000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> count,$A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load count 10 Bytes</span><br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load value from program memory</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">inc</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Increment memory location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">X</span>+,Temp&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Store byte to the RAM location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Decrement Count</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> again&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Check if all bytes moved</span><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;End of program</span><br /><br /><span style="color: #adadad; font-style: italic;">;Our data which we will copy from Program Memory to RAM</span><br /><span style="color: #0000ff;">Data</span>:<br />.<span style="color: #0000ff;">db</span> $<span style="color: #ff0000;">10</span>,$<span style="color: #ff0000;">20</span>,$<span style="color: #ff0000;">30</span>,$<span style="color: #ff0000;">40</span>,$<span style="color: #ff0000;">50</span>,$<span style="color: #ff0000;">60</span>,$<span style="color: #ff0000;">70</span>,$<span style="color: #ff0000;">80</span>,$<span style="color: #ff0000;">90</span>,$<span style="color: #ff0000;">95</span></div></div> <br />In the above code.. you can see while loading the address of program memory location, i multiplied it with 2, i.e. LDI ZH,High(2*Data)<br />The reason is, the program memory is organized in word manner i.e. two bytes for each command, So the address has to be multiplied by 2. You can try running these programs and see its working in the Simulator of AVR Studio.</div> <br /><br /><strong class='bbcode bold'>Program 1: Find Greatest of 3 numbers Stored in program memory </strong><br /><div class='indent'><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to find greatest of 3 numbers</span><br /><span style="color: #adadad; font-style: italic;">;</span><br /><span style="color: #adadad; font-style: italic;">;numbers are stored in ROM and the final</span><br /><span style="color: #adadad; font-style: italic;">;result will be stored in a register</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> num1 = <span style="color: #46aa03; font-weight:bold;">r0</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Location for First number</span><br /><span style="color: #0000ff;">.def</span> num2 = <span style="color: #46aa03; font-weight:bold;">r1</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Location for second number</span><br /><span style="color: #0000ff;">.def</span> answer = <span style="color: #46aa03; font-weight:bold;">R2</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;location for Final answer</span><br /><br />.<span style="color: #0000ff;">org</span> $<span style="color: #ff0000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>, <span style="color: #0000ff;">Low</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">Data</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load the program memory address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>, <span style="color: #0000ff;">High</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">data</span><span style="color: #66cc66;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load first number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num2,num1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Move it to num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">inc</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Increment the address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load second number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">cp</span> num1,num2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Compare them</span><br />&nbsp; &nbsp; &nbsp; &nbsp; brlt next&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Jump if num1&lt;num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num2,num1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If num1&gt;num2 then move num1</span><br />next:&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">; to num2 location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">inc</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Increment the address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load the third number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">cp</span> num1,num2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Again compare</span><br />&nbsp; &nbsp; &nbsp; &nbsp; brlt final&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Check if num1&lt;num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> answer,num1&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If No, then num1 is answer</span><br />final:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> answer,num2&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If Yes, then num2 is our answer</span><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;End of program</span><br /><br /><br /><span style="color: #0000ff;">Data</span>:&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Our 3 numbers</span><br />.<span style="color: #0000ff;">db</span> $<span style="color: #ff0000;">23</span>,$<span style="color: #ff0000;">23</span>,$<span style="color: #ff0000;">14</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Try changing them and see results</span></div></div></div> <br /><br />Now you can try yourself writing some programs to make yourself more easy with load and store operations.<br />Here is the list of programs you can try out:<br /><ol class='bbcode' style='list-style-type: upper-alpha'><li class='bbcode'>Swap two numbers stored in RAM<br /></li><li class='bbcode'>Find Greatest of 5 numbers<br /></li><li class='bbcode'>Copy memory block from RAM to RAM<br /></li><li class='bbcode'>Sorting of 10 numbers<br /></li><li class='bbcode'>Clear SRAM area from 0x60 to RAMEND</li></ol><br /></div> <br /><br />*Happy programming with your AVR*<br /><br />Any Doubts? Post here...<br /> <a class='bbcode' href='http://www.8051projects.net/forum-t1700-last.html' rel='external'  target='_blank'> <strong class='bbcode bold'>Doubts in AVR Tutorial - Step 3</strong> </a>]]></description>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Mon, 27 Aug 2007 05:17:05 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
						<item>
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[I think the wait is over... now as i am not getting any questions from your side.. so i can post the answer to the assignment i gave.. which is 5 programs..<br />So here are the programs.. Please take a look!<br /><strong class='bbcode bold'>Swap two numbers stored in RAM</strong><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to swap two numbers</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> temp = R16 <span style="color: #adadad; font-style: italic;">;Temporary register</span><br /><span style="color: #0000ff;">.def</span> num1 = R17 <span style="color: #adadad; font-style: italic;">;Number one location</span><br /><span style="color: #0000ff;">.def</span> num2 = R18 <span style="color: #adadad; font-style: italic;">;Location for second number</span><br /><br />.<span style="color: #0000ff;">cseg</span><br />.<span style="color: #0000ff;">org</span> $<span style="color: #ff0000;">0</span><br /><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,0x00 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Assuming the two numbers are stored</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x90 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;at location 0x0090 in RAM</span><br /><span style="color: #00007f; font-weight:bold;">ld</span> num1,<span style="color: #46aa03; font-weight:bold;">Z</span>+ &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load first number</span><br /><span style="color: #00007f; font-weight:bold;">ld</span> num2,<span style="color: #46aa03; font-weight:bold;">Z</span> &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load second number</span><br /><span style="color: #00007f; font-weight:bold;">mov</span> temp,num1 &nbsp; <span style="color: #adadad; font-style: italic;">;copy num1 to temp</span><br /><span style="color: #00007f; font-weight:bold;">mov</span> num1,num2 &nbsp; <span style="color: #adadad; font-style: italic;">;copy num2 to num1</span><br /><span style="color: #00007f; font-weight:bold;">mov</span> num2,temp &nbsp; <span style="color: #adadad; font-style: italic;">;copy temp to num2</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x90 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;load the RAM location back</span><br /><span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Z</span>+,num1 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;store the first number</span><br /><span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Z</span>, num2 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;store the second number</span><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;end of prog</span></div></div><br /><br /><strong class='bbcode bold'>Find Greatest of 5 numbers</strong><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to find greatest of 5 numbers</span><br /><span style="color: #adadad; font-style: italic;">;</span><br /><span style="color: #adadad; font-style: italic;">;numbers are stored in ROM and the final</span><br /><span style="color: #adadad; font-style: italic;">;result will be stored in a register</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> num1 = <span style="color: #46aa03; font-weight:bold;">r0</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Location for First number</span><br /><span style="color: #0000ff;">.def</span> num2 = <span style="color: #46aa03; font-weight:bold;">r1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Location for second number</span><br /><span style="color: #0000ff;">.def</span> answer = <span style="color: #46aa03; font-weight:bold;">R2</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;location for Final answer</span><br /><span style="color: #0000ff;">.def</span> count = r16 &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Count</span><br /><br />.<span style="color: #0000ff;">org</span> $<span style="color: #ff0000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>, <span style="color: #0000ff;">Low</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">Data</span><span style="color: #66cc66;">&#41;</span> <span style="color: #adadad; font-style: italic;">;Load the program memory address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>, <span style="color: #0000ff;">High</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*<span style="color: #0000ff;">data</span><span style="color: #66cc66;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> count,<span style="color: #ff0000;">4</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load count</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load first number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num2,num1 &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Move it to num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Z</span>,<span style="color: #ff0000;">1</span><br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">lpm</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load second number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">cp</span> num1,num2 &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Compare them</span><br />&nbsp; &nbsp; &nbsp; &nbsp; brlt next &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Jump if num1&lt;num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num2,num1 &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If num1&gt;num2 then move num1</span><br />next: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">; to num2 location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Z</span>,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Increment the address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;are we done with all 5 numbers?</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> again &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;if no then jump back</span><br />final:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> answer,num2 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If Yes, then num2 is our answer</span><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;End of program</span><br /><br /><span style="color: #adadad; font-style: italic;">;Try changing them and see results</span><br /><span style="color: #0000ff;">Data</span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Our 5 numbers</span><br />.<span style="color: #0000ff;">db</span> $<span style="color: #ff0000;">3</span>,$<span style="color: #ff0000;">23</span>,$<span style="color: #ff0000;">14</span>,$<span style="color: #ff0000;">50</span>,$<span style="color: #ff0000;">20</span>,$<span style="color: #ff0000;">0</span><br /><span style="color: #adadad; font-style: italic;">;last zero is to aligh the bytes in word manner</span><br /><span style="color: #adadad; font-style: italic;">;we have 5 numbers so i am padding with a 0 to make it</span><br /><span style="color: #adadad; font-style: italic;">;even. if we dont't do this.. compiler will do it</span><br /><span style="color: #adadad; font-style: italic;">;automatically to prevent misalignment.</span></div></div><br /><br /><strong class='bbcode bold'>Copy memory block from RAM to RAM</strong><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to copy a block of memory (10 Bytes)</span><br /><span style="color: #adadad; font-style: italic;">; from one RAM location to another RAM location.</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> temp = <span style="color: #46aa03; font-weight:bold;">r0</span><br /><span style="color: #0000ff;">.def</span> count = r16<br /><br />.<span style="color: #0000ff;">org</span> <span style="color: #ff0000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x60 &nbsp; <span style="color: #adadad; font-style: italic;">;Lets fill the RAM with some numbers</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,0x00 &nbsp; <span style="color: #adadad; font-style: italic;">;to copy, so we can check is it working</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> count,<span style="color: #ff0000;">10</span> &nbsp;<span style="color: #adadad; font-style: italic;">;Load count</span><br />fill:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Z</span>+,count &nbsp; <span style="color: #adadad; font-style: italic;">;Store value to RAM location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> fill<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x60 &nbsp; <span style="color: #adadad; font-style: italic;">;Load memory location to copy from</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,0x00<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">YL</span>,0x90 &nbsp; <span style="color: #adadad; font-style: italic;">;Load destination memory location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">YH</span>,0x00<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> count,<span style="color: #ff0000;">10</span> &nbsp;<span style="color: #adadad; font-style: italic;">;Load count</span><br /><br />copy:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ld</span> temp,<span style="color: #46aa03; font-weight:bold;">Z</span>+ &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load value to temporary register</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Y</span>+,temp &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Store it to location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;decrement counter</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> copy<br /><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;End of program...</span></div></div><br /><br /><strong class='bbcode bold'>Sorting of 10 numbers</strong> <br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to sort 10 numbers </span><br /><span style="color: #adadad; font-style: italic;">;in ascending order</span><br /><span style="color: #adadad; font-style: italic;">;10 numbers are stored in ROM</span><br /><span style="color: #adadad; font-style: italic;">;and sorted answer is stored in RAM</span><br /><span style="color: #adadad; font-style: italic;">;at location 0x0060</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> count1 = r17 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;First Count</span><br /><span style="color: #0000ff;">.def</span> count2 = r18 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Second count</span><br /><span style="color: #0000ff;">.def</span> temp = <span style="color: #46aa03; font-weight:bold;">r0</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Temp reg for swap</span><br /><span style="color: #0000ff;">.def</span> num1 = <span style="color: #46aa03; font-weight:bold;">r1</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Num 1</span><br /><span style="color: #0000ff;">.def</span> num2 = <span style="color: #46aa03; font-weight:bold;">r2</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Num 2</span><br /><br />.<span style="color: #0000ff;">cseg</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Code segment starts</span><br />.<span style="color: #0000ff;">org</span> <span style="color: #ff0000;">0</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">Zh</span>,<span style="color: #0000ff;">high</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*mydata<span style="color: #66cc66;">&#41;</span> <span style="color: #adadad; font-style: italic;">;Load memory add where</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">Zl</span>,<span style="color: #0000ff;">low</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span>*mydata<span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #adadad; font-style: italic;">;data is stored in ROM</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">Yh</span>,0x00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Destination location</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">Yl</span>,0x60 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;0x0060 in RAM</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> count1,<span style="color: #ff0000;">10</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load count</span><br /><br />copy:<br /><span style="color: #00007f; font-weight:bold;">lpm</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load from program mem</span><br /><span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Y</span>+,temp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Store it to RAM</span><br /><span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Z</span>,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Increment Z</span><br /><span style="color: #00007f; font-weight:bold;">dec</span> count1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Decrement counter</span><br /><span style="color: #00007f; font-weight:bold;">brne</span> copy &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;copy all 10 bytes</span><br /><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,0x00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load first pointer</span><br /><span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x60<br /><span style="color: #00007f; font-weight:bold;">ldi</span> count1,<span style="color: #ff0000;">10</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load counter for it</span><br /><br />sort:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> <span style="color: #46aa03; font-weight:bold;">YL</span>,<span style="color: #46aa03; font-weight:bold;">ZL</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load second pointer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> <span style="color: #46aa03; font-weight:bold;">YH</span>,<span style="color: #46aa03; font-weight:bold;">ZH</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Y</span>,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Increment it</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ld</span> num1,<span style="color: #46aa03; font-weight:bold;">Z</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;load first number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> count2,count1 <span style="color: #adadad; font-style: italic;">;load count2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">subi</span> count2,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Count2 = Count1-1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">breq</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;end if last num</span><br /><br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ld</span> num2,<span style="color: #46aa03; font-weight:bold;">Y</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Load second number</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">cp</span> num1,num2 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Compare them</span><br />&nbsp; &nbsp; &nbsp; &nbsp; brlo next &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Jump if num1&lt;num2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> temp,num2<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num2,num1 &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;If num1&gt;num2 then swap</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">mov</span> num1,temp<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Z</span>,num1 &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;and store them on their</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Y</span>,num2 &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;respective locations</span><br />next: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Y</span>,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Increment the address</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count2 &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;dec count2 for Y pointer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> again &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;check if count is zero</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">adiw</span> <span style="color: #46aa03; font-weight:bold;">Z</span>,<span style="color: #ff0000;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;increment Z pointer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">dec</span> count1 &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Dec count1 for Z pointer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> sort &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;finish if zero</span><br /><br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;End of program</span><br /><br />mydata:<br />.<span style="color: #0000ff;">db</span> $<span style="color: #ff0000;">10</span>,$<span style="color: #ff0000;">90</span>,$<span style="color: #ff0000;">50</span>,$<span style="color: #ff0000;">20</span>,$<span style="color: #ff0000;">91</span>,$<span style="color: #ff0000;">23</span>,$<span style="color: #ff0000;">55</span>,$<span style="color: #ff0000;">62</span>,$<span style="color: #ff0000;">39</span>,$<span style="color: #ff0000;">80</span></div></div><br /><br /><strong class='bbcode bold'>Clear SRAM area from 0x60 to RAMEND</strong><br /><div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="asm" style="font-family: monospace;"><span style="color: #adadad; font-style: italic;">;Program to clear RAM</span><br /><span style="color: #adadad; font-style: italic;">;this program is for ATMega8515 So ram area is from</span><br /><span style="color: #adadad; font-style: italic;">;0x60 to RAMEND</span><br /><br /><span style="color: #0000ff;">.include</span> <span style="color: #7f007f;">&quot;8515def.inc&quot;</span><br /><br /><span style="color: #0000ff;">.def</span> temp = r16 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Temporary variable</span><br /><span style="color: #0000ff;">.def</span> cnth = r25 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Counter High byte</span><br /><span style="color: #0000ff;">.def</span> cntl = r24 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Counter Low byte</span><br /><br />.<span style="color: #0000ff;">org</span> <span style="color: #ff0000;">0</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> cnth,0x02 &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load count 0x200 to clear</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> cntl,0x00 &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;memory from 0x00 to 0x1FF</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">clr</span> temp &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;clear temp</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZH</span>,0x00 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;Load starting address of</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">ldi</span> <span style="color: #46aa03; font-weight:bold;">ZL</span>,0x60 &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;RAM 0x0060 in Z pointer</span><br /><br />clrram:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">st</span> <span style="color: #46aa03; font-weight:bold;">Z</span>+,temp &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;Store 0 in current Z location</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">sbiw</span> cnth:cntl,<span style="color: #ff0000;">1</span> <span style="color: #adadad; font-style: italic;">;Decrement the counter</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">brne</span> clrram &nbsp; &nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">;end if zero</span><br />&nbsp; &nbsp; &nbsp; &nbsp;<br /><span style="color: #0000ff;">end</span>:<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f; font-weight:bold;">rjmp</span> <span style="color: #0000ff;">end</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #adadad; font-style: italic;">;End of program</span></div></div>]]></description>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Mon, 03 Sep 2007 04:32:48 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
						<item>
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[<span style='font-size:18px'>Interfacing Keypad with AVR microcontroller</span><br /><br /><div class='indent'><a class='bbcode' href='http://www.8051projects.net/keypad-interfacing/' rel='external'  target='_blank'><strong class='bbcode bold'>Keypad Tutorial</strong></a><br />Learn to interface a 4x4 matrix keypad with AVR microcontroller.</div>]]></description>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Thu, 29 Nov 2007 02:05:45 -0800</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
						<item>
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
<link>http://www.8051projects.net/forum-t1701.html</link>
<description><![CDATA[<span style='font-size:14px'><strong class='bbcode bold'>AVR Serial Programming Tutorial</strong></span><br /><br /><div class='indent'><a href="http://www.8051projects.net/serial-communication/" title="AVR UART programming"><b>AVR UART Programming</b></a><br /><br />Learn to program AVR in C as well as assembly for serial Programming or UART programming.<br /></div><br /><br /><span style='font-size:14px'><strong class='bbcode bold'>Interfacing ADC with AVR</strong></span><br /><br /><div class='indent'><a href="http://www.8051projects.net/adc-interfacing/" title="Interfacing ADC with AVR"><b>ADC0804 interfacing tutorial</b></a><br /><br />Interface an 8-bit ADC (ADC0804) with AVR microcontroller.<br /></div>]]></description>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Sat, 27 Oct 2007 13:49:16 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t1701.html</guid>
</item>
				</channel>
				</rss>