Getting Started With PIC Microcontroller
by Lithium-ion in Circuits > Microcontrollers
55 Views, 2 Favorites, 0 Comments
Getting Started With PIC Microcontroller

It is the new series on PIC microcontroller in which we will learn basic PIC programming and hardware implementation to advance level.
Supplies
PICKIT 3
PIC16F722A
JUMPERS
BREADBOARD
STORY:

I am used to AVR and ARM microcontrollers, never have I ever seen a PIC lane around in my lab. Then one day, I bought two of them, the PIC18F2550 and PIC16F722A. Just to test what is different, why they exist and what are the types of projects which can be made using them. Usually the PIC node is cheaper and used in optimized projects that are in the market. I found it is easy to program a PIC and overall offers a better price to performance ratio than other available microcontrollers with the same specifications. In this tutorial we will show how I programmed my first PIC chip and I will provide the exact links to software which are used. I will show why setting this type of environment helps a user to easily program these MCU.
This PIC series is sponsored by PCBWAY, A reliable and affordable PCB/PCBA manufacturer from CHINA. PCBWAY is one stop solution for all the prototyping needs. As the series continues we will order our development board from PCBWAY.
PIC16F722A:
The PIC16F722A is an 8-bit microcontroller from Microchip Technology based on the enhanced mid-range architecture of the PIC16 family. It is widely used in embedded applications due to its low power consumption, rich peripheral set, and affordability.
Key Features:
- CPU: 8-bit Enhanced Mid-Range Core
- Operating Frequency: Up to 20 MHz
- Program Memory: 14 KB Flash
- RAM: 384 bytes
- EEPROM: 256 bytes
- I/O Pins: 35 (out of 40 pins total)
Peripherals:
- Timers: 1× 8-bit Timer, 2× 16-bit Timers
- PWM Modules: 2 (via CCP)
- CCP (Capture/Compare/PWM): 2 modules
- USART: 1 (for serial communication)
- SPI / I²C: 1 module supporting both protocols (MSSP)
- Analog-to-Digital Converter (ADC) 12 channel 10 bi
- Comparator Modules: 2
Writing First Assembly Level Blink Code:
Writing code in assembly language requires learning register level programming, which can be seen in the datasheet and can be modified accordingly. Writing assembly level is good, but requires much more expertise than C programming. Making logic in register level programming is more difficult than high level languages like C or Python.
Here we are just going to make a simple GPIO toggle program. The good thing is that the programming of registers is the same for all 8 bit microcontrollers in a PIC environment, so this same code works for every 8 bit PIC. The register for GPIO toggle is known as TRIS, here is the assembly level code for the same.
Code:
Now we need a compiler which converts this code (low level language) into machine level code (HEX format) . The proper procedure and software for this is given below.
Compiling and Getting HEX File:




For the compiling of the code, and to convert the same into HEX. I am using MikroC software. This one supports the whole family of PIC and is very easy to learn in the first go, if you are a beginner. Let’s convert the code into HEX in 4 steps.
- Download the software, make a new folder and set up a project in that as a standard project.
- Change the CPU clock as per the max clock the IC can work on, see in datasheet.
- Go to the edit project section, under the project tools menu. Under the general output setting tick export as hex.
- Now hit the build button. It will make some at the project location in the same folder. We only need the Hex file to copy it from there to a safe location. And that is all what we need from the compiler.
Getting Hands on PIC KIT 3:

Now we have a HEX file which is basically the same code, but the compiler version or we can say machine level code. Now we have to put this code into the PIC16F722A. Download full blink project from here.
PIC microcontrollers can use high-voltage programming (HVP), especially for in-circuit serial programming (ICSP) or factory programming. High-voltage programming is a method where a higher-than-normal voltage (typically ~12V) is applied to the MCLR/VPP pin of the microcontroller to put it into programming mode. Like for Arduino programming we need a USB to TTL converter. For programming the PIC we need PIC KIT, I am using version 3 of the same, it is quite expensive due to its hardware. But there are some alternative options which will be discussed in upcoming blogs. And to interface PIC kit with microcontroller and computer, a compatible software is required, discussed below in detail.
Setting PIC KIT 3 Software:




PIC kit 3 is officially released by microchip, it can be downloaded from here. Here are the 3 steps for programming the IC using PICKIT 3 and software.
Step1: Connect the PIC kit to your microcontroller according to the given schematics.
Step2: Start the software, and it will automatically detect the IC. Sometimes for the new PIC we need to download the operating system which is automatically redirected when clicked, under the tools menu > update operating system > opens a folder > select HEX > wait > done.
Step 3: Choose the HEX file (BLINK code) and then click write it will take a few seconds and dump the code in your IC and message back : programmed successfully.
Testing and Working:


After successfully following the steps, I was able to program the IC in the first go. Some point to note, this is high voltage programming (12v) but VDD and VSS of the IC are connected at +5v and ground. Without a proper programming controller we can not program these PICs. The programming using PIC kit is a little fast as compared to Arduino. Some PIC has USB serial programming support, but to configure that we need to upload the right bootloader in the IC first. But when programming with a PIC kit, it does not require any external bootloader.
Get your hands on custom PCB, from PCBWAY. Sign-up now using this link and get free PCB coupons for your first order. Explore PCB, PCBA, FLEX, STENCIL, CNC, 3D PRINTING and much more..