Professional Documents
Culture Documents
By Fernando Brea
Translation by Manolo Hernández-Peña M.
How to program a PIC microcontroller
IOCards Project
Table of content
1. Introduction
2. Materials
a. Hardware
b. Software
3. Hardware connections
4. Hardware configuration
5. Software installation
6. Software configuration
Introduction.
The aim of this tutorial is to explain how to program a PIC microcontroller used for the
second generation of electronic cards designed for IOCards Project.
The second generation of these cards uses PIC microcontrollers. This tutorial will show
how to program the PIC 16F876 used by the IOCards servomotor II and by the IOCards
encoders II.
I would like to thank to Manuel Vélez and everybody inside the cockpit builders group
for their achievements.
Materials.
Hardware:
Ø A serial cable
Software:
Available at:
http://www.opencockpits.com/modules.php?name=Downloads&d_op=viewdownload&cid=1&orderby=dateD
We will download the file corresponding with the circuit we are building. If you have
any doubt, you can ask in our forum.
Hardware connections.
Plug the cable in the PC serial port. There’s no problem in connecting it while the PC is
running because this port is protected against short circuits. Remember the port number
(1 or 2). We’ll need to define this number later in the software.
Insert the PIC in the programmer socket, taking into account the correct position.
Importatnt NOTES:
1. Insert the pic with the programmer disconnected from the cable to avoid electrical
damages to the PIC.
2. Don’t press the PIC very much. Only a good electric contact is needed.
3. To take out the PIC from its socket, use a screwdiver and try to maintain the PIC
parallel to the socket (to avoid the pins from breaking).
Hardware configuration.
Lets configure the serial port in our PC:
Windows 9x / ME
Start -> Configuration -> Control panel -> System icon -> Devices administrator tab ->
Ports (Com & LPT) -> Double click on communications port (Com 1 or 2 ). A similar
properties window as the one for Windows XP will be shown.
Windows XP
Start -> Control panel -> System icon -> Hardware tab -> Devices administrator tab ->
Ports (Com & LPT) -> Double click on communications port (Com 1 or 2 ) -> Port
configuration tab
Software installation.
Software installation is very easy. Just extract the downloaded files into a folder:
Note: if we use Windows XP, an error message will be shown the first time we run the
program.
Windows NT/2000/XP doesn’t let any program to use the hardware directly. Only
through windows APIs or through specific drivers. Icprog tries to access to the serial
port so the error is shown. To solve this we’ll have two options:
First, we’ll accept the error message, and the software will run.
Open Menu -> Settings -> Hardware and check Windows Api. Press OK.
Close the program and start it again. Now the error message is not shown.
Open Menú -> Settings -> Hardware and select Direct I/O. Press OK.
Then:
Menú -> Settings -> Options -> Mics tab and check Enable NT/2000/XP Driver. Press
OK. The following message will be shown:
Answer Yes.
Software configuration.
Start IcProg.exe
Oscillator and Configuration bits are changed as indicated by the *.hex file. We can
maintain these values, or change them later if we have problems during the
programming proccess.
The file code that we want to write in the microcontroller is stored in the buffer. The
programmer is connected to the proper serial port.
We will only know if the writing procces has been successsfully finished if we have
enabled the verification option.
Anyway, we can click the verification button after the writing proccess.
and when the “Verification completed” message is shown, the PIC is successfully
programmed.
it means that there’s an error in the first position. Most of times this is caused by a
communications error.
Errors solutions:
General
Try again after this advices. If you still have problems try this:
Hardware
v Check the cable connections and the number of the serial port
v Check the model of PIC that we are programming
v Check the PIC position on the socket
v Check that all the pins are correctly inserted on the socket
Try again after this advices. If you still have problems try this:
Software
Try again after this advices. If you still have problems try this:
v Decrease the value of “Bits per second” (Software configuration). Use the values
4800, 2400, 1200 y 300 trying with each of them.
Try again after this advices. If you still have problems try this:
v Menu -> Settings -> Hardware type, decrease two points the value of I/O retard
and try after each decrease.
Try again after this advices. If you still have problems try this:
If everything fails, don’t worry. Look for your friends; at least one of them will be able
to program your PIC.