How to Use “MikroC PRO for PIC” to Program PIC Microcontrollers: From 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.
- First of all download the software from given link and install it.
- After installation, start the software from desktop icon which seems like this one
- Once started you will see a screen like given below.
- To create your first project, click “New Project”.
- “New Project Wizard” window opens. Select standard project and click next.
- 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.
- Again click next. We don’t need to add any file.
- Select “Include all” libraries and click Finish.
- A window like shown below appears. This is place where we will write our program.
- Go to projects at menu bar and select Edit project.
- 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.
- Now it’s time to write our program.
- 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.
- TRIS register determines whether port is input or output. It can contain either 0 or 1 value.
0 = OUTPUT
1 = INPUT
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.
- ANSEL register determines whether port is digital or analog. It can contain either 0 or 1 value.
0 = DIGITAL
1 = ANALOG
When we use ANSELB it’s going to set whole port B i.e. (B0, B1, B2 …) as DIGITAL.
- 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
- Delay_ms () produces the delay in milli seconds.
- Write the following code in software
- After writing the code Build it from Menu bar. If everything is right it will display a message of finish successfully in below window.
- 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.
- Double click the MikroController in Proteus a dialogue box appears as shown
- 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.
- Click on play button on the bottom of Proteus.
- You will see that LED is blinking for 1 sec on Proteus window.
- That’s all for this tutorial in our next tutorial we will see how to program our actual controller using PICKit3.