Professional Documents
Culture Documents
In this simple tutorial, we will create a new project, write some code and compile it
in mikroC for PIC and test the results. Our project will make LED diodes blink, so
it can be easily tested on PIC microcontrollers.
10K
RA2 RB4
RA3 RB3
RA4 RB2
PICxxxx
RA5 RB1
1K LD7
RE0 RB0
Reset
VCC
RE1 VDD 1K LD6
RE2 VSS
VDD RD7 1K LD5
VSS RD6
OSC1 RD5
1K LD4
X1 OSC2 RD4
8MHz 1K LD3
RC0 RC7
C1 C2
22pF 22pF RC1 RC6 1K LD2
RC2 RC5
RC3 RC4
1K LD1
RD0 RD3
1K LD0
RD1 RD2
New Project.
page
2 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD
Creating first project in mikroC for PIC
Step 4: Set up your project
Project Wizard dialog will appear - fill the dialog with appropriate settings for your project:
page
3
MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple...
Creating first project in mikroC for PIC
Led blinking for mikroC for PIC:
Here is the code that will make LED’s on PORTB blink every second. Type it in the Code Editor (if
there is any default code you can over write it):
File: ProjName.c
Page: 1 od 1
void main() {
PORTB = 0;
TRISB = 0; // Configure pins of PORTB as output
while(1) { // Beginning of a repeat loop
PORTB = ~PORTB; // Toggle diodes on portb
Delay_ms(1000); // Wait for 1 second
}
Note: If you want to try another port, just replace each instance of PORTB and TRISB in code with
your port, e.g. PORTC/TRISC.
Step 6: Build!
Now it’s time to build our project. First, save your file by clicking on the Save Icon, or click Ctrl+S.
Select Project > Build from the drop-down menu, or click the Build Icon. You can also use the short-
cut Ctrl+F9.
Build.
page
4 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD