Atmel Studio 6 or AS6 in short, is the latest IDE (Integrated Development Environment) by Atmel for their 8 bit and 32bit MCUs lines. AVR Studio 6 comes integrated with latest version of avr-gcc compiler. So the complete development environment can be installed with a single, easy to use installer.
The IDE Consist of a high end editor with flawless auto-complete feature. The editor is powered by proven Microsoft Visual Studio. The editor makes it easy to type and edit C source file with its auto complete feature. the user don’t have to “refer” to the reference manual often, as the editor itself shows the parameter requirements of functions, its return type and a short help on functions.
You can start Atmel Studio 6 by using its icon from the Windows® Desktop or the Start Menu.
Fig. 1 - AS6 Desktop Icon |
Fig. 2 - AS6 Startup Screen |
The First screen shown up after the AS6 has started is the Start Page. The start page helps you quickly create a new project or load your previous project without wasting much time.
Fig. 3 - AS6 Home Screen. |
To create a new project we select “New Project …” option from the Start Page. Please refer to Fig 3.
AS6 will show you the New Project Wizard as shown in the image below (Fig 4).
Step 1: From the project template area (Installed Templetes) select C/C++ as the project template.
Step 2: From the project type area select “C Executable Project” .
Step 3: After that fill out the project details at the bottom, like project name, its location on your PC etc. Finally Hit Ok.
Fig. 4 - New Project Page1 |
After the project detail window, comes the Device Selection Window. That let you choose the target MCU for your project. Here in our project we are using ATmega8 MCU so select that from the device list.
Step 1: Go to the search box and enter "ATmega8"
Step 2: Many chips whoes name begins with ATmega8 (like ATmega8515, ATmega8535 etc) are listed. Select ATmega8 (or whatever chip is present on your xBoard MINI)
Step 3: Click OK.
Fig. 5 - Device Selection. |
After we have completed the “New Project” wizard, we are presented with the AVR Studio 6 main window. So let us get introduced with the various parts of AVR Studio 6 window.
Fig. 6 - Main Parts of AS6. |
The image below shows the Solution Explorer. By default it is on the right hand side.
Fig. 7 - Solution Explorer |
The solution explorer helps us keep the project source files in an organized hierarchal way. In our project there is an main application code file that is the high level application program (say a line LCDTest.c). In this case the file is named LCDTest.c, it is placed in the root of project.
The high level application requires services from lower level codes like the Motor Library, ADC Library etc. All these library are kept in their own folders inside the lib folder.
All our library are deployed in two files namely libname.c and libname.h
The c file contains the actual implementation while the h file contains the prototypes.
Creating a Folder.
As you have seen above how we organize our project in an Hierarchical way now we will see how to actually do this.
Fig. 8 - Add a new folder. (Click to Enlarge ...) |
in almost all of your projects we will have the lib folder (which stands for library files). The library files have set of functions that makes our life easier. They provide functions to do common tasks. For example LCD Library provide all functions to use the built in LCD Module. It provides functions to clear the LCD, write text and numbers on in it and many other functions too!
eXtreme Electronics provide following library files with xBoard MINI.
In addition to these low level libraires we also provide some high level libraries that uses these low level libraries to provide high level functions. Following high level libraries are available.
To orgasise our project we create a folder for each library that we going to use in our project. For example if you plan to use the LCD library create a folder named "lcd" inside the "lib" folder.
Steps are as follows.
Fig. 9 - Add a new subfolder. (Click to Enlarge ...) |
Now when the folders are created in the project, its time to copy some files in the folder. The lcd library consists of following four files.
You can download all these files from here.
Extract all these files using utilities like WinZip or WinRAR
You have to copy all these four files to your project's "lib\lcd\" folder using Windows.
Fig. 10 - Your Project Folder |
Double click on your project folder (LCDTest in this case), to open it.
Inside that you will see
All this is shown below.
Fig. 11 - Locating Your "lib" folder |
Open the "lib" folder.
You will see all the sub folder you added to it using the solution explorer.
Since in this example we have created only one sub folder named "lcd" you will only find one folder. Double click to open it.
This folder will be empty.
Fig. 12 - Empty folder "lcd" |
Copy all the four files which makes up the LCD library to this folder.
Fig. 13 - Paste lcd library files |
Fig. 14 - All four files which makes up the lcd lib |
Once the support files are copied to the project folder (using My Computer) they must be added to the project. To add existing source files to project do the following.
Fig. 15 - Add Existing Item to AS6. |
It will open up the add existing item dialog, which will help you select files to add to the project. Open the lib folder. Inside you will see all the subfolders you created using the solution explorer.
Fig. 16 - Browse for the files to add. |
Since we have created only the lcd subfolder inside lib folder, we see only that. Open that folder to view the files for lcd library.
Fig. 17 - Open the lcd subfolder. |
Select all four files which are part of lcd library. And click Add.
Fig. 18 - Select all four files. |
Fig. 19 - Files added to project. |
You can double click a file in the solution explorer pane to load it into the main editor.
Fig. 20 - Editing a File |
A preprocessor symbol which often used as a global constant can be defined for a project using the project properties dialog.
To bring up the project properties dialog you can do any one of the following.
To define a new symbol do the following :-
Fig. 21 - Project Properties Dialog. |
Fig. 22 - Defining a new Symbol. |
NOTE: One symbol that must be defined in all project is the CPU clock frequency in Hz. This symbol is named F_CPU. Its value must be set according to the speed on which AVR MCU will be running. The xBoard MINI runs at 16MHz so we define F_CPU=16000000 in all your projects.
Building is the process of compiling(or assembling if file is in assembly language) various source files in the project and linking the output files (.o) to give a final executable hex file.
To build the project, select Build Solution from the Build menu. You can also use keyboard shortcut F7 to build the project.
Fig. 23 - Building the Solution |
If everything is setup correctly and your source files do not have any syntax error then you will get the following message.
It states the number of projects succeeded and the number of projects failed. Since we have only one project in our solution we should get something like this :-
Build succeeded. ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
Fig. 24 - Build Output |
Once the project is build successfully a hex file is generated. You can use any programmer to upload this hex file to your MCU. This hex file is generated inside the folder Debug which is inside the Project folder (LCDTest in our case) which is again inside the solution folder (LCDTest in our case).
How to transfer this hex file to the board is given in this tutorial.