How to Program a PIC Microcontroller to Build a Project

The recent trends in the advanced technology are helpful in developing most advanced electronic gadgets. Most of these electronic devices are developed using microcontrollers. The microcontroller is an electronic component, which is programmed to perform various control operations. There are various kinds of microcontrollers available, such as 8051, AVR, ARM, and PIC microcontrollers, etc., which are programmed by using the integrated development tools.

PIC Microcontroller Programming Steps

PIC Microcontroller

The PIC is a family of the microcontroller, which is manufactured by the different companies such as NXP, microchip, etc. The PIC stands for “peripheral interface controller”, which contains memories, timers/counters, serial communication, interrupts and ADC converters built into a single integrated chip.

The PIC microcontrollers are found in most electronic devices such as alarm systems, traffic control systems and RFID based security systems, etc. The PIC microcontroller programming can be carried out to perform the huge range of tasks. Even though there are many types of PIC microcontrollers , the best and basic microcontroller is PIC16f877a.

The microcontroller generates the output logic pulses so that the LED light is switched ON and OFF at certain intervals. It is a 40 pin microcontroller. The Crystal interfaced to the input pins of the microcontroller provides accurate clock signals at the crystal frequency.

Circuit Designing

The PIC microcontroller transmit and receive the data with respect to clock pulses, the PIC microcontroller operates with 4MHz crystal frequency. Two capacitors are connected to the crystal oscillator with range of 20pf to 40pf which is used to stabilize the clock signals. At some times, the PIC microcontroller goes to block state or missing time calculation,at that time we need to reset the microcontroller. If a microcontroller is reset for 3sec time delay, 10k resistor and 10uf capacitor are connected to the respective pins.

The 5v DC supply is given to the 11 pin of the microcontroller which drives the circuit. The crystal is connected to the 13 and 14 pins of the microcontroller. The reset circuit is interfaced at 1 pins of the microcontroller. The Yellow LEDs is connected to the PORTB of the microcontroller.

Circuit Diagram

This circuit is designed with the help of Proteus software. The Proteus is a circuit designing software that contains a database of components, which we can use to build the circuit. Each and every component is available in the component library.

PIC Microcontroller Project Circuit Diagram

Open the Proteus software. A window with a menu bar appears.

Click the file menu.

Select ‘new design’ from the drop-down menu.

Click the library menu.

Select ‘pick devices/symbol’ from the drop-down menu.

Select the relevant comment by double clicking it, so that the electronic components list appear on the window.

Add all the components and draw the circuit with the proper connections as shown above.

Program the PIC Microcontroller

The PIC microcontroller programming is performed through ‘MP-Lab’ software. First instal the MP-Lab software, then select and install the compiler like CCS, GCC compiler, etc. Here ‘CCS C compiler’ is used for building the program.

First open the MPLAB software. This shows the menu bar with file, edit, view, project and tools option.

Select the project option and select the ‘project wired option’ from the drop-down menu. This will show the project wired window.

Select the compiler and path location for your project. Here ‘CCS C compiler’ is selected for the PIC microcontroller, then select the ‘browse’ option from the project wired window to select the ‘ccsloader’ in the PICC folder from the program files. A folder with the name ‘source group’ is created in the ‘target’ folder.

Give a name to the project and click on ‘NEXT’ button to save the project. A folder with the name ‘source group’ is created in the ‘target’ folder.. Click on the ‘file’ menu on the menu bar. Select ‘new file’ from the drop- down menu.

Load the Code to PIC Microcontroller

The code loading process of microcontroller is called dumping. The microcontrollers understand only the machine level language, which contains ‘0 or 1s’. So we need to load the hex code into the microcontroller. There are many softwares available in the market for loading the code to the microcontroller. Here we have used ‘PICFLSH’ programmer software to dump the code to the PIC microcontroller. The programmer kit comes with the hardware kit along with the software.

This software needs to be installed into the computer. The microcontroller placed in the hardware kit, which comes with the socket. Here are the steps to load the code onto the microcontroller.

Code Dumping Device

Interface the hardware (programmer kit) to the computer through a serial cable

Place the microcontroller in the socket of the hardware kit. Press the lock button to ensure the microcontroller is connected to the board.

Open the software installed in the computer. This shows the menu bar with file, functions, open, save and setting options.

Select the ‘open’ option from the drop-down menu and select the ‘load file’ .

Click on the ‘load’ button so that the hex file is loaded into the microcontroller.

Code Loading to PIC Microcontroller

Simulating the Circuit

The simulation is a decision analysis and support tool, which is used to know the performance of the circuit. The hardware is the cost-effective equipment, so the proposed action cannot be directly observed by the hardware. The simulation software allows you to know the circuit performance and find & rectify the errors of the program. There are different types of simulating softwares available in the market for checking the circuit performance. Here Proteous software is used to check the circuit performance.

Open the project in the Proteus software.

Click on the ‘Debug’ menu.

Select the ‘start debugging’ option. The LED starts blinking, which indicates the circuit is running.

After some time, select the ‘stop debugging’ option. The LED will now stop blinking.

32 Comments

I am trying to develop a x-y axis motion system on PIC16f877a. I have the hardware and the proteus and Mplab software. But I dont know how to start and how many number of ICs I require for achieving this. Any and every help is appreciated.
Thank you.

Hii sir, I am student and I have given project based on pic microcontroller,by using pic we control the speed of DC motor by producing pwm..but I have problem that is to control the pwm by using andriod phone.SO. i need help..plz reply sir

I don’t know if i can learn diz C prorgramming code from the starch.. am just a beginner and i am really interested in learning this code, probably if there is any online class for it. i will really appreciate if u reply me

HI Ibrahim Oluwanishola
Sorry to inform you that we cannot provide you, online classes,
Thank you so much for your feedback
But if you have any technical queries please email us on team@elprocus.com and our technical team will help you.

Hello,
thank you for the article, gets basic understanding on pic microcontroller.
Am working on one project which requires the functionality as when we give one pulse(analog) then counter should increase on display and timer enables for certain amount of time (0-99 ms).
Please suggest what steps need to take.

please can you help me on my project.The project is to control the speed of 220 v dc motor using pic microcontroller with help of pwm.And future we have to contol the duty cycle of pwm with the help of android phone via wii or bluetooth module.Sir please help me sir.

Hi Nazim
Thank you so much for your feedback
Check out the link for the latest PIC projects.
If you have any technical queries or if you need a customized project from us please email us on team@elprocus.com

Hi,
I am new to this so please excuse if this sounds a little stupid. I have a K150 pic programmer and a couple of brand new pic16f627a. The programmer is already attached to my pc and already working. I’ve got the microbrn software running on my desktop and can open and read the IC’s.

I would like to use the pic IC’s for FM radio broadcast in the following two frequencies: 62.2mhz and 62.5mhz. I also have the physical transmitter circuit but damaged the PIC IC (pic16f627a) through a short circuit.

What I need to know is how to program each new IC to one frequency each? Do I need a HEX code builder or an FM Transmitter circuit diagram simulator to design the circuit and produce the Hex codes? Would you be able to generate the HEX codes for me?