Difference between revisions of "Programming PIC Microcontrollers"
From PHCC
(→PIC programmer) |
(→PIC programmer) |
||
(One intermediate revision by the same user not shown) | |||
Line 15: | Line 15: | ||
The PIC programmer is a little piece of hardware to transfer the firmware from your computer to your PIC microcontroller. There are many kinds available and these are most of the time only able to program Microcontrollers of one specific brand. Since the PHCC uses the Microchip PICs I will only focus on these. When trying to find a programmer that will suit the job, also check if it is capable of programming the specific model of the Microcontroller family. Since there are too many programmers out there they all rely on some of the basic designs with sometimes a few modifications. I recommend to use a JDM programmer, because it is cheap and doesn't require any external power source and is driven directly of the serial port (requires one on your PC though). If you don't have a serial port there are also parallel port programmers, which most of the time require a external power source. This will increase costs most of the time since the programmers often need a not so common supply voltage. Some, on the other hand, sometimes also work with a different supply voltage then the specified one. Also USB solutions excist but these are a bit more expensive. ''(NOTE from John: I picked up a USB JDM programmer for 35 USD on eBay.)'' The JDM programmer comes in various shapes and sizes but basically all work the same and are widely supported by most of the available (free) software. A good source is ebay, just search for JDM programmer. | The PIC programmer is a little piece of hardware to transfer the firmware from your computer to your PIC microcontroller. There are many kinds available and these are most of the time only able to program Microcontrollers of one specific brand. Since the PHCC uses the Microchip PICs I will only focus on these. When trying to find a programmer that will suit the job, also check if it is capable of programming the specific model of the Microcontroller family. Since there are too many programmers out there they all rely on some of the basic designs with sometimes a few modifications. I recommend to use a JDM programmer, because it is cheap and doesn't require any external power source and is driven directly of the serial port (requires one on your PC though). If you don't have a serial port there are also parallel port programmers, which most of the time require a external power source. This will increase costs most of the time since the programmers often need a not so common supply voltage. Some, on the other hand, sometimes also work with a different supply voltage then the specified one. Also USB solutions excist but these are a bit more expensive. ''(NOTE from John: I picked up a USB JDM programmer for 35 USD on eBay.)'' The JDM programmer comes in various shapes and sizes but basically all work the same and are widely supported by most of the available (free) software. A good source is ebay, just search for JDM programmer. | ||
− | Another option is to build one yourself. The following link describes how and provides schematics and layouts for the THVP programmer. [http://projects.varxec.net/thvp [THVP programmer]] | + | Another option is to build one yourself. The following link describes how and provides schematics and layouts for the THVP programmer. [http://projects.varxec.net/thvp [THVP programmer]] or for a USB solution go to [http://www.mcuhobby.com/articles.php?article_id=7[PICKit2 clone]] |
=== Software === | === Software === |
Latest revision as of 10:30, 22 October 2009
Programming PIC Microcontrollers
On request the following is a short tutorial on how to prepare your firmware and program a PIC microcontroller. First a list of required items:
- PIC programmer
- Programming software
- Compiler
- Firmware assembly file or HEX file
- PIC Microcontroller/processor
- PC (preferred with RS-232 port)
PIC programmer
The PIC programmer is a little piece of hardware to transfer the firmware from your computer to your PIC microcontroller. There are many kinds available and these are most of the time only able to program Microcontrollers of one specific brand. Since the PHCC uses the Microchip PICs I will only focus on these. When trying to find a programmer that will suit the job, also check if it is capable of programming the specific model of the Microcontroller family. Since there are too many programmers out there they all rely on some of the basic designs with sometimes a few modifications. I recommend to use a JDM programmer, because it is cheap and doesn't require any external power source and is driven directly of the serial port (requires one on your PC though). If you don't have a serial port there are also parallel port programmers, which most of the time require a external power source. This will increase costs most of the time since the programmers often need a not so common supply voltage. Some, on the other hand, sometimes also work with a different supply voltage then the specified one. Also USB solutions excist but these are a bit more expensive. (NOTE from John: I picked up a USB JDM programmer for 35 USD on eBay.) The JDM programmer comes in various shapes and sizes but basically all work the same and are widely supported by most of the available (free) software. A good source is ebay, just search for JDM programmer.
Another option is to build one yourself. The following link describes how and provides schematics and layouts for the THVP programmer. [THVP programmer] or for a USB solution go to [PICKit2 clone]
Software
To load the firmware to the PIC you also need software that will run from your PC. There are many free software tools around, but I recommend using PICpgm. It is easy to use and has autodetect which will find your type of programmer and the Microcontroller model automatically. http://members.aon.at/electronics/pic/picpgm/
Check if autodetect was succesfull by checking the device info for the correct PIC model. It is as easy as loading your HEX file from disk and press the program button (yellow lightning) and if all goes well you will get a message that programming was succesfull. It normally takes only a few seconds to program the PIC.
Compiler
In case you want to code your own firmware or make adjustments to existing firmware you need to have a compiler which will output your source code to a HEX file which can be loaded onto the MC. Microchip provides a free suite called MPLAB which includes an IDE (which goes beyond the scope of this tutorial) where you can develop your own firmware code. It also contains a compiler called MPASMWIN which can compile your .asm source files to HEX files.
Make sure the settings are the same as in the picture, except with your own .asm loaded. PHCC works with a bus system called DOA and DOB (daisy chained output modules) that makes use of an unique address for each output board you connect to it. You define the unique address in the extra options textbox. Leave everything as in the picture except change the 2 digits after 0x. As many of you probably noticed the address is given in hex digits. PHCC can handle 256 devices per bus so define an unique address between 0x00 and 0xFF. After everything is set, press assemble and your HEX file will be created in the same directory your .asm file is in. The compiler will tell you if the procedure was succesfull and if not will create a error log (yourfilename.err) in the same directory. The error log will tell you of any errors in the .asm source file, indicated with linenumbers from your source for each error. Even if the procedure was succesfull most of the time a error log is still created. You can leave this as it is and don't have to pay attention to it, everything is normal. Now your HEX file is ready to be loaded onto the PIC.
Credit: Danny "Ghost" Faber, Viperpits.org, http://www.viperpits.org/smf/index.php?topic=3995.0