Sei sulla pagina 1di 8

Design Devices Boot Loader Enabled PIC Microcontrollers

User Guide
Revision B-1

PIC & MPLAB are registered trademarks of Microchip Technology Inc.

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Overview
The PIC16F87X series microcontrollers from Microchip (www.microchip.com) feature flash based program memory. The flash program memory can be written by running code allowing the devices to be re-programmed in process without an expensive EEPROM programmer. The Design Devices boot loader enabled PIC16F876/7 microcontrollers contain a special program that resides in the upper 255 instructions of program memory. This special program executes when the microcontroller is powered on or reset. The program checks the B5 input pin and if it is high it begins to read a MPLAB hexfile program and writes it to user program memory. The hexfile data is uploaded using the microcontrollers SSP serial interface with the help of a special DOS upload program called loader.exe. If the B5 input pin is low the boot loader program transfers execution to the current user program in flash memory.

Programming
This section describes how to setup the PIC on a breadboard for programming. Design devices also offers a programming and development board that includes the complete breadboard circuit described in this section. If you are using our boot loader enabled PIC with the development board you can skip to the Testing your Circuit and Program Uploading sections. To program the microcontrollers they first need to be setup on a breadboard according to the schematic shown below.

Breadboard Tips
It is very important when setting up a breadboard project to keep the oscillator as close to the microcontroller as possible. A ceramic resonator has three pins with the ground pin in the center. The oscillator connections on the PIC16F876 are pins 8, 9 & 10 with pin 8 being ground (pins 12, 13 & 14 on the PIC16F877). Because the pins on the ceramic oscillator and the PIC dont match up well and the leads on most oscillators are not long enough to orient the component perpendicular relative to the PIC an oscillator socket used. We have found that cutting 3 pins off of a wire wrap DIP socket makes a nice custom resonator socket that works well with breadboard. Using a socket such as this will allow you to properly orient the oscillator close to the processor. Be very careful that that +5 volt regulator IC is properly connected. If it is reversed you will introduce a voltage higher than +5 volts into the circuit and destroy both the PIC and the MAX232 ICs. Make sure you have wired the proper pins on the PIC to ground and +5 volts. If these connections are reversed you may also damage the devices. See the schematic for details. The regulator will get warm if you use a high supply voltage. If you find it gets too warm you may want to add a simple heat sink to it. To keep the temperature down you can also use a lower supply voltage, however, it should be at least 6 volts. A +5 volt regulator can also get very warm if it goes into oscillation. To prevent this put the .1uf filter capacitor (C2 in the schematic) tied between Vout and ground close to the regulator itself on the breadboard.

Page 2 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Boot Loader Enabled PIC16F876 Schematic


R1 4.7K U1 PIC16F876 1 8 9 O1 10 18 17 20 19 + 26 C3 1uf + 1 3 11 9 4 5 14 8 6 15 16 2 C5 1uf + C6 1uf + Upload R2 4.7K U3 Rx Tx

Reset

C4 1uf

GND

MAX232 GND + 6-12 VDC 47uf + C1 U2 GND 7805 Vin Vout Gnd .1uf C2 Rx Tx
1 6 2 7 3 8 4 9 5

DB9

Note The Design Devices Programmer and Development Board implements this circuit. See Appendix B

Parts List U1 U2 C1 C2 R1, R2 O1 U3 C3-C6 Design Devices Boot Loader Enabled Microchip PIC16F876 (Part No. PIC876) LM7805 or LM340T5 (Digikey LM340T-5.0-ND) 100uf 50v Electroylic Capacitor (Available at Radio Shack) .1uf Ceramic Capacitor (Available at Radio Shack) 4.7 K Ohm Watt Resistor (Available at Radio Shack) 20 MHz ceramic resonator (Digikey X909-ND) MAX232 (Digikey 296-1402-5-ND) 1uf 50v Electrolyic Capacitor (Available at Radio Shack)

You will also need a 6-12 volt DC power adapter or 6 volt battery, a standard male-female DB9 RS232 cable and, optionally, a female DB9 breadboard socket (see Testing Your Circuit). Digikey: www.digikey.com (1-800-DIGI-KEY)

Page 3 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Boot Loader Enabled PIC16F877 Schematic

R1 4.7K U1 PIC16F877 1 12 13 O1 14 26 25 32 31 + 38 C3 1uf + 1 3 11 9 4 5 14 8 6 15 16 2 C5 1uf + C6 1uf + Upload R2 4.7K U3 Rx Tx

Reset

C4 1uf

GND

MAX232 GND + 6-12 VDC 47uf + C1 U2 GND 7805 Vin Vout Gnd .1uf C2 Rx Tx
1 6 2 7 3 8 4 9 5

DB9

Note The Design Devices Programmer and Development Board implements this circuit. See Appendix B

Parts List U1 U2 C1 C2 R1, R2 O1 U3 C3-C6 Design Devices Boot Loader Enabled Microchip PIC16F877 (part no. PIC877) LM7805 or LM340T5 (Digikey LM340T-5.0-ND) 100uf 50v Electroylic Capacitor (Available at Radio Shack) .1uf Ceramic Capacitor (Available at Radio Shack) 4.7 K Ohm Watt Resistor (Available at Radio Shack) 20 MHz ceramic resonator (Digikey X909-ND) MAX232 (Digikey 296-1402-5-ND) 1uf 50v Electrolyic Capacitor (Available at Radio Shack)

You will also need a 6-12 volt DC power adapter or 6 volt battery, a standard male-female DB9 RS232 cable and, optionally, a female DB9 breadboard socket (see Testing Your Circuit).

Digikey: www.digikey.com (1-800-DIGI-KEY)

Page 4 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Testing Your Circuit


Once you have your circuit setup on the breadboard or Design Devices development board you can test your circuit by running the included example program. A complete MPLAB project for the example program can be found in the Example folder on the included floppy disk. This program has been uploaded to the microcontroller for testing purposes. The code defines pin 2 on both the PIC16F877 and PIC16F876 as an output to be used for a debug LED. To add an LED to the circuit connect its anode (long lead) to this pin though a 1k resistor and its cathode to ground. When the user code runs it will set this pin high and light the LED. This is very helpful to determine if the PIC is executing user code or boot loader code. Do the following to test the circuit: 1. Power up the circuit. 2. Connect the breadboard to an available PC serial port. The easiest way to do this is to cut the male end off a standard female-to-male DB-9 serial cable and insert the proper wires into the breadboard. Use an ohmmeter to figure out which wire is connected to each pin. 3. From Windows 95/98/NT/2000 bring up a DOS window. Do this by selecting Start and then Run... Type command in the popup window and click on OK (on Windows NT type cmd). 4. Insert the included floppy disk. In the DOS window type a:\programs\term.exe. This program will default to COMM port 1 at 9600 baud. If you need to use another COMM port please see the Appendix A for a complete description of the options available with this program. The boot loader code only communicates at 9600 baud. 5. Depress the microcontroller reset switch on the breadboard. 6. The debug LED should turn on and you should the following text in your DOS window: PIC16F877 Boot Loader Example Last key pressed was ? Every key you type will be echoed back to the term program and also saved in flash memory on the PIC. If you power cycle or depress the reset switch you will see that the last character you typed has been saved and printed out in the Last key pressed was __ message. If the debug LED does not turn on or you see garbage characters in your DOS window try depressing the reset switch slowly. If that does not help make sure your breadboard wiring is correct and you have the ceramic resonator close to the processor. If you still have problems make sure you are using the correct COMM port.

Program Uploading
The boot loader enabled microcontrollers are programmed using the loader.exe program located on the floppy disk in the programs folder. To make things easier you should copy this program from the floppy disk to the C:\Windows directory on your PC (C:\WINNT\System32 for Windows NT). Alternatively, you could copy this program to any directory on your PC that is part of your existing PATH environment variable. You could also create a new directory to place the loader.exe program and add that directory to your PATH environment variable.

Page 5 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

To program the PICs you will need MPLAB or a similar product that creates a PIC hexfile from assembly code. For demonstration purposes we will use the example MPLAB project on the included floppy disk. You can open the project in MPLAB directly from the floppy or move the example folder to another disk on your PC. If you move the folder you will have to edit the project and remove the example.asm node and add it again in the new location. Do this by opening the example.prj file, clicking on the Project menu and selecting Edit Project. In the project files section in the resulting popup window click on example [.asm] and click on the D elete Node button. Click on example [.hex] and click on the Add Node button. Browse to where you moved the example folder and select the example.asm file in that folder and click ok. See the MPLAB user guide for more details. Compile the program by going to the Project Menu and selecting Make Project. The project should compile with no errors, but a couple of messages warning you about crossing a page boundary. These messages are normal. To upload the hexfile to your PIC open up a DOS window, cd to your example directory. Run the loader.exe program in the DOS window with example.hex as the argument. Example: C:\example> loader.exe exmaple.hex The loader.exe program defaults to COMM1. If you need to use another COMM port please see the Appendix A for a complete description of the options available with this program. You should see the following after running loader.exe: Design Devices PIC16F876/7 Boot Loader Using comm port 1 at 9600 baud Waiting for microprocessor upload signal (Press ESC To Abort). At this point the loader.exe program is waiting for an upload ready signal from the PIC. On the breadboard hold down the upload pushbutton while depressing the reset pushbutton. You can release the upload pushbutton once you should then see the following in the DOS window: Press Y to program PIC or any other key to abort. When you press the y key on your PC the loader.exe program will upload the hexfile to the PIC. After the upload is complete connect pin 26 on the PIC16F876 or pin 38 on the PIC16F877 to ground through a 4.7K Ohm resistor and depress the reset switch again. The PIC will now be running the program you just uploaded. For information on how to use the serial and flash routines located in the boot loader code see the example.asm file. There are many comments in that assembly file that explain how this is done. Boot loader related programming information for these microcontrollers such as calling boot loader serial and flash routines and configuration bit information is also present in the example.asm file. Use this assembly file as a starting point for you project. If you have any comments, problems, suggestions or corrections to this document, please feel free to email them to support@designdevices.com.

Page 6 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Appendix A Loader.exe
Loader.exe is a program used to communicate to a Design Devices boot loader enabled PIC microcontroller. It is a simple program that can be run in a DOS window under Windows 95/98/NT. Available Options -p Sets the COMM port. Possible values are 1, 2, 3 or 4. . If the option is not present the program will use COMM port 1.

Example: A:\Programs> loader.exe p3 exmaple.hex Instructs the program to use COMM port 3. Known Bugs: 1. If you are having trouble attaching to the COMM port with another application even after you have terminated loader.exe you might try closing the DOS window you ran loader.exe in to free the port.

Term.exe
Term.exe is a program that sends and receives characters from a serial port. It can be used to test the Design Devices boot loader enabled PIC microcontrollers. Available Options: -p -s Sets the COMM port. Possible values are 1, 2, 3 or 4. If the option is not present the program will use COMM port 1. Sets the serial baud rate. Possible values are 2400, 4800, 9600, 19200, 38400, 57600, 115200. If the option is not present the program will use 9600 baud.

Example: A:\Programs > term.exe p3 Instructs the program to use COMM port 3. A:\Programs > term.exe p2 s4800 Instructs the program to use COMM port 2 and connect at 4800 baud. Known Bugs: 2. If you are having trouble attaching to the COMM port with another application even after you have terminated loader.exe you might try closing the DOS window you ran loader.exe in to free the port. NOTE the boot loader code assumes a communication speed of 9600 baud when reading a hexfile for device programming. User programs can change this speed and with the s option you can use this program to communicate with your PIC during for testing purposes.

Page 7 of 8

Boot Loader Enabled PIC User Guide Revision B-1

Copyright 2002 Design Devices All Rights Reserved

Appendix B
The Design Devices Boot Loader PIC Programmer and Development Board The PIC programming & development board supports our boot loader enabled PIC16F877/6 microprocessors by implementing the circuits shown in this manual. In addition to boot loader programming the board is an ideal platform for development work featuring numerous breadboard compatible tie points, replaceable oscillator, regulated power supply and complete serial conversion circuitry. This board can be used with other 40-pin and 28-pin PICs as a development platform.

This set of jumpers properly routes power and serial to 28-pin PICs. Jumper all 3 sets of these pins only when using 28-pin PICs (remove the jumpers from the 40-pin set).

This set of jumpers properly routes power and serial to 40-pin PICs. Jumper all 4 sets of these pins only when using 40-pin PICs (remove the jumpers from the 28-pin set).

Boot loader upload switch connected to pin B5 on the PICs. See manuals section on programming.

28-pin Oscillator Socket Socket for ceramic oscillator for 28-pin PICs (PIC876)

PIC reset switch which grounds MCLR pin.

RS232 Serial Connector Use a straight through RS232 cable with all pins connected.

DC Power Connector 6-12 volts 1A

DC power connector polarity configuration Jumpers. These jumpers allow you to connect positive or negative on the board to the tip of the power jack (labeled T) and positive or negative on the board to the ring of the power jack (labeled R). Arrange the jumpers according to your AC adapter (factory configured for center positive adapters). If you are using battery power connect the battery directly to the + and labeled pins. The DC supply should be between 6 and 12 volts and should be able to supply 1 amp (or at least as much current as your circuit requires).

40-pin Oscillator Socket Socket for ceramic oscillator for 40-pin PICs (PIC877)

TTL Level Serial Breadboard compatible tie points for Rx, Tx, RTS and CTS serial channels.

5 Volt Regulated Supply Breadboard compatible tie points for 5-volt power supply and ground.

Page 8 of 8

Potrebbero piacerti anche