Tuesday, May 10, 2011


MPLAB Integrated Development Environment (IDE) is a free, integrated toolset for the development of embedded applications employing Microchip's PIC® and dsPIC® micro controllers. A rich set of compilers and assemblers are also available with it.

This post teaches you to how to start programming your PIC microcontroller in C using MPLAB IDE. To begin with download and istall MPLAB IDE from the the the Microchip's website.Don't forget to install HITECH C compiler when it asks you during the installtion process. For the demopnstartion purpose I am using MPLAB version 8.60.

Now start the MPLAB. The following screen appears.

This is the environment where you do your further work.Next select the project wizard from the Project menu.

 Next select the pic which you are using. Here PIC 16F877A is used.

Next select the compiler toolsuite. Here HITECH C compiler is used and it is selected.

Next give the name of the project and select a project directory where the necessary files needed for your project are kept. Here " test " is the project name.

Here we can add the files required for our project. For the time being you can leave it.Click next to continue.

Here we can add the files required for our project. For the time being you can leave it.Click next to continue.

Now every thing is over.

Once you click finish you can see a window as shown below.

Here you can add various files for your project.

Open a new file from the file menu and enter the following program and save it as "led.c".

Now you have to add this file to the source file as shown below.

In the program we have used  a delay function which is included in the header file "delay.h". So we have to add "delay.h" to the header files and "delay.c"  files to the header files as shown below.

Once this is complete you can build your project by selecting 'Build' option from the Project menu or by pressing F10. If there are no errors then you will get a message 'Build Successful.

For the proper working of the PIC you will have to set the configuration bits. You can set it in MPLAB itself. From the 'configure' menu select Configuration bits and you can set the various bits as shown below. A typical value is 3F7A for a 10MHz crystal.

After building the hex file will be formed.

Also you can export your hex file.(File menu -> Export File). The advantage is that the together with the program code, eeprom, configuration bits, Device ID etc will be automatically programmed into the PIC.

Now you can use any of the programmer to program the PIC.

Downloads : test.zip



Abraham Alexander said...

Nice work Anil :)


Muhammad Azeem said...

This is a nice article..
Its very easy to understand ..
And this article is using to learn something about it..
asp.net, c#, javascript
Thanks a lot..!

Anonymous said...

nice article but i think it's not complete...thanks anyway

nesrine.algeria said...

nice article, hope u all the best...

prakul rajvanshi said...

thanks for the article it help me a lot.

Karthiksai said...

hi can u show me the code for delay.c pls?

Anil C S said...

it is included in the test.zip file included at the end of this post. You can download it.

unr34l-dud3 said...

You should not set the config bits via MPLAB, set it in your code! MPLAB X does not support the config *tool*.

Anonymous said...

Thank you. It helped a lot.
For someone doesn't have hi-tech C compiler:

Sulav said...

i dont get how to create delay.h and delay.c in test.mcw section??? can u help me please

Jim said...

Nice article, thank you

Anonymous said...

i cannot save in source file it is saving in other files. while building error message comes ' there is no source files in the project' please help me

Anonymous said...

this is wrong code for pic32mx795 programing.

dont be happy all of u .

it's never work on kit of pic32 controller

Arshia Hafeez said...

from where can i add delay.h and delay.c files??? please help me out

Srinivas Vinee said...

sir please send me pic18f458 ide and supporting hi tech cross compilrer links for downloading

Anonymous said...

Sir, how we can give a varying delay (not a constant delay like 100ms)? Let the required delay is stored in a variable 'x'. Is it possible to write as

Prince Garg said...

can you suggest me some reading articles where i can learn some basic programs...

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes