1st Project 8051 C v100
1st Project 8051 C v100
1st Project 8051 C v100
Project
The mikroC for 8051 organizes applications into projects consisting of a single project
file (extension .mcproj) and one or more source files (extension .c). MikroC for 8051 IDE
allows you to manage multiple projects (see Project Manager). Source files can be com-
piled only if they are part of a project.
Note that the project doesnt include files in the same way as preprocessor does. For
more inormation, see Add/Remove Files from Project.
3
In this simple project demonstration, we will create a new project, write some code, compile
it with mikroC for 8051 and test the results. Our example will make LED diodes blink so it
can be easily tested on the 8051 microcontrollers.
Hardware Connection
You will need the the connection scheme shown above to test the code for the 8051 micro-
controller. LED diodes are connected to Port P0. In this example you can use any other port
because this simple program will change the state of all ports in the same way. Prior to start,
you have to go through the three basic steps:
This is the source code that will make all microcontrollers I/O pins to change their logic
state every second. Since LED are conected to the Port P0, they will blink at the same
rate.
8
Compilation
When you have created the project and have written the source code, it's time to com-
pile it. Select Project Build from the drop-down menu or click the Build Icon from the
Project Toolbar. If more than one project is opened you can compile all open projects
by selecting Project Build All from the drop-down menu, or click the Build All Icon
from the Project Toolbar.
If there are some errors, you will be notified in the Message Window. If no errors are
encountered, the mikroC for 8051 will generate output files.
Output Files
Upon successful compilation, the mikroC for 8051 will generate output files in the proj-
ect folder (folder which contains the project file .mcproj). Output files are summarized in
the table below:
Assembly View
After compiling the program in the mikroC for 8051, you can click the View Assembly
icon or select Project View Assembly from the drop-down menu to review the gener-
ated assembly code (.asm file) in a new tab window. Assembly language uses simbolic
names and is much easier to understand, therefore.
9
Customizing Projects
Edit Project
You can change basic project settings such as type of chip, oscillator frequency and mem-
ory model in the Project Settings window. Any change in the Project Setting window affects
only currently active project which means that if more than one project is opened, you have
to ensure that the right project is set as active one in the Project Manager.
The mikroC for 8051 IDE provides a convenient option which enables several projects to
be opened simultaneously. If you have several projects being related in some way, you
can 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 reopend by clicking the Open Project Group icon. All rel-
evant data about the project group is stored in the project group file (extension .mpgroup).
.c source files;
.h header files;
.mcl binary files;
.pld project level defines files (future upgrade);
image files;
.hex, .asm and .lst files, see output files. These files
cannot be added or removed from project; and
other files.
The list of relevant source files is stored in the project file (extension .mcproj).
To add source file to the project, click the Add File to Project icon. Each added source
file must be self-contained, i.e. must have all necessary definitions after preprocessing.
To remove file(s) from the project, click the Remove File from Project icon.
Note
To include the header files (extension .h), use the preprocessor directive #include. See
File Inclusion for more information.
10
Source Files
Source files containing C code should have extension .c. The list of source files relevant
to the application is stored in the project file with extension .mcproj, along with other proj-
ect information. You can compile source files only if they are part of the project.
Select File New Unit from the drop-down menu, or press CTRL+N, or click the New File
icon from File Toolbar.
A new tab will be opened. It is a new source file. Select File Save from the drop-down
menu, or press CTRL+S, or click the Save File icon from File Toolbar and name it as you
want.
If you use New Project Wizard, an empty source file, named after the project with exten-
sion .c, will be created automatically. The mikroC 8051 doesnt require you to have a
source file named the same as the project, its just a matter of convenience.
Select File Open from the drop-down menu, or press CTRL+O, or click the Open File
icon from the File Toolbar. In Open dialog browse to the location of the file that you want
to open, select it and click the Open button.
The selected file is displayed in its own tab. If the selected file is already opened, its cur-
rent Editor tab will become active.
Make sure that the window containing the file you want to print is an active window.
Select File Print from the drop-down menu or press CTRL+P.
In the Print Preview Window, set a desired layout of the document and click the OK but-
ton. The file will be printed on the selected printer.
Note
Use the preprocessor directive #include to include header files with extension .h. Do
not rely on the preprocessor to include source files other than headers. See
Add/Remove Files from Project for more information.
11
Saving file
Make sure that the window containing the file that you want to save is active.
Select File Save from the drop-down menu, or press Ctrl+S, or click the Save File icon
from File Toolbar.
Make sure that the window containing the file that you want to save is active.
Select File Save As from the drop-down menu. The New File Name dialog will be dis-
played.
In the dialog, browse to 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.
Click the Save button.
Closing file
Make sure that the tab containing the file that you want to close is the active tab.
Select File Close from the drop-down menu, or right click the tab of the file that you
want to close and select the Close option from menu.
If the file has been changed since it was last saved, you will be prompted to save your
changes.