CREATING THE FIRST PROJECT IN
mikroC PRO for AVR
2
Project
The mikroC PRO for AVR organizes applications into projects consisting of a single proj-
ect file (file with the .mcpav extension) and one or more source files (files with the .c
extension). The mikroC PRO for AVR IDE allows you to manage several projects at a
time. Source files can be compiled only if they are part of the project.
A project file contains:
Project name and optional description;
Target device in use;
Device clock;
List of the project source files;
Header files (*.h);
Binary files (*.mcl);
Image files; and
Other files.
In this reference guide, we will create a new project, write code, compile it with the mikroC
PRO for AVR and test the results. The purpose of this example is to make LED diodes on
the microcontroller PORTA blink, which will be easy to test on AVR microcontrollers.
3
Hardware Connection
For the purpose of testing this example on an AVR microcontroller, it is necessary to connect
hardware as per schematic below. LED diodes are connected to PORTA only. However, you
can use any other port because this simple program will change the state of all ports in the
same way.
Prior to creating a new project, it is necessary to do the following:
Step 1: Install the compiler
Install the mikroC PRO for AVR compiler from the product CD,
CD:\zip\mikroc_pro_avr\mikroc_pro_avr_setup.exe. Desktop shortcut and start menu
shortcut will be automatically created.
Step 2: Start up the compiler
Start up the mikroC PRO for AVR compiler by double clicking the appropriate icon. The mikroC
PRO for AVR IDE (Integrated Development Environment) will appear on the screen.
After these two steps you are ready to create a new project.
4
New Project
The process of creating a new project is very simple. Select the New
Project option from the Project menu as shown in Figure on the left.
The New Project Wizard window appears. It can also be opened by
clicking the New Project icon from the Project toolbar.
Click here to start a new project
The New Project Wizard window
will guide you through the process
of creating a new project. The
introductory window of this appli-
cation contains a list of actions to
be performed when creating a
new project. Click Next.
Step 1:
From the Device Name drop-
down list, select the microcon-
troller you want to write a program
for.
5
Step 2:
Enter the oscillator frequency
value in the Device Clock field.
Step 3:
Specify the name and location of
the project.
Step 4:
In the event that the project con-
sists of several source files, it is
necessary to specify them all and
include into the project by clicking
the Add button. It is also possible
to add files later in the Project
Manager window.
6
Step 5:
Choose between whether to
include all libraries into the project
or not.
Step 6:
After all, it is necessary to confirm
all selected options by clicking
Finish.
After creating the project, a new
blank window to write a program in
will appear. See Figure on the left.
If you use New Project Wizard when
creating a new project, a blank
source file, named after the project
with the .c extension, will automati-
cally be created. The mikroC PRO
for AVR does not require you to
have a source file named the same
as the project, it’s just a matter of
convenience.
7
This is the source code that is to make all microcontroller’s I/O pins to change their logic
state once per second. Any change of the microcontroller's port state can be seen on LEDs.
8
Compilation
When the program is written, it is necessary to compile it into a program (.hex) code, by
selecting one of the build options from the Project menu:
To create a HEX file, select Build (Ctrl+F9) from the Project menu or click the Build
icon from the Project toolbar.
The Build All Projects (Shift+F9) option builds all files within the project, libraries (if
there is a source code for them) and def files for the chip in use.
The Build + Program (Ctrl+F11) option is special as it enables the mikroC PRO for
AVR compiler to automatically load the program into the microcontroller after compi-
lation. The process of programming is performed by using the AVRflash programmer.
All the errors detected during compilation will be shown in the Messages window. If no
errors are encountered, the mikroC PRO for AVR compiler will generate output files.
Output Files
The mikroC PRO for AVR compiler generates output files in the project folder containing
the project file. Output files are summarized in the table below:
Format Description File Type
Intel hex style records. It is used for programming AVR
Intel HEX .hex
microcontrollers.
Binary Compiled Library which may be included in other projects. .mcl
Assembler File Assembly file with symbolic names. .asm
Overview of AVR memory allotment. The List File represents an
List File extended version of assembly code, i.e. contains addresses of .lst
instructions, registers, routines and labels.
Assembly Code Overview
After compilation, click the View Assembly icon or select the View Assembly option
from the Project menu to review the generated assembly code in a new window. To
overview the complete List File, select the View Listing option from the same menu.
9
Project Settings
Edit Project
By selecting the Project Settings option from the View menu, a new window providing
possibility to change type and clock frequency of the microcontroller, appears. Any change
in this window affects only the currently active project. If more than one project is open,
make sure that the right project is set as active one in the Project Manager.
Project Group
As mentioned before, the mikroC PRO for AVR IDE enables several projects to be
opened simultaneously. If there are several projects related to each other in some way,
it is possible to create a project group.
The project group may be saved by clicking the Save Project Group icon in the Project
Manager window. It may also be reopened by clicking the Open Project Group icon in
the same window. All relevant data about the project group is stored in the project group
file (file with the .mcavgroup extension).
Add/Remove Files from Project
A project may contain the following types of files:
.c source files;
.h header files;
.mcl binary files;
.pld project level defines files;
image files;
.hex, .asm and .lst files. These files cannot be added
or removed from the project; and
other files.
To add a file to the project, click the Add File to Project option from the Project menu
or click the Add File to Project icon from the Project toolbar. Each added file must be
self-contained, i.e. must have all definitions after preprocessing.
To remove file(s) from the project, click the Remove File from Project option from the
Project menu or click the Remove File from Project icon from the Project toolbar.
10
Source Files
Creating a new source file
In order to create a new source file, it is necessary to select the New Unit option from
the File menu, or press CTRL+N or click the New File icon from the File toolbar. A new
window, i.e. a new source file automatically appears. Select the Save option from the File
menu, or press CTRL+S or click the Save File icon from the File toolbar and name it as
you want.
Opening an existing file
In order to open a saved file, it is necessary to select the Open option from the File
menu, or press CTRL+O or click the Open File icon from the File toolbar. In the Open dia-
log box, browse the location of the file that you want to open, select it and click the Open
button.
The file will be automatically displayed in its own window. If such file is already open, it
becomes active.
Printing an active file
First of all, it is necessary to make sure that the file you want to print is active. Select the
Print option from the File menu or press CTRL+P and click the OK button.
In the Print Preview window, set a desired layout of the document and click the Print
icon.
11
Saving file
Make sure that the file you want to save is active.
In order to save it, it is necessary to select the Save option from the File menu, or press
Ctrl+S, or click the Save File icon from the File toolbar.
Saving file under different name
Make sure that the file you want to save is active.
In order to save it under different name, it is necessary to select the Save As option from
the File menu. The Save As dialog box will appear. Here you can browse the folder in
which you want to save the file.
In the File Name field, modify the name of the file you want to save and click the Save
button.
Closing file
Make sure that the file you want to close is active.
In order to close it, it is necessary to select the Close option from the File menu, or right
click the window of the file you want to close and select the Close option. If the file has
been changed since it was last saved, you will be prompted to save the changes.
Clean Project Folder
The Clean Project Folder option from the
Project menu gives you a possibility to
choose the files that you want to delete
from your current project.
Select the files you want to delete from the
project and click the Clean button. The
selected files will be permanently deleted.
Please note that only files in bold are gen-
erated by the compiler and can be recreat-
ed after the process of compilation.
If you want to learn more about our products, please visit our website: www.mikroe.com
If you are experiencing some problems with any of our products or just need additional information, please place
your ticket at: www.mikroe.com/en/support
If you have any question, comment or business proposal, do not hesitate to contact us: office@mikroe.com