Copyright © mikroElektronika, January 2012. All rights reserved.
TO OUR VALUED CUSTOMERS
I want to express my thanks to you for being interested in our products and for having
confidence in MikroElektronika.
The primary aim of our company is to design and produce high quality electronic products
and to constantly improve the performance thereof in order to better suit your needs.
Nebojsa Matic
General Manager
The Microchip name, logo and products names are trademarks of Microchip Technology in the U.S.A and other countries.
Page 2
Table of Contents
1. Introduction to mikroC PRO for PIC® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 04
2. Hardware Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 05
3. Creating a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 06
Step 1 - Project Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 07
Step 2 - Add files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 3 - Include Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Step 4 - Finishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Blank new project created . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4. Code Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5. Building the Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6. Changing Project Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
7. What’s next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Page 3
1. Introduction to mikroC PRO for PIC
®
mikroC PRO for PIC®
organizes applications
into projects consisting of a single project file
(file with the
.mcppi
extension) and one or
more source files (files with the .c extension).
The mikroC PRO for PIC® compiler 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;
• Binary files (*.mcl); and
• Other files.
In this reference guide, we will create a new
project, write code, compile it and test the
results. The purpose of this project is to make
microcontroller PORTB LEDs blink, which will
be easy to test.
03
05
07
02
01
06
04
08
01
Main Toolbar
02
Code Explorer
03
Project Settings
Page 4
04
Messages
05
Code Editor
06
Image Preview
07
Project Manger
08
Library Manager
2. Hardware Connection
Let’s make a simple “Hello world” example for the
selected microcontroller. First thing embedded
programmers usually write is a simple
LED blinking
program. So, let’s do that in a few simple lines of C
code.
LED blinking is just turning ON and OFF LEDs that
are connected to desired PORT pins. In order to see
the example in action, it is necessary to connect
the target microcontroller according to schematics
shown on
Figure 2-1.
In the project we are about
to write, we will use only
PORTB,
so you should
connect the LEDs to PORTB only.
C22
22pF
X2
8MHz SEC
MCLR-RE3
RA0
RA1
RA2
RA3
RA4
RA5
RE0
RE1
RE2
C21
22pF
VCC-MCU
VCC
GND
RA7
RA6
RC0
RC1
RC2
MCU
RD0
RD1
DIP 40
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
VCC
GND
RD7
RD6
RD5
RD4
RC7
RC6
RC5
RC4
RD3
RD2
Figure 2-1:
Hardware connection schematics
LD4
LED
LD0
LED
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
VCC-MCU
RB4
R5
4K7
RB0
LD1
LED
R1
4K7
LD5
LED
RB5
R6
4K7
RB1
R2
4K7
PIC18F45K22
LD6
LED
RB6
R7
4K7
LD2
LED
RB2
R3
4K7
LD7
LED
RB7
R8
4K7
LD3
LED
RB3
R4
4K7
Prior to creating a new project, it is necessary to do the following:
Step 1: Install the compiler
Install the mikroC PRO for PIC® compiler from the
Product DVD
or
download it from the MikroElektronika website:
http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
Step 2: Start up the compiler
Double click on the compiler icon in the Start menu, or on your desktop
to Start up the mikroC PRO for PIC® compiler. The mikroC PRO for PIC®
IDE (Integrated Development Environment) will appear on the screen.
Now you are ready to start creating a new project.
Page 5