A Start-To-End PIC Programming Tutorial
In this tutorial we will implement a "blinking led" application. When you complete this tutorial, you will have a blinking led with a one second delay.
For this tutorial you will need :
On the Basic Tools To Program PIC page you will find basic tools for programming a PIC micro controller. These tools are an "assembler", a "programmer software" and a "programmer hardware". Before starting this tutorial you should download the softwares and prepare the programmer hardware (setup the circuit shown in the Tools page on a bread board or buy one).
Assembler : The assambler converts the assembly code into hexadecimal information which is meaningful for the microcontroller.
We will use Microchip's free PIC assembler tool which is called as MPASM. When you download and install the Microchip's MPLAB-IDE tool, the MPASM tool will be installed under the "./Program Files/Microchip/MPASM Suite" folder. You will see a program called as MPASMWIN.exe
- Choose Redix, Warning Level and Hex Output as Default.
- Choose Error File and List File from Generated Files.
- Clear the Case Sensitive check box.
- And choose the processor you use (here 16F628).
Let's try to assemble a file.
- Choose the file by pressing "Browse" button in MPASM.
- Be sure you configured the MPASM as in the above picture.
- Finally, click "Assemble" button.
If everything is fine, a dialog box will be shown like in the picture below.
Now, some files have been generated to the same folder you move the "blink.asm". These are "blink.err","blink.lst" and the most important one "BLINK.HEX".
The blink.err file shows the errors occured in the assembly process. The blink.lst file includes the programming information such as errors, warnings, memory. It is useful espacially for correcting errors.
BLINK.HEX is the file we will send to PIC microcontroller.
Programmer Software : The programmer software sends the hexadecimal information to the microcontroller.
We will use IC-PROG to program our PIC.
Configuring IC-PROG :
Configure the software as in the below picture :
Sending the hex file to the PIC
I assume you have a programmer hardware and it is connected to PC properly. If you have trouble with the programmer hardware recheck Basic Tools To Program PIC page or send me your question from the form on the About page.
- Click Open File from File menu.
- Choose the BLINK.HEX file.
- Click Program All from Command menu (Or press F5).
- Click Yes to Dialog Box.
It will program and verify your PIC. If everything is fine, you will see a message like Successfully Verified. Otherwise, you will see an error message saying error at the address ...
To see the results
Now, we need a testbench to see the results. I setup the test bench in the picture below.
I used the bottom part of my programmer bread board. I just carried the power for PIC (fifth pin to the ground and fourteenth pin to +5V)and connect a resistor (150Ohm)and a LED serially to the sixth pin of the PIC.
If everything is ok, the LED will blink with a delay of 1 second (approximately). (As you can see in the picture above, you should be very careful while working on bread board, otherwise you might burn the bread board with a chip :-) )
If you have any question or comment feel free to contact me from the communication form on the About page (use a correct mail address to have me to reach you later).