Summary of PIC – First Project
This article explains programming PIC microcontrollers using Embedded C and the MikroC IDE. It details creating a hex file, using a Pickit2 programmer to burn code, and specific setup steps like running as administrator and configuring clock speeds. The process involves writing code in MikroC, building the project to generate a hex file, connecting hardware via USB with necessary drivers, and using the Pickit2 software to import and write the program to the chip.Parts used in the PIC Microcontroller Programming Project:
- PIC Microcontroller
- MikroC Compiler from Mikroelektronika
- MPLAB IDE (Optional integration)
- Pickit2 Programmer
- Pickit3 Programmer (for latest devices)
- Computer with USB connection
- PL2303 Driver
- 20 MHz Crystal Oscillator
- .hex File
Programming in PIC microcontroller can be done by using assembly language or by using Embedded C because of the ease of writing code.We have used done the programming through Embedded C language.For programming any microcontroller we need a IDE or Intregrated Developement Enviroment. In case of PIC microcontroller the official IDE is MPLAB Further several third parties develop C language compilers for PICs, many of which integrate to MPLAB or feature their own IDE.
Steps for using MikroC IDE
Run MikroC as administrator as shown in the figure [Note: MikroC and MikroC pro for PIC are different compilers.We have used MikroC in all our tutorials for PIC. Please don’t confuse it with MikroC pro].
A sub window will open .Implement the following things in it
- Give a name to your Project [ Please don’t use names that are exactly same as the functions used in MikroC such as ‘main‘ or ‘for‘ ]
- Select a suitable location[Please don’t select desktop or my documents locations. Save inside a specific folder]
- Select the device for which you want to write the code
- Write down the value of clock in your hardware [I have used 20 MHz crystal oscillator thats why i wrote 20.000000]
- Click on “Default” and Click on “OK“
- Now a workspace will be created. Write your program in that area.
- After completing your program, save it and click on the build icon as shown in the figure
- If your program has no error then compiler will display a success message in the compiler messages area as shown in the figure above else the error messages will be displayed.Fix those errors(if any)
- Hex file successfully created.
Steps to write your program to PIC microcontroller
Connect your PIC microcontroller to the PIC programmer.
- Connect your PIC programmer to your computer.If you are connecting through your USB, you must first install this driver: PL2303
- Download and Open Pickit 2 programmer software[Download Link].
- If the device name is mentioned as shown in the figure below then it is successfully connected .If not then check your connection and the programmer again.
- Go to “File” in the menu and click on “Import Hex” and then go to the location where you have saved your MikroC project and select the .hex file associated with your MikroC project.
- After importing the .hex file change the VDD PICkit 2 value to “5.0” and click on “Write” as shown in the figure.
For more detail: PIC – First Project
Quick Solutions to Questions related to PIC Microcontroller Programming:
-
What language is used for programming PIC microcontrollers in this tutorial?
Embedded C language is used because of the ease of writing code. -
Which compiler was selected for this tutorial and why?
MikroC from Mikroelektronika was chosen due to its simplicity. -
What is a hex file created during the compilation process?
A hex file is a format used to store machine language code in hexadecimal form. -
How should you run the MikroC IDE to start a project?
You must run MikroC as an administrator. -
Where should you save your project files according to the instructions?
Save inside a specific folder and do not select desktop or my documents locations. -
What driver is required if connecting the programmer through USB?
You must first install the PL2303 driver. -
What value should be set for VDD in the Pickit2 software before writing?
The VDD value should be changed to 5.0. -
What step confirms the device is successfully connected to the programmer?
The device name being mentioned in the software window indicates successful connection.
Related projects
Download Legacy MPLAB IDE 8 from Microchip
The original MPLAB® IDE 8 series is still relevant when maintaining older PIC® and dsPIC® projects that were created before MPLAB X...
IDEs & CompilersHow to Download MPLAB X IDE Safely
MPLAB® X IDE is used for developing, building, debugging and programming embedded applications across several Microchip device families. For an active firmware...
IDEs & CompilersDownload MPLAB IDE v8.92 from Microchip
MPLAB® IDE v8.92 belongs to the final generation of the original MPLAB IDE 8 development environment. It still appears in older PIC®...
IDEs & CompilersSoftware UART (SoftUART) using TMS320F28027 Piccolo with Proteus Simulation
IntroductionCreating reliable serial communication without a hardware UART might sound tricky, but this SoftUART project proves how flexible embedded systems can be....
IDEs & CompilersMastering PIC 24F Series: A Comprehensive Guide with MPLAB and Proteus
Introduction The field of embedded systems plays a crucial role in modern society, with a myriad of applications across various sectors such...
IDEs & CompilersDigital Clock using PIC Microcontroller Interrupt – XC8
A Real Time clock (Digital Clock) can be made easily by using Timer 1 of a PIC Microcontroller. The Timer1 module exists...
