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




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.

https://www.mikroe.com/MikroC/#pic

  • After installation, start the software from desktop icon which seems like this one

1-icon

  • Once started you will see a screen like given below.

2-First

  • To create your first project, click “New Project”.

3-creat

  • “New Project Wizard” window opens. Select standard project and click next.

4-wiz

  • 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.

5-wiz2

  • Again click next. We don’t need to add any file.

6-Wiz3

  • Select “Include all” libraries and click Finish.

7-wiz4

  • A window like shown below appears. This is place where we will write our program.

8-start

  • Go to projects at menu bar and select Edit project.
READ  Breakout board for 18-pin PIC16F series microcontrollers

9-edit

  • 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.

10-edit2

11-edit3

  • 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.

  1. 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
  • void main(){TRISB0_bit = 0; //set pin B0 as output

    ANSEL = 0; //set port as Digital

    do

    {

    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

    }

12-progrm

  • After writing the code Build it from Menu bar. If everything is right it will display a message of finish successfully in below window.

13-build

  • 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.

14-circuit

  • Double click the MikroController in Proteus a dialogue box appears as shown

Read More Information….

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




Current Project / Post can also be found using:

  • how to write a program in MicroC of P18F4550 microcontroller pdf

Leave a Comment

*
= 5 + 0

Read previous post:
World’s Largest Neuromorphic Supercomputer goes Live
World’s Largest Neuromorphic Supercomputer goes Live

The world’s largest neuromorphic supercomputer built to process information in a similar manner to the natural brain function has finally...

Close
Scroll to top