Professional Documents
Culture Documents
1st Project C Pro Pic PDF
1st Project C Pro Pic PDF
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
Page 3
01
06
02
07
03
05
04
08
01 Main Toolbar
04 Messages
07 Project Manger
02 Code Explorer
05 Code Editor
08 Library Manager
03 Project Settings
Page 4
06 Image Preview
2. Hardware Connection
MCLR-RE3
RB7
RA0
RB6
RA1
RB5
RA2
RB4
RA3
RB3
RA4
RB2
RA5
X2
8MHz SEC
RE0
RE1
RE2
C22
C21
22pF
22pF
VCC-MCU
VCC
GND
RA7
RA6
PIC18F45K22
Figure 2-1:
Hardware connection schematics
RB4
RB4
LD5
LED
RB3
RB2
RB5
LD0
LED
RB0
R1
4K7
R6
4K7
LD1
LED
RB1
R2
4K7
RB1
RB0
VCC-MCU
LD6
LED
RB6
RD7
LD7
LED
RD6
RD5
R5
4K7
RB5
RB0
GND
RB7
R7
4K7
R8
4K7
LD2
LED
RB2
LD3
LED
RB3
R3
4K7
R4
4K7
RD4
RC0
RC7
RC1
RC6
RC2
RB6
RB1
VCC
LD4
LED
RB7
RC5
MCU
RC4
RD0
RD3
RD1
RD2
DIP 40
Install the mikroC PRO for PIC compiler from the Product DVD or
download it from the MikroElektronika website:
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.
http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
Page 5
01
Page 6
Figure 3-2: You can specify project name, path, device and clock in the first step
Page 7
01
02
03
Figure 3-3: Change the destination folder using Browse For Folder dialog
Page 8
01
02
03
Figure 3-4: Enter project name and change device clock speed if necessary
Page 9
01
Page 10
01
Page 11
Step 4 - Finishing
After all configuration is done, final step
allows you to do just a bit more.
01 There is a check-box called Open Edit
Project window to set Configuration
bits at the final step. Edit Project is
a specialized window which allows you
to do all the necessary oscillator and
PLL settings, as well as to set other
configuration bits. We made sure that
everything is described in plain English,
so you will be able to do the settings
without having to open the datasheet.
Anyway, since we are only building a
simple application, we will leave it at
default configuration (HS oscillator with
PLL disabled). Therefore, leave the
checkbox unchecked.
01
02
Figure 3-7: Choose whether to open Edit Project window after dialog closes.
02 Click Finish.
Page 12
Page 13
4. Code Example
Time has come to do some coding. First thing
we need to do is to initialize the PORTB to act
as digital output. TRISB register, associated
with PORTB, is used to set whether each pin
acts as input or output.
// set PORTB to be digital output
TRISB = 0;
// Delay 1000 ms
Delay_ms(1000);
void main() {
// set PORTB to be digital output
TRISB = 0;
// Turn OFF LEDs on PORTB
LATB = 0;
while(1) {
// Toggle LEDs on PORTB
LATB = ~LATB;
// Delay 1000 ms
Delay_ms(1000);
Page 15
Figure 5-2: After the successful compilation and linking, the message window should look something like this
Page 16
01
02
04
03
7. Whats next?
More examples
mikroC PRO for PIC comes with over 150 examples which demonstrate a variety of
features. They represent the best starting point when developing a new project. You will
find projects written for mikroElektronika development boards, additional boards, internal
MCU modules and other examples. This way you always have a starting point, and dont
have to start from scratch. In most cases, you can combine different simple projects to
create a more complex one. For example, if you want to build a temperature datalogger, you
can combine temperature sensor example with MMC/SD example and do the job in much
less time. All projects are delivered with a working .HEX files, so you dont have to buy a
compiler license in order to test them. You can load them into your development board right
away without the need for building them.
Community
If you want to find answers to your questions on many interesting topics we invite you to visit
our forum at http://www.mikroe.com/forum and browse through more than 150 thousand
posts. You are likely to find just the right information for you.
On the other hand, if you want to download more free projects and libraries, or share your own
code, please visit the Libstock website http://www.libstock.com. With user profiles, you can
get to know other programmers, and subscribe to receive notifications on their code.
Page 18
DISCLAIMER
All the products owned by MikroElektronika are protected by copyright law and international copyright treaty. Therefore, this manual is to be treated as any other
copyright material. No part of this manual, including product and software described herein, may be reproduced, stored in a retrieval system, translated or transmitted in any form or by any means, without the prior written permission of MikroElektronika. The manual PDF edition can be printed for private or local use, but not for
distribution. Any modification of this manual is prohibited.
MikroElektronika provides this manual as is without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties or conditions
of merchantability or fitness for a particular purpose.
MikroElektronika shall assume no responsibility or liability for any errors, omissions and inaccuracies that may appear in this manual. In no event shall MikroElektronika,
its directors, officers, employees or distributors be liable for any indirect, specific, incidental or consequential damages (including damages for loss of business profits
and business information, business interruption or any other pecuniary loss) arising out of the use of this manual or product, even if MikroElektronika has been advised
of the possibility of such damages. MikroElektronika reserves the right to change information contained in this manual at any time without prior notice, if necessary.
HIGH RISK ACTIVITIES
The products of MikroElektronika are not fault tolerant nor designed, manufactured or intended for use or resale as on line control equipment in hazardous
environments requiring fail safe performance, such as in the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, direct life support machines or weapons systems in which the failure of Software could lead directly to death, personal injury or severe physical or environmental
damage (High Risk Activities). MikroElektronika and its suppliers specifically disclaim any expressed or implied warranty of fitness for High Risk Activities.
TRADEMARKS
The MikroElektronika name and logo, the MikroElektronika logo, mikroC, mikroBasic, mikroPascal, mikroProg, EasyPIC v7, EasyPIC PRO v7, BigPIC6 and
LV18F v6 are trademarks of MikroElektronika. All other trademarks mentioned herein are property of their respective companies.
All other product and corporate names appearing in this manual may or may not be registered trademarks or copyrights of their respective companies, and are only used
for identification or explanation and to the owners benefit, with no intent to infringe.
Copyright MikroElektronika, 2012, All Rights Reserved.
Page 19
Designed by
MikroElektronika,
January 2012.
Creating the rst project in
mikroC PRO for PIC ver. 1.00