Mikroc Pro For Avr: Creating The First Project in
Mikroc Pro For Avr: Creating The First Project in
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.
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.
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.
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.
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:
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).
.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
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.
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.
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
Closing file
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: [email protected]