Getting started with WinAVR(Your first program in C for AVR) This tutorial is taken from the book
MY EXPERIENCE IN PROGRAMMING AVR MICROCONTROLLER
IN C USING WINAVR/AVRGCC.
you can download it free from the files
section(FILE-AVRBOOK.RAR) of yahoo group-booksbybibinhttp://groups.yahoo.com/group/booksbybibin/
comments about this book on
www.booksbybibin.blogspot.com
1. First you download WinAVR fromwww.winavr.sourceforge.net
2. Install WinaVR2006 to C drive. Then you can see that your desktop has the following programs.
The main program we use is the programers Notepad. So let's start with first program.
3. Type your first program
#include<avr/io.h>
void delay_ms(unsigned char time_ms);
main()
{
DDRC=0xff;
DDRA=0xff;
DDRB=0xff;
DDRD=0xff;
while(1)
{
PORTC=0X00;
PORTA=0X00;
PORTB=0X00;
PORTD=0X00;
delay_ms(200);
PORTA=0Xff;
PORTB=0Xff;
PORTC=0Xff;
PORTD=0Xff;
delay_ms(200);
}
return(0);
}
void delay_ms(unsigned char time_ms)
{
unsigned short delay_count = F_CPU / 4000;
unsigned short cnt;
asm volatile ("\n"
"L_dl1%=:\n\t"
"mov %A0, %A2\n\t"
"mov %B0, %B2\n"
"L_dl2%=:\n\t"
"sbiw %A0, 1\n\t"
"brne L_dl2%=\n\t"
"dec %1\n\t" "brne L_dl1%=\n\t":"=&w" (cnt)
:"r"(time_ms), "r"((unsigned short) (delay_count))
);
}
Let's start with first program of blinking LED's on all ports
Open Programmer's Notepad and type the program in
Now save the contents in a folder named 'BLINK' (let's say)
4.Now make a makefile and store it in same folder
See how to make a makefile in this link
http://booksbybibin.14.forumer.com/viewtopic.php?p=4#4
5. Now compile the program
6. Go to Tool->Make.
> "make.exe" all
make.exe: *** No rule to make target `all'. Stop.
> Process Exit Code: 2
> Time Taken: 00:00
This error occur because the Makefile is not proper or Makefile is not in the directory.
7. Here is another error occuring
make.exe: *** No rule to make target `obj/main.o', needed by
`simple_op.elf'. Stop.
> Process Exit Code: 2
> Time Taken: 00:03
solution:edit the 'mfile' completely.
8. So after compiling the programm, next step is to download the program into the chip
Set the programmer as per schematic shown
http://booksbybibin.14.forumer.com/viewtopic.php?t=3
9. Now go to Tool- Program
See the program is compiled and downloaded into the chip.
If you are getting any error in programming see this link (Avrdude errors and troubleshooting)
10. Disconnect the Reset pin of microcontroller from the parallel port and connect RESET to 5V. Connect an LED to the pins(PA0,PC1 etc..), you can see the LED is blinking(other end of LED is connected to ground through a 150 ohm resistor)
11.What you had done in first program??
See the datasheet what DDRA and PORTA represents. DDR determine the direction of the specific pin and PORT register have the value which should be sent to the port. So here we had written a program to blink LED's on all ports A,B,C,D. Next step is to program the chip. So we had to use a programmer to load the program into the microcontroller's flash. Here we are using BSD programmer with AVRDUDE software as we have set in Makefile. If you are using a different programmer, then you have to
change the programmer options.
Bibin John
www.bibinjohn.tk
Richard Principal- 07-18-2006
Hi there seems to be a error when I click on to
First you download WinAVR from < u r l > www.winavr.sourceforge.net
Of course it could be at
http://winavr.sourceforge.net/
Also the link to step number 5 is missing.
SO WHAT IS STEP NUMBER FIVE ANYWAY, DOES THE PICTURE ADD ANYTHING?
yogi- 07-19-2006
k, i will make it proper, some probs with image hosting
Richard Principal- 09-15-2006
go on be a devil
Tell us what step number 5 is
nevada- 12-23-2006
Re: Getting started with WinAVR(Your first program in C for
7. Here is another error occuring
make.exe: *** No rule to make target `obj/main.o', needed by
`simple_op.elf'. Stop.
> Process Exit Code: 2
> Time Taken: 00:03
solution:edit the 'mfile' completely.
How do i 'edit the mfile completely'?
Using the same programmer that you recommended along with atmega 16.
Thanks
yogi- 12-25-2006
use mfile editor to make the makefile. Use the sample files given in the book.
winnerslose- 10-13-2008
I am getting this error :
C:\DOCUME~1\SB\LOCALS~1\Temp/cc3s4zqW.s: Assembler messages:
C:\DOCUME~1\SB\LOCALS~1\Temp/cc3s4zqW.s:56: Error: unknown opcode `ntmov'
C:\DOCUME~1\SB\LOCALS~1\Temp/cc3s4zqW.s:75: Error: unknown opcode `ntmov'
C:\DOCUME~1\SB\LOCALS~1\Temp/cc3s4zqW.s:97: Error: unknown opcode `ntmov'
make.exe: *** Error 1
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.