PIC Microcontroller Tutorial - Lesson 1
Author : Dinesh Kumar Wickramasinghe
Hello friends, I am writing this set of blog posts to those who are willing to learn PIC family microcontroller programming from the beginning. Actually I was planning to write these blog posts long time back but it didn’t go as planned. Somehow I could find some time now to write. So this set of tutorials are for those who are willing to learn microcontroller programming from the beginning.
I started learning Microcontroller programming from the famous PIC family microcontrollers. After sometime I heard about Arduino and then I found that Arduino is a very easy platform to learn. But I still love doing experiments with PIC microcontrollers and It has the real fun.
A typical computer has a processor, memory and input / output ports to connect external devices. Microcontroller has the same. We also call a Microcontroller as a Microcontroller unit (MCU)
Why use Microcontrollers?
Microcontrollers are mostly used in Embedded Systems. You can use Microcontrollers from simple electronic circuit to a large industrial automation projects and also Robotic projects. You can build firmware for Microcontrollers using programming languages like C, C++ and you can easily update your firmware. You can connect many devices like sensors, morots, relays to Microcontrollers.
Difference between a Microcontroller and Microprocessor
You know Microprocessor cannot work alone. It needs memory storage etc. When building a PC, you need to purchase Processor, RAM cards, also a Motherboard to fit them all. But in a Microcontroller, it has everything (But sometimes you may need to connect few external components like an oscillator).
Compared to the power of a PC, microcontroller has a limited processing power and limited memory. Yes you cannot play Crysis on a microcontroller :P
Famous Microcontroller Manufacturers
Well known Microcontroller manufacturers are Microchip, Atmel, ARM, Texas Instruments, Intel etc.
You know the famous Arduino UNO platform is based on ATmega328 Microcontroller which is manufactured by ATmel.
In this tutorial series, I will use PIC family microcontrollers which are manufactured by Microchip.
Which Microcontroller should I select in my project?
It is totally depend on your project requirements. We will talk more about this later.
About this Tutorial Series
During this tutorial series, I will use PIC16F84A and PIC16F877A microcontrollers. Why I selected them because those microcontrollers are easy to learn, Cheap and easy to program.
As the programming language, I will mostly use MikroC language from Microelectronica.
What Hardware and Software I need?
When using Arduino platform, the only thing you need is the Arduino board and a USB cable (except sensors, motors etc)
But when dealing with PIC Microcontrollers, you need a few things. But don’t worry, you can build them all by yourself. If you want, you can purchase them too.
Here are the Hardware you need (I will give you more detail later in this post)
- PIC16F84A / PIC16F877A microcontrollers (First few lessons are only based on PIC16F84A)
- A Microcontroller Programmer (You can buy or you can build your own one, I will show you how)
- Simple Microcontroller project board (This one also you can buy or you can build your own one)
- LEDs, Sensors, Motors etc (Don’t worry now, we will move step by step)
Here are the Software you need (I will give you more detail later in this post)
- MikroElektronika MikroC compiler
- Programmer software (MicroBurn or ICProg)
Let’s build your own Microcontroller Programmer
You need something called Programmer to upload your firmware (Your compiled version of source code) to your microcontroller. So basically programmer is an interface to connect Microcontroller to your PC or Laptop. Below version of programmer is called the JDM programmer. It is very simple and easy to build. The only disadvantage here is the JDM Programmer connects to the PC via the Serial port. Most modern PCs and Laptops do not have Serial ports. But there is a solution. Wait a second I will explain to you later.
Anyway here is the schematic of the JDM Programmer for PIC16F84A.
Here is the schematic of the JDM Programmer for PIC16F877A.
You don't need to build two programmers. You can see that components are the same on both schematics. Just build one and add two IC bases for both Microcontroller types. Connect the relevant pins of the IC base carefully. You can understand this if you carefully check both schematics. Please note that you can program only one Microcontroller at a time.
Here is my JDM programmer. It has two interfaces to connect both PIC16F84A and PIC16F877A. I built this one years ago and still works fine.
And here is another version of JDM programmer I built (Mini JDM) . It can only program PIC16F84A Microcontroller.
You can see that both the programmers has normal IC bases, but it is much better to use a ZIP socket.
I know most of you don’t have a Serial port on your PC or Laptop, then you have to go for a USB Programmer. It is a bit difficult task to build your own version of a USB programmer. So the best way is to buy one. You can buy K150 Programmer. K150 is cheap and it supports many types of PIC Microcontrollers.
You will also find PICKit family programmers with more advanced debugging features.
Let's build a simple Microcontroller Development Board
Once you upload your firmware to the microcontroller using any of the above mentioned programmers, you need a development board to test it. You can build your own one. Here are the schematics for PIC16F84A and PIC16F877A microcontroller development boards.
Schematics for PIC16F84A
Here is an image of my development board for PIC16F84A
Schematics for PIC16F877A
Here is an image of my development board for PIC16F877A
On both of the development boards, I’ve used a 4MHz crystal. Also 7805 voltage regulator to supply stable 5V to the microcontroller.
I’ve also used female headers to all the ports of the microcontroller. So I can easily connect sensors, LEDs to the microcontroller for my experiments. You can also add few female headers to the +5V and Ground connections.
You can also buy a development board like in the picture below. This one is for PIC16F877A microcontroller. I couldn't find any commercial version of development boards for PIC16F84A microcontroller.
Software Download Information
We will use MikroElektronika MikroC language in this tutorial series. You can download the MikroElektronika MikroC IDE from the link below.
Download MikroElektronika MikroC IDE
You can also download the latest version from the Official MikroElektronika page.
If you plan to use the JDM programmer, then you can use the IcProg software to upload your compiled code to the Microcontroller.
Download IC Prog
If you use K150 programmer, then you have to use MicroBurn. This is also a similar software. You can download MicroBurn here.
Here is the end of this blog post. In the next post I will explain you how to write your first PIC Microcontroller code and upload it to the PIC16F84A Microcontroller and test it. So make the things ready.
If you see any unclear things in this article or any mistakes, questions, please comment. I will try my best to explain them as much as simple.
Have a nice day.