How to Use “MikroC PRO for PIC” to Program PIC Microcontrollers

How to Use “MikroC PRO for PIC” to Program PIC MicrocontrollersFrom now on we are going to start a new series of tutorials on PIC Microcontrollers. We will start from very basic level. We will make some projects using PIC Microcontrollers from beginner level to expert. In today’s tutorial we will learn how to use “MikroC PRO for PIC” software to program a PIC MicroController. Here we will cover only simulations of project on Proteus. In next tutorial we will shift to hardware as well. You may also like to check pic microcontrollers programming in c and pic microcontroller assembly language programming.

Following are the steps you need to follow to run a simulation in Proteus using program from “MikroC PRO for PC” software.

  1. First of all download the software from given link and install it.

  1. After installation, start the software from desktop icon which seems like this one
  2. Once started you will see a screen like given below.
  3. To create your first project, click “New Project”.
  4. “New Project Wizard” window opens. Select standard project and click next.
  5. Type Project Name, Folder where you want to save your project, your PIC MicroController device mine is P18F46K22 (for simulation you can use any but you will have to select same in Proteus) and Device clock (set it to 32MHz). Then click Next.
  6. Again click next. We don’t need to add any file.
  7. Select “Include all” libraries and click Finish.
  8. A window like shown below appears. This is place where we will write our program.
  9. Go to projects at menu bar and select Edit project.
  10. In the opened window select your MCU (MikroController name) and MCU clock frequency. Further on left panel Oscillator selection, 4x PLL, Brown out Reset and MCLR pin should be set as shown. And then click OK.
  11. Now it’s time to write our program.
  12. We will write a program to turn a LED ON and OFF connected to PIC MikroController with a delay. We need to set different registers of PIC MikroController to get this project work. We will discuss all of them one by one.
  13. TRIS register determines whether port is input or output. It can contain either 0 or 1 value.



When we use TRISB its’ going to set whole port B i.e. (B0, B1, B2 …) as output.When we use TRISB1_bit it sets only B1 pin as output.

  1. ANSEL register determines whether port is digital or analog. It can contain either 0 or 1 value.



When we use ANSELB it’s going to set whole port B i.e. (B0, B1, B2 …) as DIGITAL.

  1. LAT register is used to write a value on a port. When we use LATB it is going to write values on port B. We can give it a hex value like 0x00 will write 0 on port B and 0xFF will write 1 on the Port B. LAT register can contain both hex and decimal values i.e. writing only 0 instead of 0x00 will also set port B to be 0. If we want to set only pin B0 to high or low we will use LATB.B0
  2. Delay_ms () produces the delay in milli seconds.
  3. Write the following code in software
  4. void main() 
     TRISB0_bit = 0; //set pin B0 as output
     ANSEL = 0; //set port as Digital
     LATB.B0 = 0; //write the pin B0 with 0 value
     Delay_ms(1000); //Delay of 1 second
     LATB.B0 = 1; //write the pin B0 with 1 value
     Delay_ms(1000); //Delay of 1 second
     while(1); //Keep the loop running
  5. After writing the code Build it from Menu bar. If everything is right it will display a message of finish successfully in below window.
  6. Draw circuit in Proteus as shown (Use same controller which you selected in software earlier). Set crystal frequency 8MHz by double clicking it and entering the frequency in dialogue box that appears.
  7. Double click the MikroController in Proteus a dialogue box appears as shown
  8. Browse for Program file in box and give the path of .hex file created after building the program in MikroC software. It will be in same folder, where you saved the .c file. Also change the processor clock frequency to 32MHz.
  9. Click on play button on the bottom of Proteus.
  10. You will see that LED is blinking for 1 sec on Proteus window.
  11. That’s all for this tutorial in our next tutorial we will see how to program our actual controller using PICKit3.

Video lecture on how to use MikroC for pic

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,097 other subscribers