+ All Categories
Home > Documents > Programming a PIC

Programming a PIC

Date post: 22-Nov-2014
Category:
Upload: alice-teh
View: 47 times
Download: 3 times
Share this document with a friend
Popular Tags:
14
How to program a PIC microcontroller By Fernando Brea Translation by Manolo Hernández-Peña M.
Transcript
Page 1: Programming a PIC

How to program a PIC microcontroller

By Fernando Brea Translation by Manolo Hernández-Peña M.

Page 2: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Table of content

1. Introduction 2. Materials

a. Hardware b. Software

3. Hardware connections

4. Hardware configuration 5. Software installation

6. Software configuration 7. Programming the microcontroller 8. Errors and solutions

Page 3: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

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. IOCards project is based in some electronic cards developed by Manuel Vélez (http://www.opencockpits.com) and the related software that make posible to control the flight simulator with external elements as switches, buttons… 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.

Page 4: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Materials. Hardware: Ø The PIC 16F876 controller

Sold in electronics shops

Ø The programmer (T-20se or similar)

Sold in electronics shops.

There are another models as T-20 II, el TE-20 X. If you can’t find them, the best is to ask for a PIC 16F876 programmer and the personnel in the shop will advice us. Price

can be from 8 to 10 € NOTE : TE-21 programmer is NOT valid.

Ø A serial cable

Sold in electronics shops.

It depends on which connectors our PC and the programmer have. Nowadays, most of PCs have a male DB9 connector and most of programmers have a female DB9

connector. NOTE : we DON’T need a crossed cable; inner connections are made pin to pin.

Page 5: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Software: Ø ICProg (Ver. 1.05C) software.

Downlodable from http://www.ic-prog.com

Here you can download the last version of ic-prog.exe file and the helpfile. If you use Windows NT/2000/XP you’ll have to download the IC-Prog NT/2000 driver too (ic-

prog.sys).

Ø Code file (IOCard_Servo.hex)

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.

Page 6: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

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).

Connect the cable to the programmer.

Page 7: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

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

Verify the following values: Bits per second: 9600 Data bits: 8 Parity: None Stop bits: 1 Flow control: none With this we have finished configuring our hardware.

Page 8: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Software installation. Software installation is very easy. Just extract the downloaded files into a folder: icprog105C.zip -> icprog.exe (the main program) help_spanish.zip -> icprog.chm (the help file) icprog_driver.zip -> icprog.sys (the driver for Win NT/2000/XP) 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:

1- Configure Icprog for using the windows APIs or 2- Install the specific drivers.

First, we’ll accept the error message, and the software will run. 1 .- Use the Windows APIs: Open Menu -> Settings -> Hardware and check Windows Api. Press OK.

Close the program and start it again. Now the error message is not shown. 2 .- Using specific drivers for NT/2000/XP 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:

Page 9: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Answer Yes. A new mesagge for installing the driver will be shown:

Answer Yes and the driver will be installed. The program is now ready to work.

Page 10: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Software configuration. Start IcProg.exe Ø Hardware settings (mandatory):

Menú –> Settings -> Type of Hardware

Programmer -> JDM Programer Ports -> 1 or 2, depending on where we connected the serial cable. I/O retard -> 10 (we will decrease this value if we have problems). Interface -> we set it before. Communication -> All disabled. Click Ok. Ø Other settings (optional):

Menu –> Settings -> Options -> Confirmation tab We will check the desired options. Menu –> Settings -> Options -> Programming tab We will check “Verify”.

Page 11: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Programming the microcontroller

1. Select the device (microcontroller) to be programmed.

2. Open the code file to be written in the PIC.

Code is stored in the selected buffer. 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.

Page 12: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

3. Verifying the information.

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.

4. Programming the microcontroller

Clic the “Write all” button. Some messages will be shown: § Device writing confirmation (if enabled) § Writing code progress bar § Writing data progress bar § Writing configuration § Verifying code (if enabled) § Verifying data (if enabled)

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.

Page 13: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

and when the “Verification completed” message is shown, the PIC is successfully programmed. If we obtain a message like this:

it means that there’s an error in the first position. Most of times this is caused by a communications error.

Page 14: Programming a PIC

How to program a PIC microcontroller IOCards Project

By: Fernando Brea [email protected]

Errors solutions: General v Only one chip must be inserted in the programmer sockets v Erase the PIC before writing it v Close all other applications running on the PC

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 v Check the type of PIC. v Check Menu -> Settings -> Type of hardware. v Check the number of serial port selected. v Check that the file code (*.hex) is correct. It’s no good writing a *.txt file in the

PIC. 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: v Change the port v Use another PC v Try another programmer v Change the PIC

If everything fails, don’t worry. Look for your friends; at least one of them will be able to program your PIC.


Recommended