Become a subscriber (Free)


Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.

Enter Your E-mail Address
Enter Your First Name (optional)
Then

Don't worry — your e-mail address is totally secure.
I promise to use it only to send you MicroZine.

PIC C Compiler: How to Quickly Use the MikroC Compiler to create a hex file from C Source code.

This pic c compiler tutorial shows you how to re-compile C source code using the MikroC compiler. These are the main steps that you use when re-compiling code that you can download from this site. The MikroC interface is a large one and there are many features that tend to confuse you when first using the software. These simple steps below will ensure you don't get distracted and can just got on with the simple task of compilation so you can produce a new hex file ready for programming into the PIC chip.

Note: For projects that are pre-version 6.0.4 ( .ppc extension. ) use the Project->"Import Project" menu and follow the instructions in the windows that follow to convert to Version 6.0.4 usage. Note that you have to manually copy over the .h files to the new project directory as this is not done for you.

Re-compilation is only needed to examine (see the .lst file produced to see the assembler code along with the C source code) or change the code as the ZIP files found on this site already contain the hex file for programming the chip.

 MikroC V6.0.4 main screen

MikroC has quite a few controls but for this compiler tutorial you only need to consider a few of them.

Re-compiling the source files

Download the ZIP file and extract its contents to your directory e.g. create the directory c:\Projects\a-project\.

In this directory you will have files with extensions .c, .h ,.hex ,.mcppi - the .mcppi file is the main project file that you select from mikroC using the Open project button:

Open Project

Opening a project file.

Menu:

Project-->"Open Project..."

Toolbar:

open project mikroC

Navigate to your stored files and select the .mcppi extension to load the project.

Edit Project

If you want to change the project settings e.g. the chip type, oscillator frequency or other chip parameters then hit the 'Edit Project' button :

Menu:

Project-->"Edit Project..."

Toolbar:

edit project mikroC

Compile

Next hit the compile button:

Menu:

Build-->"Build"

Toolbar:

compiling mikroc C source

Success

When the MikroC PIC C Compiler has completed its compilation the messages box at the bottom will show the compilation status (any errors in compilation are shown in red).

When the compile finishes (and if successful) you should see something similar to the following:

mikroc compiler success

Now there should now be a lot more files in the original directory and the hex file will have been updated.

Some Tips for MikroC PIC C Compiler

Libraries

MikroC is unusual in that it has a set of built-in libraries that you can use for many different peripherals. I tend to create the code myself as I like to know exactly how something works and this also has the advantage that:

  1. You can use the code for a similar peripheral device.
  2. You can get rid of bugs if you have any.

However, if you are pushed for time then the built in libraries provide a convenient way of speeding up the design process and include code support many different devices/concepts.

To find the libraries Use the Menu: View-->"Library Manager"

Examples of available libraries:

  • Conversions
  • CAN_SPI
  • LCD
  • GLCD
  • RS485
  • Trigonometry (integer operation)

Note: Double click the library to bring up help for that library component.

Warning: If you use the library you will be locked into using the tool and it will be difficult to change over to a different pic c compiler should you wish to do so. Also, sometimes MikroC likes to change things around and that breaks your existing code examples from this site are that they re-labelled UART functions as USART1 and USART2 and they don't provide a simple definition that would have stopped code breaking - you have to go away and figure it out which is a pain.

MikroC PIC C Compiler Library Linking Errors

The main reason for bringing up the subject of libraries is that for a normal project as some point you will be asked if you want to include all libraries (slows compilation a bit - I think). If you do not then you need to go in a specifically click checkboxes in the library manager to include standard libraries. This is totally non-standard behaviour - other compilers will include the libraries asked for in the source file - especially standard ones such as stdlib.h and string.h.

If you don't click the checkboxes you will get errors in the message output and the message will not indicate why it is there.

Example: If you turn off the C_Stdlib and compile the 7segment counter timer code the following error appears:

"Line 0      ErrNo.=360     Unresolved extern 'ldiv'"

The reason is that somwhere in the code a long divide operation is occuring and stdlib happens to be the place that this (assembler) library function is located - but the compiler wont' tell you that so you have to go through your code and check all libraries that are "included" by your code are matched by the checkboxes in the library manager. Some errors are more obvious e.g. LCD_Init and not checking the lcd library.

#include oddities

The other slightly wrong thing with libraries is that you can use them without declaring the include directive e.g. for the LCD frequency counter code it does not have the following line

#include "lcd.h" //

Also the above line causes an warning anyway!

The bad thing about this is that a library is included only by the external environment i.e. by the MikroC environment - that is Ok if you only ever use that environment for compiling but not if you want to move to a different compiler. Also it is just non-standard bad practice and allows you to get away with code that should have an include directive in it.



Jump from PIC C compiler to
Best-Microcontroller-Projects Home Page



Privacy Policy | Contact | About Me

Site Map | Terms of Use | Links




Google

Recent Articles

  1. A short pic C compiler tutorial on compiling mikroelectronika C files.

    Oct 21, 14 02:06 AM

    Simple PIC C Compiler instructions for quickly compiling MikroC hex files from C source code.

    Read more

  2. A frequency counter using timers built into microcontrollers.

    Oct 15, 14 02:54 PM

    How to make a frequency counter working up to about 50MHz, using a pic microcontroller.

    Read more

  3. Color Sensing Circuit

    Oct 08, 14 05:07 AM

    Color sensing circuit : How to use three LEDs to detect color using a microcontroller

    Read more

Custom Search

Sign up for MicroZine:
''The'' Microcontroller Newsletter


Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:


"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be Removed
at any time.  

It will NOT be
available indefinitely SO

To avoid
disappointment get it:

Now



:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.


To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates.

Scroll up to the form above and sign up NOW.  Don't forget it's FREE and if you don't like it you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.



Social Bookmarking
Click & Add:
add to BlinkBlink
add to Del.icio.usDel.icio.us
add to DiggDigg
add to FurlFurl
add to GoogleGoogle
add to SimpySimpy
add to SpurlSpurl
Bookmark at TechnoratiTechnorati
add to YahooY! MyWeb
Readers comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."


- Ranish Pottath


"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com

Learn PIC C Now
Wondering how to program your next project using C and need a great start?


"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

Learn Microcontrollers
"Interested in
Microcontrollers?"


Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon