<?xml version="1.0" encoding="utf-8" ?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
				<channel rdf:about="http://www.8051projects.net/">
				<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 8051 projects, pic projects, avr 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>
				<dc:language>en-gb</dc:language>
				<dc:date>2008-10-07T12:30:15-07:00</dc:date>
				<dc:creator>contact@nospam.com</dc:creator>
				<admin:generatorAgent rdf:resource="http://e107.org" />
				<admin:errorReportsTo rdf:resource="mailto:contact@nospam.com" />
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
				<items>
				<rdf:Seq>
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t1701.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>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.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.We will also discuss problems you face while working on with the assignments. So i get started with the essentials of AVR.Note: The tutorials will be in assembly language. We can discuss about C later on.Lets Learn AVR - Step 1: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. AVR Instruction Set   (User Guide, 150 pages) Architecture Manual or Datasheet for your AVR MicrocontrollerThe above document will help you to get familiar with the instruction set and to know about your AVR in a better way.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.You can get your free copy of AVR studio from link below. AVR Studio 4.12 (build 460)   (45 MB, updated 11/05) - Registration needed AVR Studio 4.12 Service Pack 4 (build 498)  (25 MB, updated 10/06) - No registration AVR Studio 4.13 (build 528)   (73 MB, updated 03/07) - Registration neededSo you can download any of the copy above as per your need more information about AVR studio can be obtained from AVR Studio 4 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.Download PonyProg - serial device programmerInterfacing Schematic:Note: Do not forget to run the setup after installing PonyProg.Setup Information:In interface setup, select parallel and then from the drop down select AVR ISP I/O.slect the LPT Port (parallel port) available on your PC. Then click ok!To load Hex file:Go to File-> Open Program (FLASH) filethen from the drop down where ".e2p" is show, select ".hex" and load your hex file.The first step of our AVR tutorial is over... if you have any doubts please post in the link belowDoubts in AVR tutorial - Step 1</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>I hope you've all gone through the step 1 and ready to work on the AVR Microcontroller.So lets start with the programming and writing our first program which is "hello world" of microcontrollers..AVR Tutorial - Step 2Note: The program i wrote is for ATMEGA8515 and there is not much difference in other AVRs except some has extra features.Before programming AVR, first you need to know few important programming tips and AVR registers.CODE:.include "8515def.inc"This include the definition file for ATmega8515, so that we can directly address the registers with their names.All AVRs have 32 general purpose registers from R0 - R32.R0-R15 registers have certain restrictions of use, i.e. they are not allowed to load immediate value.e.g. LDI R15, $35the above statement will give you an error, saying "Invalid Register"Where as registers from R16-R32 can be used for this purpose i.e.LDI R16,$35 is a valid statement.You can move values from one register to other by usingMOV R15,R16Not 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.For the ease of programming, you can also give names to the register likeCODE:.def myregister = R16There 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.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:CODE:LDI YH,HIGH&#40;LABEL&#41; ; Set the MSB<br />LDI YL,LOW&#40;LABEL&#41; ; Set the LSBwhere LABEL is address for any lookup table or any memory location.Some important notes for using registers <br />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.If you need pointer access reserve R26 to R31 for that purpose.16-bit-counter are best located R25:R24.If you need to read from the program memory, e.g. fixed tables, reserve Z (R31:R30) and R0 for thatpurpose.If you plan to have access to single bits within certain registers (e.g. for testing flags), use R16 toR23 for that purposeNow 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..if you don't have an include file then you can define yourself as..CODE:.equ PORTA = $1B ;incase of ATmega8515So if you are not able to find an include file you can use the .EQU directive to define ports and other registers.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 writtenlogic one, Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configuredas an input pin.for writing and reading data to Ports, PORTx registers are there. and to read from ports PINx registers are there.for example..writing to portCODE:.def output = R16<br />LDI output, $FF<br />OUT DDRA, output ; making as o/p<br />LDI output, $00<br />OUT PORTA, output ; clear all PORTA pinsReading from portCODE:.def input = R17<br />LDI input, $00<br />OUT DDRA,input<br />IN input, PINAWe are finished with the basics of AVR, lets try programming with simplest program. Blinking an LED!CODE:.include "8515def.inc"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Include file<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; RJMP MAIN&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Reset vector<br /><br />MAIN:<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi R16,low&#40;RAMEND&#41;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;Load stack with<br />&nbsp; &nbsp; &nbsp; &nbsp; out SPL,R16&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;RAMEND - highest value<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi R16,high&#40;RAMEND&#41;&nbsp; &nbsp; ;of internal SRAM<br />&nbsp; &nbsp; &nbsp; &nbsp; out SPH,R16<br />&nbsp; &nbsp; &nbsp; &nbsp; SBI DDRA,0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Make PORTA Pin 0 as o/p<br /><br />DO:<br />&nbsp; &nbsp; &nbsp; &nbsp; SBI PORTA,0&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Set Pin 0 of PORTA<br />&nbsp; &nbsp; &nbsp; &nbsp; RCALL DELAY&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Wait for some time<br />&nbsp; &nbsp; &nbsp; &nbsp; CBI PORTA,0&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Cleare Pin 0 of PORTA<br />&nbsp; &nbsp; &nbsp; &nbsp; RCALL DELAY&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Wait for some time<br />&nbsp; &nbsp; &nbsp; &nbsp; RJMP DO&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Forever loop!<br /><br />DELAY:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;The delay routine<br />&nbsp; &nbsp; &nbsp; &nbsp; LDI R16,$20&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load some delay value<br />LOOP1:<br />&nbsp; &nbsp; &nbsp; &nbsp; SER R17&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Make R17 as $FF<br />LOOP:<br />&nbsp; &nbsp; &nbsp; &nbsp; DEC R17&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Decrement R17<br />&nbsp; &nbsp; &nbsp; &nbsp; BRNE LOOP&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Jump if not zero<br />&nbsp; &nbsp; &nbsp; &nbsp; DEC R16&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Decrement R16<br />&nbsp; &nbsp; &nbsp; &nbsp; BRNE LOOP1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Jump if not zero<br />&nbsp; &nbsp; &nbsp; &nbsp; RET&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;ReturnPlease post your problems in the forum   Doubts in AVR tutorial</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>I hope you are now familiar with the register set of AVR and instructions that deals with these registers.So let move on to our next step of the tutorial. I named it as "Dealing with load and store instructions of AVR"Lets learn AVR Tutorial - Step 3In this part of tutorial you will learn<br />Reading from Program memoryReading from RAMWriting to RAMPractice programsHere is the summary of Load and store instructions that are used for dealing with SRAM of AVR Microcontroller<br />LD Rn,X/Y/Z>either X or Y or Z register can be used>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)LD Rn,X+/Y+/Z+>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>This is a post increment instructionLD Rn, -X/-Y/-Z>Load Rn with value stored at location pointed by pre-decrement of address stored in X/Y/ZLDD Rn,Y/Z+displacement >Load Rn with value at address Z or Y + displacement>e.g. Z is 0x0090, Displacement is 0x10 so Rn will be loaded with value stored at 0x0090+0x10 = 0x0100ST X/Y/Z, Rn>Store the value of Rn to location pointed by X or Y or ZST X+/Y+/Z+, Rn>Store the value in Rn to location pointed by X or Y or Z and increment the address pointerSTD Y/Z+displacement, Rn>Store the value in Rn to location pointed by Y or Z + DisplacementLDS Rn, SRAM_Address>Load value from SRAM Address to the Rn register>SRAM Address is the immediate value e.g. LDS R0,0x0100STS SRAM_Address, Rn>Store Rn to immediate SRAM locationTo read from Program memory we have special instructions like<br />LPM>Load form program memory, This instruction is used in most of the AVRs and its hard coded in the architecture.>This instruction will load R0 with the address specified by register Z [This is hardcoded]LPM Rn, Z>Load Rn from program memory pointed by register Z>This instruction is not supported by all AVRs e.g ATMega8515, AT90S8515LPM Rn,Z+>Load Rn from program memory and increment the memory location pointed by Z>This instruction is also not supported by all AVRsNote: 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.Now we are done with the instructions overview.. now lets practice them.. Program 1: Copy 10 Bytes memory block stored in Program memory(ROM) to Data memory (SRAM)CODE:;This program is to copy memory block from Program<br />;memory to AVR RAM (10 Bytes)<br /><br />.include "8515def.inc"<br /><br />.org $0<br />.def Temp = R0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Temprary variable<br />.def count = R17&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Byte Count<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH,HIGH&#40;2*data&#41;&nbsp; &nbsp; &nbsp;;Load Z with address where<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL,LOW&#40;2*data&#41;&nbsp; &nbsp; &nbsp; ;our data is stored<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi XL,$60&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load Destination RAM location<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi XH,$0<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi count,$A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load count 10 Bytes<br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; lpm&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load value from program memory<br />&nbsp; &nbsp; &nbsp; &nbsp; inc ZL&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Increment memory location<br />&nbsp; &nbsp; &nbsp; &nbsp; st X+,Temp&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Store byte to the RAM location<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Decrement Count<br />&nbsp; &nbsp; &nbsp; &nbsp; brne again&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Check if all bytes moved<br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;End of program<br /><br />;Our data which we will copy from Program Memory to RAM<br />Data:<br />.db $10,$20,$30,$40,$50,$60,$70,$80,$90,$95 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)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. Program 1: Find Greatest of 3 numbers Stored in program memory CODE:;Program to find greatest of 3 numbers<br />;<br />;numbers are stored in ROM and the final<br />;result will be stored in a register<br /><br />.include "8515def.inc"<br /><br />.def num1 = r0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Location for First number<br />.def num2 = r1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Location for second number<br />.def answer = R2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;location for Final answer<br /><br />.org $0<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL, Low&#40;2*Data&#41;&nbsp; &nbsp; &nbsp;;Load the program memory address<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH, High&#40;2*data&#41;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; lpm&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load first number<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num2,num1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;Move it to num2<br />&nbsp; &nbsp; &nbsp; &nbsp; inc ZL&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Increment the address<br />&nbsp; &nbsp; &nbsp; &nbsp; lpm&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load second number<br />&nbsp; &nbsp; &nbsp; &nbsp; cp num1,num2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Compare them<br />&nbsp; &nbsp; &nbsp; &nbsp; brlt next&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Jump if num1&lt;num2<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num2,num1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;If num1>num2 then move num1<br />next:&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; to num2 location<br />&nbsp; &nbsp; &nbsp; &nbsp; inc ZL&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Increment the address<br />&nbsp; &nbsp; &nbsp; &nbsp; lpm&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load the third number<br />&nbsp; &nbsp; &nbsp; &nbsp; cp num1,num2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Again compare<br />&nbsp; &nbsp; &nbsp; &nbsp; brlt final&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Check if num1&lt;num2<br />&nbsp; &nbsp; &nbsp; &nbsp; mov answer,num1&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;If No, then num1 is answer<br />final:<br />&nbsp; &nbsp; &nbsp; &nbsp; mov answer,num2&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;If Yes, then num2 is our answer<br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;End of program<br /><br /><br />Data:&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Our 3 numbers<br />.db $23,$23,$14&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Try changing them and see results Now you can try yourself writing some programs to make yourself more easy with load and store operations.Here is the list of programs you can try out:<br />Swap two numbers stored in RAMFind Greatest of 5 numbersCopy memory block from RAM to RAMSorting of 10 numbersClear SRAM area from 0x60 to RAMEND *Happy programming with your AVR*Any Doubts? Post here...  Doubts in AVR Tutorial - Step 3</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>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..So here are the programs.. Please take a look!Swap two numbers stored in RAMCODE:;Program to swap two numbers<br /><br />.include "8515def.inc"<br /><br />.def temp = R16 ;Temporary register<br />.def num1 = R17 ;Number one location<br />.def num2 = R18 ;Location for second number<br /><br />.cseg<br />.org $0<br /><br />ldi ZH,0x00 &nbsp; &nbsp; ;Assuming the two numbers are stored<br />ldi ZL,0x90 &nbsp; &nbsp; ;at location 0x0090 in RAM<br />ld num1,Z+ &nbsp; &nbsp; &nbsp;;Load first number<br />ld num2,Z &nbsp; &nbsp; &nbsp; ;Load second number<br />mov temp,num1 &nbsp; ;copy num1 to temp<br />mov num1,num2 &nbsp; ;copy num2 to num1<br />mov num2,temp &nbsp; ;copy temp to num2<br />ldi ZL,0x90 &nbsp; &nbsp; ;load the RAM location back<br />st Z+,num1 &nbsp; &nbsp; &nbsp;;store the first number<br />st Z, num2 &nbsp; &nbsp; &nbsp;;store the second number<br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end &nbsp; &nbsp;;end of progFind Greatest of 5 numbersCODE:;Program to find greatest of 5 numbers<br />;<br />;numbers are stored in ROM and the final<br />;result will be stored in a register<br /><br />.include "8515def.inc"<br /><br />.def num1 = r0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Location for First number<br />.def num2 = r1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Location for second number<br />.def answer = R2 &nbsp; &nbsp; &nbsp; &nbsp;;location for Final answer<br />.def count = r16 &nbsp; &nbsp; &nbsp; &nbsp;;Count<br /><br />.org $0<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL, Low&#40;2*Data&#41; ;Load the program memory address<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH, High&#40;2*data&#41;<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi count,4 &nbsp; &nbsp; &nbsp; &nbsp; ;Load count<br />&nbsp; &nbsp; &nbsp; &nbsp; lpm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load first number<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num2,num1 &nbsp; &nbsp; &nbsp; ;Move it to num2<br />&nbsp; &nbsp; &nbsp; &nbsp; adiw Z,1<br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; lpm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load second number<br />&nbsp; &nbsp; &nbsp; &nbsp; cp num1,num2 &nbsp; &nbsp; &nbsp; &nbsp;;Compare them<br />&nbsp; &nbsp; &nbsp; &nbsp; brlt next &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Jump if num1&lt;num2<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num2,num1 &nbsp; &nbsp; &nbsp; ;If num1>num2 then move num1<br />next: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; to num2 location<br />&nbsp; &nbsp; &nbsp; &nbsp; adiw Z,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Increment the address<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;are we done with all 5 numbers?<br />&nbsp; &nbsp; &nbsp; &nbsp; brne again &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;if no then jump back<br />final:<br />&nbsp; &nbsp; &nbsp; &nbsp; mov answer,num2 &nbsp; &nbsp; ;If Yes, then num2 is our answer<br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;End of program<br /><br />;Try changing them and see results<br />Data: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Our 5 numbers<br />.db $3,$23,$14,$50,$20,$0<br />;last zero is to aligh the bytes in word manner<br />;we have 5 numbers so i am padding with a 0 to make it<br />;even. if we dont't do this.. compiler will do it<br />;automatically to prevent misalignment.Copy memory block from RAM to RAMCODE:;Program to copy a block of memory (10 Bytes)<br />; from one RAM location to another RAM location.<br /><br />.include "8515def.inc"<br /><br />.def temp = r0<br />.def count = r16<br /><br />.org 0<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL,0x60 &nbsp; ;Lets fill the RAM with some numbers<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH,0x00 &nbsp; ;to copy, so we can check is it working<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi count,10 &nbsp;;Load count<br />fill:<br />&nbsp; &nbsp; &nbsp; &nbsp; st Z+,count &nbsp; ;Store value to RAM location<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count<br />&nbsp; &nbsp; &nbsp; &nbsp; brne fill<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL,0x60 &nbsp; ;Load memory location to copy from<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH,0x00<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi YL,0x90 &nbsp; ;Load destination memory location<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi YH,0x00<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi count,10 &nbsp;;Load count<br /><br />copy:<br />&nbsp; &nbsp; &nbsp; &nbsp; ld temp,Z+ &nbsp; &nbsp;;Load value to temporary register<br />&nbsp; &nbsp; &nbsp; &nbsp; st Y+,temp &nbsp; &nbsp;;Store it to location<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count &nbsp; &nbsp; ;decrement counter<br />&nbsp; &nbsp; &nbsp; &nbsp; brne copy<br /><br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end &nbsp; &nbsp; &nbsp;;End of program...Sorting of 10 numbers CODE:;Program to sort 10 numbers <br />;in ascending order<br />;10 numbers are stored in ROM<br />;and sorted answer is stored in RAM<br />;at location 0x0060<br /><br />.include "8515def.inc"<br /><br />.def count1 = r17 &nbsp; &nbsp; ;First Count<br />.def count2 = r18 &nbsp; &nbsp; ;Second count<br />.def temp = r0 &nbsp; &nbsp; &nbsp; &nbsp;;Temp reg for swap<br />.def num1 = r1 &nbsp; &nbsp; &nbsp; &nbsp;;Num 1<br />.def num2 = r2 &nbsp; &nbsp; &nbsp; &nbsp;;Num 2<br /><br />.cseg &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Code segment starts<br />.org 0<br />ldi Zh,high&#40;2*mydata&#41; ;Load memory add where<br />ldi Zl,low&#40;2*mydata&#41; &nbsp;;data is stored in ROM<br />ldi Yh,0x00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Destination location<br />ldi Yl,0x60 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;0x0060 in RAM<br />ldi count1,10 &nbsp; &nbsp; &nbsp; &nbsp; ;Load count<br /><br />copy:<br />lpm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load from program mem<br />st Y+,temp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Store it to RAM<br />adiw Z,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Increment Z<br />dec count1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Decrement counter<br />brne copy &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;copy all 10 bytes<br /><br />ldi ZH,0x00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;Load first pointer<br />ldi ZL,0x60<br />ldi count1,10 &nbsp; &nbsp; &nbsp; &nbsp; ;Load counter for it<br /><br />sort:<br />&nbsp; &nbsp; &nbsp; &nbsp; mov YL,ZL &nbsp; &nbsp; &nbsp; &nbsp; ;Load second pointer<br />&nbsp; &nbsp; &nbsp; &nbsp; mov YH,ZH<br />&nbsp; &nbsp; &nbsp; &nbsp; adiw Y,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Increment it<br />&nbsp; &nbsp; &nbsp; &nbsp; ld num1,Z &nbsp; &nbsp; &nbsp; &nbsp; ;load first number<br />&nbsp; &nbsp; &nbsp; &nbsp; mov count2,count1 ;load count2<br />&nbsp; &nbsp; &nbsp; &nbsp; subi count2,1 &nbsp; &nbsp; ;Count2 = Count1-1<br />&nbsp; &nbsp; &nbsp; &nbsp; breq end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;end if last num<br /><br />again:<br />&nbsp; &nbsp; &nbsp; &nbsp; ld num2,Y &nbsp; &nbsp; &nbsp; &nbsp; ;Load second number<br />&nbsp; &nbsp; &nbsp; &nbsp; cp num1,num2 &nbsp; &nbsp; &nbsp;;Compare them<br />&nbsp; &nbsp; &nbsp; &nbsp; brlo next &nbsp; &nbsp; &nbsp; &nbsp; ;Jump if num1&lt;num2<br />&nbsp; &nbsp; &nbsp; &nbsp; mov temp,num2<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num2,num1 &nbsp; &nbsp; ;If num1>num2 then swap<br />&nbsp; &nbsp; &nbsp; &nbsp; mov num1,temp<br />&nbsp; &nbsp; &nbsp; &nbsp; st Z,num1 &nbsp; &nbsp; &nbsp; &nbsp; ;and store them on their<br />&nbsp; &nbsp; &nbsp; &nbsp; st Y,num2 &nbsp; &nbsp; &nbsp; &nbsp; ;respective locations<br />next: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; adiw Y,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Increment the address<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count2 &nbsp; &nbsp; &nbsp; &nbsp;;dec count2 for Y pointer<br />&nbsp; &nbsp; &nbsp; &nbsp; brne again &nbsp; &nbsp; &nbsp; &nbsp;;check if count is zero<br />&nbsp; &nbsp; &nbsp; &nbsp; adiw Z,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;increment Z pointer<br />&nbsp; &nbsp; &nbsp; &nbsp; dec count1 &nbsp; &nbsp; &nbsp; &nbsp;;Dec count1 for Z pointer<br />&nbsp; &nbsp; &nbsp; &nbsp; brne sort &nbsp; &nbsp; &nbsp; &nbsp; ;finish if zero<br /><br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;End of program<br /><br />mydata:<br />.db $10,$90,$50,$20,$91,$23,$55,$62,$39,$80Clear SRAM area from 0x60 to RAMENDCODE:;Program to clear RAM<br />;this program is for ATMega8515 So ram area is from<br />;0x60 to RAMEND<br /><br />.include "8515def.inc"<br /><br />.def temp = r16 &nbsp; &nbsp; &nbsp;;Temporary variable<br />.def cnth = r25 &nbsp; &nbsp; &nbsp;;Counter High byte<br />.def cntl = r24 &nbsp; &nbsp; &nbsp;;Counter Low byte<br /><br />.org 0<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; ldi cnth,0x02 &nbsp; &nbsp;;Load count 0x200 to clear<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi cntl,0x00 &nbsp; &nbsp;;memory from 0x00 to 0x1FF<br />&nbsp; &nbsp; &nbsp; &nbsp; clr temp &nbsp; &nbsp; &nbsp; &nbsp; ;clear temp<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZH,0x00 &nbsp; &nbsp; &nbsp;;Load starting address of<br />&nbsp; &nbsp; &nbsp; &nbsp; ldi ZL,0x60 &nbsp; &nbsp; &nbsp;;RAM 0x0060 in Z pointer<br /><br />clrram:<br />&nbsp; &nbsp; &nbsp; &nbsp; st Z+,temp &nbsp; &nbsp; &nbsp; ;Store 0 in current Z location<br />&nbsp; &nbsp; &nbsp; &nbsp; sbiw cnth:cntl,1 ;Decrement the counter<br />&nbsp; &nbsp; &nbsp; &nbsp; brne clrram &nbsp; &nbsp; &nbsp;;end if zero<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />end:<br />&nbsp; &nbsp; &nbsp; &nbsp; rjmp end &nbsp; &nbsp; &nbsp; &nbsp; ;End of program</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>Interfacing Keypad with AVR microcontrollerKeypad TutorialLearn to interface a 4x4 matrix keypad with AVR microcontroller.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t1701.html">
						<title>Re: Lets Learn AVR - Step by step tutorial</title>
						<link>http://www.8051projects.net/forum-t1701.html</link>
						<dc:date>2008-10-07T12:30:15-07:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>AVR Serial Programming TutorialAVR UART ProgrammingLearn to program AVR in C as well as assembly for serial Programming or UART programming.Interfacing ADC with AVRADC0804 interfacing tutorialInterface an 8-bit ADC (ADC0804) with AVR microcontroller.</description>
						</item>
				</rdf:RDF>