Step 10: New source file

Picture of New source file
Creating source and header files is very easy. Simply right click on the project or project folder that you want your new file to be created within, and click New>Source File. In the window that appears look for the type of file that you want to create, type in a name for your new file and click Finish.

Please note that you Need a file called main.c somewhere in your project, this is because that is the file that the compiler starts with. The compiler will compile main.c and any source files included within it. For an simple example of what to put in main.c try using the source listing from this page (for attiny2313). I have used this example in the pictures on this step.

Now that you have finished the code we need to build it. What is build you ask? Building a project is the act of compiling all of the source code and creating a "compiled" result. For normal C programmers you would build an executable file (an EXE for windows users). Since we are putting data onto an AVR we are building a Flash image. Before you hit build you will not see any errors in your code. After hitting build you will see that some lines are underlined in red. These are called "Compile Errors" - these are bits of code that are incorrect, because the compiler cannot understand them or has a problem with them.

Note about source files (again for people from an Arduino IDE background): Now that we have moved on from a single source file it's time to get serious about organising our code. Doing so is not hard and it means that when you want to make your project do something else (like adding a button to your blinky light). In C, the language that we are now using, the way to make code is to organise it into groups of "utility" files. Say we want to know if a number is a prime, if a number is a Fibonacci number and if a number is a square. Now imagine that we want to use these new methods in both the Blinky Light project and the completely separate Fading Light project. If you wanted to do this in the Arduino IDE the only realistic way would to be copy and paste your methods (which is kind of hard work). Further more it kinda sucks because if I discover that my method isAFibonacciNumber actually has a bug, I have to copy and paste the fix to both projects. Wouldn't it be easier if you could write a function once and use it many times? Well you can, and it's easy... We use source files and header files. We might make a source file called NumberUtilities.c . Number Utilities would contain all of the number crunching methods we might want to use. Now if I want to use Number Utilities all I need to do is import it once. The great thing is that if I need to make a change, or a fix then I need only do so once. For more help with C and AVR you may want to hit google, an AVR forum or your library. Remember that there is a links section at the end of this instructable!.
ffinacio2 years ago
When I am trying to install AVR plugins, instead to load CDT Optional Features and corresponding Plugins, it is only installed AVR Eclipse Plugin. AVR Eclipse Plugin Services is not available.
Typing main.c file it is presented semantic errors for all registers and bit included in the blinky example.
I have used indigo and juno versions of eclipse .
I should like to have some comment from you.