PIC Micro's For Beginners - Program
your first PIC
You have the code, and you know what a PIC is -
you now need to get a
PIC programmer and program your code onto your PIC! I use the
PICKit 2 for programming, as it is made by the same company that
develops PIC's, and in return it is extremely reliable and can
program almost every PIC under the sun, and it is actually very
affordable. After you have installed the PICKit 2 software, connect
the PIC to the PICKit 2 with the relevant programming pins. These
are always;
-
MCLR (pin 1)
-
Vdd (pin 14)
-
Vss (pin 5)
-
PGD (pin 13)
-
PGC (pin 12)
Note;
(5 pins, positions vary for different PIC's, but the 18F1320 is
shown above)
Here is the pin-out for the PICKit 2;

With these pins connected to your
PICKit 2, you can now program your PIC. I use
breadboards
extensively, so should every hobby electronics guru,
and I dedicate a single
breadboard for programming PIC's, so there
is no need for expensive adaptor boards or the such, just put your
PIC in a
breadboard and connect the relevant pins, then off you go.
Here's a the wiring diagram for the PICKit 2 and the
18F1320, and below that, a picture of my setup for the
PIC micro on
the
breadboard;
Note that the pins are numbered around the device, and are not in
the same physical location as the DIP package (this is because of
the software I use to draw the circuits)

You can either use
pre-terminated wire such as this or make a small adaptor using
standard headers and some ribbon wire as above. Watch this video
Watch this video, as I cover a lot of the
fundamentals and basic software use, such as compiling your program
and writing to the PIC.
Now your PIC has the program loaded onto it, you can
put it into your circuit with the LED and watch the program work
exactly as you have instructed it. Here is the wiring diagram for
the end project;

The reason why there is a
470 ohm
resistor in series with the LED is to limit the current
output of the PIC on that particular pin. Without this
resistor, the
pin will supply 5V and over 25mA when it is a logic "high" (LED
= 1). This is enough current to destroy most LED's, and
therefore needs to be restricted in some manner.
When wiring up your circuit, always be sequential and
smart about your design. Always build the power supply first and
then check the output with a multimeter, afterwards disconnect the
battery or DC power pack and continue building the circuit. When
power is applied, if anything gets hot, it is a good indication that
you have got a short circuit somewhere in your circuit - disconnect
power and isolate the fault. It is normal for your 7805 voltage
regulator to get a little warm if operating with a supply over 10
volts - but still, the temperature should be low enough to touch it.
With everything constructed, your LED will flash on
and off once every second! This is but the start of what you can do
with PIC's, your next projects should lift in intensity slowly so
that you grasp concepts firmly and knowingly, from here I would
recommend learning
how to connect a switch and read its status, then
venture into slightly more complex things - but don't get too far
ahead of yourself! If you run into issues with this guide or others
on the site, please check out my
forum and feel free to post or help others!
Finally, as I explained earlier, the compiler used to
create the program was
Swordfish, and it supports almost every 18F PIC on the market.
If you were using a different type of
PIC micro, then you simply
need to change the Device,
Config and
OSCCON settings to suit your
target PIC. I have made a section specifically designed to help the
migration between different devices which would
come in very handy for this purpose
Core Electronics sells an "Intro To PIC's Kit"
which includes everything I have used in this tutorials and
more (there are a couple of switches and extra LEDs etc) which is
very affordable and I really recommend it to anyone who wants a
PICKit 2,
breadboard, voltage regulator and other components for
less then $50.
Have a look at some other 18F tutorials and
examples, click to continue