|
You may get the development cycle of an embedded project
with the following sequence ...
- Write a small piece of code that does something, using an editor.
- Compile this little something, using gcc compiler.
- It does not? Well, correct the errors, compile again.
- It does not? One day it will, so …
- Download the code (binary) into the micro, at the target board, using AVRStudio.
- Is the code doing what you expect it to do?
- Well, correct the errors of your source code. This time, they are logical errors,
a bit harder to find.
- Compile again. It does not?
You ‘ve seen this story, ehh?
One day it will compile and it will do what you want.
Don’t really know how, but the powers of the universe will conspire
with you. You may tell your mum …
Now,
if your hardware was not ready you would have another layer of complexity,
another source of possible errors, usually more difficult to trace. In
that case you might have to re-design your hardware, which is much more
expensive than re-compiling, and of course, many times you would have
to wonder in which territory your problem lies. Thanks God, your hardware
is tested for this project.
OK then, let's give it a go! Are you ready for the first run?
Open AVRStudio and go AVRStudio4 => New Project => Project Type: AVR GCC,
Project Name: Test1, Yes, Create an initial file => Next => Debug Platform:
AVR Simulator, Device: ATmega8 => Finish.
Have
a look, right click on your Project's Tree => Edit Configuration Options.
In which tab are the gcc options? Have another look Build => Export
Makefile, save it in the working directory, right click on your project's
Other Files => Add Existing File and add the makefile you just exported.
This is the compiler's configuration file for this project, don't bother
for now. Have a good look at the I/O view, really neat huh?
Now, copy/paste the following to your test1.c and build !
int main(void) // start
{
while (1) // repeat nothing to infinity
{
}
}
There
is a strong possibility that you will get a warning, no worries. Look
at the output. Change something. Recompile. Now you are trapped, you are
going to do it thousands of times again ;-).
Another
thing you may want to see is View => Disassembler. This is the ATmega8
program memory and the assembly instructions that are going to be executed.
Your micro does not really understand C, we do.
You managed to compile right? Time to program the board!
Under
Tools => Program AVR you will find the utility for downloading code
to your board, try to connect to your programmer. Note that it should
be plugged in to your board cause it gets power from there, not to mention
your PC (I keep forgetting that). So, Tools => Program AVR => Connect
=> STK500 or AVRISP and Auto => Connect ... AVRISP for me on COM1.
Device
Tab => Device: ATmega8, Input HEX file is the test1.hex created in your
working folder. Have a look at the other tabs but don’t mess up
with the fuses unless you know what you are doing, you may lock your device
from further programming.
Just
hit the Program button in the Flash section. Look at the messages at the
bottom of the window, in a few seconds your micro is ready to run alone
with your new code. Well, not anything fancy for now, your micro just
loops for nothing, but it is running. Note that after the end of the programming
cycle your micro is reset by the programmer, meaning it starts to run
with the fresh code.
|