Step 11Writing and Compiling AVR Code
First of all, download a copy of WinAVR - http://winavr.sourceforge.net/ or MacAVR http://www.harbaum.org/till/macavr/index.shtml
WinAVR is a suite of useful tools such as the compiler, code headers/libraries and more. Basically all you need to start programming and uploading your code.
Coding for AVRs is very simple. You simply write out your code using normal C, you can include standard libraries for sorting, string manipulation, maths and much more. You need to include the relevant AVR libraries such as the io, sleep, interrupt packages depending on what your code contains (the
Once the code is written, it must be compiled and linked. The easiest way to do this is using a makefile. The makefile does all the hard work for you, all you do is specify the name of your C files and any assembly files (must be called .S - case sensitive) and the processor you're using. This file goes in the same directory as your source code.
There is a good template here: http://electrons.psychogenic.com/modules/arms/art/8/AVRProjectOrganizationStandardizedAVRMakefileTemplate.php
I won't go through the process of writing a make file, the template above is commented and should be obvious :)
To actually compile your code into the .hex binary that your micro can understand, we just use the command prompt. Navigate to the directory you need using the "cd
I will try, if i can to give a run down of what the code does. It is pretty well commented in my opinion so should be fairly self explanatory for seasoned coders. The code we'll be using is fairly complicated and deals with a lot of things that newbies want to know, dealing with input and output, interfacing with a display, using the ADC and Timer interrupts, sleep modes and more. It was a great primer for me at any rate =D
Ok, lets go onto your first program and try to upload it!
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|

























































