1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
|
<HTML>
<HEAD>
<TITLE>Jaakko Hyvätti Picprog 1.8.3 documentation</TITLE>
<LINK REV="made" HREF="mailto:Jaakko.Hyvatti@iki.fi">
</HEAD>
<BODY>
<script type="text/javascript"><!--
google_ad_client = "pub-2183881206321181";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>
<A HREF="http://www.iki.fi/hyvatti/pic/picprog.html">http://www.iki.fi/hyvatti/pic/picprog.html</A>
</p>
<HR>
<H1>Jaakko Hyvätti Picprog 1.8.3 documentation</H1>
<P ALIGN="right">2006-09-28</P>
<P>PIC16 and PIC18 microcontroller programmer for Linux and Windows/Cygwin.</P>
<P>
Translations of some version of this document: <a href="http://mbtronics.homelinux.org/picprog.html">Dutch</a>
</P>
<OL>
<LI><A HREF="#1">Background reading</A>
<LI><A HREF="#2">Requirements</A>
<LI><A HREF="#3">Hardware</A>
<LI><A HREF="#4">Installation</A>
<UL>
<LI><A HREF="#4-1">Linux</A>
<LI><A HREF="#4-2">Windows/Cygwin</A>
</UL>
<LI><A HREF="#5">Usage</A>
<LI><A HREF="#6">Burning PICs</A>
<LI><A HREF="#7">Reading PICs</A>
<LI><A HREF="#8">Exit values</A>
<LI><A HREF="#9">Internals</A>
<LI><A HREF="#10">Changes</A>
<LI><A HREF="#11">Other available programmers</A>
<LI><A HREF="#12">Available languages</A>
<UL>
<LI><A HREF="#12-1">Free compilers</A>
<LI><A HREF="#12-2">Commercial demos</A>
</UL>
<LI><A HREF="#13">Other software</A>
<LI><A HREF="#14">History</A>
<LI><A HREF="#15">Copyright notice</A>
</OL>
<P>
PICmicro microcontrollers, or MCUs, are fine chips that are especially
easy to program with a simple device attached to a parallel or serial
port. Because of the EEPROM or Flash memory, they are also easy and
fast to erase and reprogram without need for UV equipment. This makes
them very popular among electronics hobbyists.
</P>
<P>
At the moment this is the second implementation of a PIC programmer
for Linux that works with the very simple and cheap serial port
programmers. The first one I know was made by <A
HREF="http://www.rjkm.de/rjkm.html">Ralph Metzler</A> in 1996. My
programmer was originally designed for PIC16C84 and PIC16F84 chips
back in 1997, and since then I have implemented other chips without
access to most of them. I have tested PIC16F628, PIC16F676,
PIC12F675, PIC16F88, PIC16F876A, PIC16F76, PIC18F1320 and PIC18F458.
Others have used many other models. The dsPIC30 family has some code
in the sources, but the support is not finished yet.
</P>
<H2><A NAME="1">1. Background reading</A></H2>
You really should take a look at the <A
HREF="http://www.microchip.com/">Microchip www-pages</A> and read the
device datasheets and programming specifications there. <P>
Maybe the best source for PIC information is <A
HREF="http://www.piclist.com">the home page of PICLIST</A> discussion
group. Also historically a good collection of links and software for
PIC was in <A HREF="http://www.man.ac.uk/~mbhstdj/">David Tait's</A>
PIC links page and in <A HREF="http://www.gnupic.org/">GNUPIC</A>
pages. I have also documented here the software I took a look at back
in 1997. I have focused into Linux support, so I have never used
any DOS software mentioned.
<H2><A NAME="2">2. Requirements</A></H2>
<DL>
<DT> Serial port pic programming hardware
<DD> See the hardware section. This device is connected to a usual
serial port of your PC, and is the same device as used with many DOS
PIC burning programs.
<DT> C++ compiler (g++)
<DD> This program is written in C++, so you need a C++ compiler to
compile it. This you should already have installed on your Linux
system or Windows/Cygwin system.
<DT> Linux kernel version 2.0.32 or 2.1.45 or later.
<DD> This programmer needs some functionality in Linux serial driver
that as of kernel versions 2.0.32 and 2.1.45 is available in standard
kernels. The programmer uses TIOCSBRK and TIOCCBRK ioctl to control
the state of TxD serial port output accurately. These ioctl's are
standard on BSD flavor unixes, like SunOS 4, but they still are
unimplemented on many serial drivers in Linux kernel. Only the
standard serial port is known to work by me.
<DT> Cygwin DLL version 1.5.8 or later
<DD> (For Windows installations only) Earlier Cygwin versions do not
contain the necessary TIOCSBRK and TIOCCBRK ioctl functionality.
<DT> A compiler for PIC
<DD> Your assembler, or C compiler, or whatever, should produce either
Intel IHX32, IHX16, or IHX8M format hex files. For assembler on Linux I
recommend <A HREF="http://gputils.sourceforge.net/">GNU PIC
Utilities</a> gpasm.
</DL>
<H2><A NAME="3">3. Hardware</A></H2>
Use a serial port programmer device with the following pinouts:
<DL>
<DT> TxD
<DD> Programming voltage, pin /MCLR
<DT> RTS
<DD> Clock pulse, pin RB6
<DT> DTR (output), CTS (input)
<DD> Serial data, pin RB7
</DL>
A good programmer like this is for example <A
HREF="http://www.jdm.homepage.dk/newpic.htm">PIC-Programmer 2</A>
designed by <A HREF="http://www.jdm.homepage.dk">Jens Madsen</A>.
Some later chips with internal oscillator modes may need a bit more
complicated designs or the reprogramming of the chips can be
unreliable. See <a
href="http://users.tpg.com.au/btkelly/jdm_b.htm">JDM-B: JDM Programmer
Modification: Automatic Vcc Control</a> or <a
href="http://feng3.cool.ne.jp/en/rcd.html">RCD programmer</a>.
I have heard that other programmers work also, for example <a
href="http://web.zackyfiles.com/secciones/programadores/te20.htm">TE20</a>
and <a href="http://www.olimex.com/">Olimex PG2C</a> have been tested
with Picprog.
</P>
<P>
The description below is based on old version of JDM hardware. As you
can see above, there are better designs by Jens Madsen and others
available, please use them instead. Note however that for example the
latest Jens Madsen PCB does not support PIC16F628A that needs to have
pin 10, RB4/PGM grounded. Please modify the PCB to ground this pin if
your chip has PGM on pin 10.
</P>
<P>
I made a minor modification to the jdm84v23 schema and pcb mask,
because I thought D4 was stressed on positive clock pulses - it short
circuits the rs-232 RTS pin to GND. I added a 10k resistor between D4
and D3. But it also is not absolutely required, as the clock pulses
are short and rs-232 is protected for short circuits anyway. Now I
have noticed that this resistor makes the programmer less reliable,
especially with later PIC chips, like PIC16F76 and PIC18 family. If
you have built the hardware I previously suggested, and it does not
work, please short circuit that resistor or build the new PCB from
Jens Madsen site. Also you can try this patch by Matthijs Kooijman to
test the levels of signals: <a
href="http://www.iki.fi/hyvatti/pic/picprog-slow-test.diff">picprog-slow-test.diff</a>
</P>
<P>
To support for example PIC16F628 and PIC16F88, which have a low
voltage programming mode, the circuit was again modified to ground the
RB3 pin 9 and the RB4 pin 10. This prevents the chip from entering
the low voltage programming mode. To support for example PIC12F675,
PIC16F630, and PIC16F676, pin 1 was connected to Vdd. Other jumpers
need to be installed as described below.
</P>
<P>
The schemantics diagram:<BR> <A HREF="jdm84ne3.png"><IMG
SRC="jdm84ne3.png" ALT="jdm84ne3.png" BORDER="0" WIDTH="478"
HEIGHT="285"></A>
</P>
<P>
The 300 dpi pcb mask:<BR> <A HREF="jdm84pcb6.png"><IMG
SRC="jdm84pcb6.png" ALT="jdm84pcb6.png" BORDER="0" WIDTH="515"
HEIGHT="380"></A>
</P>
<P>
To support for example PIC16F876A and 16F76, which have different
pinouts for programming signals, you need an adapter that connects to
the external connector of the above programmer. Alternatively you
could redesign the pcb layout, but maybe it is easier to just solder
the adaptor. Solder the pins like this:
<PRE>
pcb 1 -- clk -- 27 (RB6) ic
connector 3 -- data -- 28 (RB7) socket
5 -- Vss -- 8,19,24
7 -- Vdd -- 20
9 -- Vpp -- 1
</PRE>
</P>
<p>
To support for example PIC12F675, PIC16F630 and PIC16F676, which have
different pinouts for programming signals but do not conflict with
PIC16C84 pins, you can solder jumper wires on the above pcb. You need
to connect pin 16 on the socket to clock (same as pin 12), pin 17 to
data (same as pins 11 and 13), and pin 18 on the socket to Vss (same
as pins 5-10). Note that pin 1 is already connected to Vdd in the
above PCB mask. If this connection is missing on your older PCB,
connect pin 1 to pin 14 with a wire.
</p>
<p>
Always check the correct pinouts for your chip from the datasheets
also!
</p>
<H2><A NAME="4">4. Installation</A></H2>
<H3><A NAME="4-1">Linux</A></H3>
<p>
There are binary packages available that have been prepared by helpful
users and operating system vendors. I know of the following, but
cannot offer any support for them. They might be for older versions,
but even if they are, check for the <a href="#10">10. Changes</a>
section below if you really need a later version. Some new versions
of Picprog only fix small specific bug, which may not affect you at
all.
<ul>
<li><a href="http://www.freebsd.org">FreeBSD</a> includes Picprog port.
</li>
<li><a href="http://www.gentoo.org">Gentoo</a> has Picprog as a package.
</li>
<li>Jan Wagemakers made a <a
href="http://www.janw.dommel.be/picprog.html">Debian package</a>.
</li>
</ul>
</p>
<p>
To install from source, download the <A
HREF="http://www.iki.fi/hyvatti/pic/picprog-1.8.3.tar.gz">picprog-1.8.3.tar.gz</A>
package, if you do not already have it. </P>
<p>
Check your system against the requirements mentioned above. </P>
<p>
Untar the archive and change to the source file directory. You should
only have to type:
<PRE>
make dep
make
</PRE>
and the program should compile without errors or warnings. If it does
not, please check that your compiler, c and c++ libraries and
utilities like make are of a reasonably recent, bugfree and compatible
version.
</P>
<p>
After compilation you can, as a root user, just type:
<PRE>
make install
</PRE>
to install the program and manual page to /usr/local. Or just copy
the files <CODE>picprog</CODE> and <CODE>picprog.1</CODE> manually.
</p>
<p>
Make sure that you have access to the serial port device like /dev/ttyS0
or /dev/ttyS1 with the user that you are running the program as.
</p>
<H3><A NAME="4-2">Windows/Cygwin</A></H3>
<p>
The Linux emulator for Windows, <a
href="http://www.cygwin.com">Cygwin</a>, allows Picprog to be
compiled on Windows plattforms.
</p>
<p>To install Cygwin, go to <a
href="http://www.cygwin.com">www.cygwin.com</a> and follow the
instructions there. In short, download <a
href="http://www.cygwin.com/setup.exe">setup.exe</a> and run it. You
need to install at least the Developer packages Gcc C compiler, Gcc
C++ compiler, Make, and Binutils in addition to the default install.
</p>
<p>
To install Picprog on Cygwin, follow the above instructions for Linux compilation from source.</p>
<p>
Windows 2000 installations that I have tried work fine. Windows 98
installations worked sometimes, and I suppose the timing routines of
Picprog do not work well on Windows 98, they even lock the computer
sometimes. I suggest using Windows 2000 or later.
</p>
<H2><A NAME="5">5. Usage</A></H2>
To get information about the usage of the program, just type the
program name. These options give information about the program:
<DL>
<DT> <CODE>--warranty</CODE>, <CODE>--copyright</CODE>, <CODE>--help</CODE>
<DD> Display warranty or copyright information or the help text
with list of supported chip types.
<DT> <CODE>--quiet</CODE>, <CODE>-q</CODE>
<DD> Do not display the copyright notice.
</DL>
The actual operation of the program is controlled by the options
<CODE>--input-hexfile</CODE> and <CODE>--output-hexfile</CODE>. If
the former is present, the program acts as a burner. If the
latter is specified, the program will read the contents of the PIC
device eeprom memories. Both may be specified on the same command
line, in which case the chip is first programmed and then read.
<H2><A NAME="6">6. Burning PICs</A></H2>
Simple instructions:
<OL>
<LI> Compile your program into a hex file.
</LI>
<LI> Insert the pic16c84 or other pic chip into the socket in the
programmer, or connect the in-circuit programming cable to your
device.
</LI>
<LI> Connect the programmer device to a serial port.
</LI>
<LI> If the device contains calibration information, like OSCCAL word
in program memory or BG bits in configuration word in PIC12F675, it is
a good idea to save these for later if this is the first time you
program the chip. See <a href="#7">next chapter</a> for more on
reading chip, but this should be enough for saving the calibration:
<PRE>
picprog --output saved-cal-chip1.hex --skip-ones --pic /dev/ttyS1
</PRE>
</LI>
<LI> Burn the program with command:
<PRE>
picprog --burn --input file.hex --pic /dev/ttyS1
</PRE>
</LI>
<LI> If the above command produces error output that suggests that the
chip was in the code protection state, or that the chip must be
completely erased before programming, retry with the following
command:
<PRE>
picprog --erase --burn --input file.hex --pic /dev/ttyS1
</PRE>
</LI>
<LI> Wait for the program to complete. Burning 8192 program locations
on 14 bit devices may take 3 minutes. I know better programming
algorithms would speed this up significantly, but I have not had time
to fix that. PIC18 family programming algorithm is significantly
faster. </LI>
</OL>
The burning options are:
<DL>
<DT> <CODE>--erase</CODE>
<DD> To be able to reprogram a PIC device that has previously been
programmed into Code Protection state (for example in pic16c84 Control
Word fuse bit 0x10 cleared), it is necessary to bulk erase the chip.
Also some PIC devices do not automatically erase each location as they
are programmed, and these devices must always be bulk erased first.
It is done by adding this option to the command line. The default is
not to bulk erase the chip.
<DT> <CODE>--burn</CODE>
<DD> Actually program the device. Without this option only the syntax
of input files and command line options is checked.
<DT> <CODE>--input-hexfile</CODE> <EM>path</EM>, <CODE>-i</CODE> <EM>path</EM>
<DD> Specifies the input hex file. The file can be either in IHX32,
IHX16, or IHX8M formats, the format is automatically recognized.
<DT> <CODE>--cc-hexfile</CODE> <EM>path</EM>, <CODE>-c</CODE> <EM>path</EM>
<DD> Only necessary for debugging. Outputs the same data as was read
from the input hex file.
<DT> <CODE>--force-calibration</CODE></DT>
<DD> Force reprogramming the OSCCAL word and BG bits in control word.
Default is to read the calibration values off the chip before erasing
and preserving their values. Use this option if you have accidentally
erased the values on chip, and you reprogram them from your saved copy
which was read off the chip before the values were lost there. In
general it is a really good idea to first read the empty chip and save
the file somewhere if the calibration data gets lost later, either by
accident or because of some bug in Picprog.</DD>
<DT> <CODE>--pic-serial-port</CODE> <EM>device</EM>, <CODE>-p</CODE> <EM>device</EM>
<DD> The device name of the serial port the programmer is connected
to. Default is <CODE>/dev/ttyS0</CODE>.
<DT> <CODE>--device</CODE> <EM>chipname</EM>, <CODE>-d</CODE> <EM>chipname</EM>
<DD> The chip type. Currently supported by code are:
<br />
auto, pic16c84, pic16cr83, pic16cr84, pic16f83, pic16f84, pic16f84a*,
pic16f87*, pic16f88*, pic16c61, pic16c62, pic16c62a, pic16c62b,
pic16c63, pic16c63a, pic16c64, pic16c64a, pic16c65, pic16c65a,
pic16c65b, pic16c66, pic16c66a, pic16c67, pic16cr62, pic16cr63,
pic16cr64, pic16cr65, pic16c620, pic16c620a, pic16cr620a, pic16c621,
pic16c621a, pic16c622, pic16c622a, pic16f627*, pic16f627a*,
pic16f628*, pic16f628a*, pic16f648a*, pic16ce623, pic16ce624,
pic16ce625, pic16c641, pic16c642, pic16c661, pic16c662, pic16c71,
pic16c710, pic16c711, pic16c712, pic16c715, pic16c716, pic16c717,
pic16c72, pic16c72a, pic16cr72, pic16c73, pic16c73a, pic16c73b,
pic16c74, pic16c74a, pic16c74b, pic16c76, pic16c77, pic16f72*,
pic16f73*, pic16f74*, pic16f76*, pic16f77*, pic16c432, pic16c433,
pic16c781, pic16c782, pic16c745, pic16c765, pic16c770, pic16c771,
pic16c773, pic16c774, pic16f870*, pic16f871*, pic16f872*, pic16f873*,
pic16f873a*, pic16f874*, pic16f874a*, pic16f876*, pic16f876a*,
pic16f877*, pic16f877a*, pic16f818*, pic16f819*, pic16c923, pic16c924,
pic16f630*, pic16f676*, pic12c508, pic12c508a, pic12ce518, pic12c509,
pic12c509a, pic12ce519, pic12cr509a, pic12c671*, pic12c672,
pic12ce673, pic12ce674, pic12f629*, pic12f675*, pic16c505, pic18f242*,
pic18f248*, pic18f252*, pic18f258*, pic18f442*, pic18f448*,
pic18f452*, pic18f458*, pic18f1220*, pic18f2220*, pic18f4220*,
pic18f1320*, pic18f2320*, pic18f4320*, pic18f6520*, pic18f6620*,
pic18f6720*, pic18f8520*, pic18f8620*, pic18f8720*, pic18f6585*,
pic18f8585*, pic18f6680*, pic18f8680*, pic18f2515*, pic18f2525*,
pic18f2585*, pic18f4515*, pic18f4525*, pic18f4585*, pic18f2610*,
pic18f2620*, pic18f2680*, pic18f4610*, pic18f4620*, pic18f4680*,
pic18f6525*, pic18f6621*, pic18f8525*, pic18f8621*, pic18f2439*,
pic18f2539*, pic18f4439*, pic18f4539*, pic18f2331*, pic18f2431*,
pic18f4331*, pic18f4431*, pic18f2221*, pic18f2321*, pic18f2410*,
pic18f2420*, pic18f2450*, pic18f2455*, pic18f2480*, pic18f2510*,
pic18f2515*, pic18f2520*, pic18f2525*, pic18f2550*, pic18f2580*,
pic18f2585*, pic18f2610*, pic18f2620*, pic18f2680*, pic18f4221*,
pic18f4321*, pic18f4410*, pic18f4420*, pic18f4450*, pic18f4455*,
pic18f4480*, pic18f4510*, pic18f4515*, pic18f4520*, pic18f4525*,
pic18f4550*, pic18f4580*, pic18f4585*, pic18f4610*, pic18f4620*,
pic18f4680*, pic18c242, pic18c252, pic18c442, pic18c452, pic18c658,
and pic18c858.
<br />
The devices marked with a star (*) can be autodetected, so they need
not to be specified. If code protection is active on the chip,
autodetection may not work.
</p>
<p>
I do not know if all the chips work or if any other than pic16c84,
pic12f675, pic16f676, pic16f76, pic16f88, pic16f876a, pic16f628,
pic18f1320, and pic18f458 work, these I have tested myself. Default
is to autodetect the device by reading configuration memory location
0x2006. If no device id is present, the default is
<CODE>pic16c84</CODE>. If reading location 0x2006 with 14 bit
programming algorithm fails, the PIC18 programming algorithm is used
to read configuration memory locations 0x3ffffe and 0x3fffff. To add
a new supported chip type, just edit the table in file
<CODE>hexfile.cc</CODE>. </DL>
The hex file addresses (in IHX16 format) used are the ones specified
by Microchip. This example is for pic16f628:
<DL>
<DT> 0x0000-0x07FF
<DD> Program memory, 2048 words * 14 bits.
<DT> 0x2000-0x2003
<DD> ID locations.
<DT> 0x2006
<DD> Device id (not present on older chips), not present in hex file
<DT> 0x2007
<DD> Control word fuses
<DT> 0x2100-0x217F
<DD> Data memory, 128 bytes * 8 bits.
</DL>
The addresses in IHX32 and IHX8M files are not word addresses but byte
addresses. Divide those addresses by 2 and you get the same addresses
as in the example above.
</p>
<p>
This example is for pic18f1320. These addresses are byte addresses.
IHX32 is the only option for saving PIC18 family programs in hex
files.
<DL>
<DT> 0x000000-0x001fff
<DD> Program memory, 8192 bytes of 8 bits, or 4096 words of 16 bits.
<DT> 0x200000-0x200007
<DD> ID locations.
<DT> 0x3ffffe-0x3fffff
<DD> Device id, not present in hex file
<DT> 0x300000-0x30000d
<DD> Control word fuses
<DT> 0xf00000-0xf000ff
<DD> Data memory, 256 bytes * 8 bits.
</DL>
</P>
<p>
Before interfacing with the PIC chip, Picprog calibrates its delay
loops by checking the clock speed of the CPU and whether the CPU
supports the TSC feature. On Linux, /proc/cpuinfo is read. On
Windows/Cygwin, /proc/cpuinfo is read and CPU clock frequency is
estimated. Therefore the clock frequency displayed on Windows is not
necessarily exactly the true clock frequency.
</p>
<p>
Long cables, different values on capacitors and resistors, and
differences on sertial ports can cause very long signal rise and fall
times. The JDM device is sensitive to that, and mostly is designed to
be connected directly to computer or with very short cable. The
sensitivity also depends on the PIC chip type. It may help to stretch
the delays in Picprog to allow for longer signal settling times.
Larger delays are needed also for <a
href="http://www.semis.demon.co.uk/uJDM/uJDMmain.htm">the uJDM
programmer device</a>. A couple of options are available. They can
be tried individually and together:
<DL>
<DT> <CODE>--rdtsc</CODE> </DT>
<DD>
Uses the CPU's TSC capability, cycle counter, to measure time delays.
This is the most accurate way of measuring time, and gives you the
fastest programming. However, this may not work with all latest
CPU's, laptops, and other variable clock rate computers.
</DD>
<DT> <CODE>--nordtsc</CODE> </DT>
<DD>
Ignores the CPU's TSC capability. Try this if the programmer does not
work. This is the default setting now. It is a bit slower than
--rdtsc, but works more reliably on current fast computers.
</DD>
<DT> <CODE>--slow</CODE> </DT>
<DD>
Slow down the delay loops by factor of 10. Try this if the programmer
does not work without it.
</DD>
</DL>
<p> Old patches to solve the timing problem were made available by Werner Almesberger:
<a href="http://www.iki.fi/hyvatti/pic/picprog-1.7-werner-almesberger.diff">picprog-1.7-werner-almesberger.diff</a>,
and by Matthijs Kooijman:
<a href="http://www.iki.fi/hyvatti/pic/picprog-slow-test.diff">picprog-slow-test.diff</a>.
</p>
<H2><A NAME="7">7. Reading PICs</A></H2>
Simple instructions:
<OL>
<LI> Insert the PIC chip into the socket in the
programmer, or connect the in-circuit programming cable to your
device.
<LI> Connect the programmer device to a serial port.
<LI> Read the device with command:
<PRE>
picprog --output ofile.hex --pic /dev/ttyS1
</PRE>
</OL>
The reading options are:
<DL>
<DT> <CODE>--output-hexfile</CODE> <EM>path</EM>, <CODE>-o</CODE> <EM>path</EM>
<DD> Specifies the output hex file. The file will be written in IHX16
format, unless otherwise specified by the <CODE>--ihx8m</CODE> or
<CODE>--ihx32</CODE> options. For PIC18 family devices, file will
be written in IHX32 format.
<DT> <CODE>--skip-ones</CODE>
<DD> When reading the PIC device, do not consider the all-ones memory
locations to be programmed, and skip them in the hex file output. For
14 bit devices, this skips the program memory locations that have hex
value 0x3FFF, and for PIC18 family devices, this skips byte values
0xFF. In data memory locations that have hex value 0xFF are skipped.
<DT> <CODE>--ihx32</CODE>, <CODE>--ihx16</CODE>, <CODE>--ihx8m</CODE>
<DD> Select the output hex file format to be either ihx16 or ihx8m,
respectively. The default is ihx32 for PIC18 family devices and ihx16
for others.
<DT> <CODE>--pic-serial-port</CODE> <EM>device</EM>, <CODE>-p</CODE> <EM>device</EM>
<DD> The device name of the serial port the programmer is connected
to. Default is <CODE>/dev/ttyS0</CODE>.
</DL>
<H2><A NAME="8">8. Exit values</A></H2>
Exit values are as defined in <sysexits.h>:
<DL>
<DT> EX_OK, 0
<DD> no error
<DT> EX_USAGE, 64
<DD> command line option syntax error
<DT> EX_IOERR, 74
<DD> file or serial port io error, or after-programming verification failed
<DT> EX_DATAERR, 65
<DD> input file syntax error, not in IHX8M, IHX16, or IHX32 format
<DT> EX_NOINPUT, 66
<DD> unable to find input file or file open failed
<DT> EX_UNAVAILABLE, 69
<DD> user or signal interrupted programming
<DT> EX_PROTOCOL, 76
<DD> the device is unknown to the programmer
</DL>
<H2><A NAME="9">9. Internals</A></H2>
Source files and their contents:
<DL>
<DT> picport.cc, .h
<DD> class picport: manipulates the serial port hardware. With this
class you can execute programming commands like read a word, program a
word, increment address etc. Look at picport.h for details.
<DT> hexfile.cc, .h
<DD> class hexfile: contains a PIC memory image. You can load and
save the contents of this class to a file, and you can program and
read it from the PIC chip. Programming uses class picport.
<DT> program.cc, h
<DD> class program: just some generic option handling.
<DT> main.cc
<DD> Just the main () to parse command line and call class hexfile to
do its job.
</DL>
<H2><A NAME="10">10. Changes</A></H2>
<p>
This document has not changed much since it was first released with
the 1.0 programmer. The changes include some information about new
software and more accurate links to PIC information. New options
to select type of device other than pic18c84 are also present.
</p>
<p>
2003-08-10 version 1.2
<br />
With help from Taneli Kalvas changed the schemantics diagram and pcb
mask to ground the RB4 pin, selecting high voltage programming on for
example pic16f628.
<br />
Implemented preservation of OSCCAL and other calibration data.
<br />
Added automatic detection of devices based on location 0x2006.
<br />
Merged Bart Goossens's changes to implement PIC16F73. I hope it works.
</p>
<p>
2003-08-21 version 1.3
<br />
Autodetect more chips. Fix programming of chips with OSCCAL. Fix
erasing some chips - erasing and resetting code protection is now
performed the hard way: all methods are tried regardless of chip type.
<CODE>--erase</CODE> now works also without
<CODE>--input-hexfile</CODE> flag.
</p>
<p>
2004-01-02 version 1.4
<br />
Add option <CODE>--force-calibration</CODE> to program OSCCAL and BG
bits. Implement programming algorithms for 16f87/16f88 and 16f87Xa.
Revise some timings on programmer reset to avoid operating voltage to
dip. More verbose output on how many locations actually were burned.
</p>
<p>
2004-03-02 version 1.5
<br />
Fix PIC16F87xA configuration word burning. Remove the 10k resistor
added by me from the PCB and schema. Add support for PIC18 family.
Make the DTR be held low as long as possible. This may improve the
reliability and limit stress on RS-232 port.
</p>
<p>
2004-03-19 version 1.6
<br />
Now compiles on Windows with Cygwin DLL version 1.5.8 and later. More
accurate timings result in shorter programming times compared to
previous versions. These timings use the CPU RDTSC instruction on x86
and AMD64 plattforms. PIC16F87/88 second configuration word
programming implemented.
</p>
<p>
2004-04-28 version 1.7
<br />
Fixed 16c OTP and UV erased parts EPROM programming to use 100µs
programming/overprogramming pulses. Use real time priorities and
nanosleep() for delays if run under root priviledges. Relax timings
so that they work out of the box with longer cables. Fixed PIC12F629
/ PIC12F675 / PIC16F627a / PIC16F628a / PIC16F648a / PIC16F630 /
PIC16F676 programming with >1.3GHz i386 CPU.
</p>
<p>
2006-03-05 version 1.8
<br />
Experimental dsPIC support, never tested, just compiled. Disabled the
real time priorities, the nanosleep function does not work any more in
Linux 2.6 kernels as it used to. Exit value 76 added to indicate
unsupported chip id. Added more PIC18F models, thanks to <a
href="http://www.janw.dommel.be/">Jan Wagemakers</a> from Belgium.
</p>
<p>
2006-03-26 version 1.8.1
<br />
Fix a mistake with 18f[24]5[128]5 and 18f[24]6[128]0. Thanks to
<a href="http://www.janw.dommel.be/">Jan Wagemakers</a> for the fix.
</p>
<p>
2006-09-28 version 1.8.3
<br />
Added --rdtsc, --nordtsc and --slow options. They may help with
laptops and new faster models of CPUs. Made --nordtsc the default.
This was originally release 1.8.2 that did not have that default.
</p>
<H2><A NAME="11">11. Other available programmers</A></H2>
<DL>
<DT> <A HREF="http://pikdev.free.fr/">PiKdev</A>
<DD> PiKdev is a simple graphic IDE for the development of PIC-based
applications. PiKdev is developed in C++ under Linux and is based on
the KDE environment. It includes a programming engine which allows
programming various flavors of PIC microcontrollers via classic (ie:
D. Tait or JDM compatible) programming hardware connected to the
parallel port or to the serial port.
<DT> <A HREF="http://pp06.sourceforge.net/">PP06</A>
<DD> Linux and Windows programming software that knows about 83 pic's
and 6 programmers.
<DT> <A HREF="http://www.voti.nl/xwisp/">XWisp</A>
<DD> Programmer software written in Python by Wouter van Ooijen.
<DT> <A HREF="http://www.iki.fi/hyvatti/pic/serp84/README">serp-0.5</A>
(<A HREF="http://www.iki.fi/hyvatti/pic/serp-0.5.tgz">serp-0.5.tgz</A>)
<DD> A serial port programmer software for Linux, written in c++,
author <A HREF="http://www.rjkm.de/rjkm.html">Ralph Metzler</A>. It
directly handles the serial hardware, standard 16450/16550 compatible
uarts, and needs root priviledges for that. Unmaintained since 1996.
<DT> <A HREF="http://www.iki.fi/hyvatti/pic/jdm84v23/jdm84.htm">jdm84v23</A> (<A
HREF="http://www.iki.fi/hyvatti/pic/jdm84v23.zip">jdm84v23.zip</A>, <A
HREF="http://www.iki.fi/hyvatti/pic/pgm84v23.zip">pgm84v23.zip</A>)
<DD> A serial port programmer, <A HREF="http://www.iki.fi/hyvatti/pic/jdm84v23/jdm84.gif">schema
(gif)</A> and DOS software. The hardware manages with rs-232
interfaces with low voltage output, even as low as ±7V is fine.
This is the programmer I use with linux with my own software. <P>
I modified the circuit to include connections to pins that are
needed for programming some PIC microcontrollers.
<P>
There is a new version of the PCB available on Jens Madsen site. It
supports more chips without jumper wires: <A
HREF="http://www.jdm.homepage.dk/newpic.htm">PIC-Programmer 2</A>.
</P>
<DT>
<a href="http://www.semis.demon.co.uk/uJDM/uJDMmain.htm">uJDM</a>
<DD>
A serial port programmer, stripped down version of the JDM device.
Works with Picprog but needs patching first with <a
href="http://www.iki.fi/hyvatti/pic/picprog-1.7-werner-almesberger.diff">picprog-1.7-werner-almesberger.diff</a>.
<DT> <A
HREF="http://www.iki.fi/hyvatti/pic/pip-02/pip-02.txt">pip-02</A>/<A
HREF="http://www.iki.fi/hyvatti/pic/pip-02/com84.txt">com84</A> (<A
HREF="http://www.iki.fi/hyvatti/pic/pip-02.zip">pip-02.zip</A>)
<DD> A serial port programmer, <A
HREF="http://www.iki.fi/hyvatti/pic/pip-02/com84.gif">schema (gif)</A>
and DOS software. Needs +12V rs-232 positive voltage level.
<DT> <A
HREF="http://home3.inet.tele.dk/frda/picasm/prog.html">prog84-3</A>
<DD> A parallel and serial port programmer, and software for Linux and
dos, written by <A HREF="http://www.omnigroup.com/~wiml/">Wim
Lewis</A> and <A HREF="http://home3.inet.tele.dk/frda/">Frank
Damgaard</A>. There is some experimental code for an USB parallel
port device.
<DT> <A
HREF="http://www.iki.fi/hyvatti/pic/dvtait84/pp.read">dvtait84</A>, <A
HREF="http://www.iki.fi/hyvatti/pic/pic84faq/pic84faq.txt">pic84faq</A>
(<A
HREF="http://www.iki.fi/hyvatti/pic/dvtait84.zip">dvtait84.zip</A>, <A
HREF="http://www.iki.fi/hyvatti/pic/pic84faq.zip">pic84faq.zip</A>)
<DD> A parallel port programmer, <A
HREF="http://www.iki.fi/hyvatti/pic/dvtait84/pp.asc">schema
(ascii)</A> and DOS software with basic and turbo-C sources included.
Author <A HREF="http://www.man.ac.uk/~mbhstdj/">David
Tait</A>. He has a lot more stuff, and some new designs to program
other PICs in his links page.
<DT> mjcox84 (<A
HREF="http://www.iki.fi/hyvatti/pic/mjcox84.zip">mjcox84.zip</A>)
<DD> A parallel port programmer, no schema, written in assembler for
DOS with 486/33 timings. Very limited. Author: Mark J Cox, <A
HREF="mailto:m.j.cox@bradford.ac.uk">m.j.cox@bradford.ac.uk</A>.
<DT> <A
HREF="http://www.iki.fi/hyvatti/pic/ngoodw84/picprog.doc">ngoodw84</A>
(<A
HREF="http://www.iki.fi/hyvatti/pic/ngoodw84.zip">ngoodw84.zip</A>)
<DD> A parallel port programmer and disassembler, no schema, seems to
use pins DATA1 = data and DATA2 = clock and needs external programming
voltage. From Everyday Practical Electronics, February 1996, author
Derren Crome. Disassembler by Nigel Goodwin <A
HREF="mailto:nigelg@lpilsley.demon.co.uk">nigelg@lpilsley.demon.co.uk</A>.
<DT> <A HREF="http://www.seattlerobotics.org/encoder/apr98/picprg.html">Minimized
PIC16C84 Programmer</A>
<DD> Parallel port programmer, DOS software, needs external 13V power
source. Author Stephen M. Nolan.
</DL>
<H2><A NAME="12">12. Available languages</A></H2>
<H3><A NAME="12-1">Free compilers</A></H3>
<DL>
<DT> <A HREF="http://gputils.sourceforge.net/">GNU PIC Utilities</A>
</DT>
<DD>
gputils have assembler, linker, disassembler and library utilities
much like MPASM. They support all PICs.
</DD>
<DT> <A HREF="http://www.cm.ph.bham.ac.uk/software/yappa/">Yappa</A>
<DD> A graphical development environment for PIC16F84 by Mark
Colclough at the University of Birmingham. Yappa combines into a
single application the editor, assembler and programmer interface that
are needed to program a PIC. Picprog is used as the programmer
backend.
<DT> <A
HREF="http://www.iki.fi/hyvatti/pic/picasm112b/picasm.html">picasm112b</A>
(<A
HREF="http://www.iki.fi/hyvatti/pic/picasm112b.tar.gz">picasm112b.tar.gz</A>)
<DD> Assembler in ANSI-C by <A HREF="http://www.iki.fi/trossi/">Timo
Rossi</A>. Outputs both IHX16 and IHX8M. You can
also find disassemblers for 12 bit and 14 bit PIC's on Timo's site.
<DT> <A
HREF="http://www.iki.fi/hyvatti/pic/asm_c84/asm_c84.html">asm_c84</A>
(<A HREF="http://www.iki.fi/hyvatti/pic/asm_c84.zip">asm_c84.zip</A>)
<DD> Assembler in ANSI-C by James Cleverdon, <A
HREF="mailto:jamesc@sequent.com">jamesc@sequent.com</A>. No INCLUDE,
no IF, outputs IHX8M. <A
HREF="http://www.iki.fi/hyvatti/pic/asm_c84/asm_c84.man">The
manual.</A>
<DT> SIL
<DD> I have heard of free SIL language (something like Pascal/M2)
compiler for PIC.
<DT> JAL
<DD> <A HREF="http://www.voti.nl/jal/">Just Another Language</A>, a
Pascal like high level language. <I>"... I wanted a HLL which is better
mached to the PIC architecture, to my programming habits, and which I
could explain to the kids of the local electronics club without giving
a full course on computer architecture."</I>
</DL>
<H3><A NAME="12-2">Commercial demos</A></H3>
<DL>
<DT> <A HREF="http://www.htsoft.com/">HI-TECH Software</A> C compiler
<DD> A demo is available of their compiler.
<DT> <A HREF="http://www.elabtronics.com/products_cat_CoreChart.htm">elabtronics
CoreChart</a>
<DD> CoreChart (formerly named bitset) is an icon-based development
tool. 30-day trial available.
</DL>
<H2><A NAME="13">13. Other software</A></H2>
<DL>
<DT> <A HREF="http://www.dattalo.com/gnupic/gpsim.html">GPSIM</A>
<DD> PIC simulator.
</DL>
<H2><A NAME="14">14. History</A></H2>
<P>Picprog was first written and released in May 1997. Around that
time I briefly experimented with microcontrollers. I found no Linux
software for the cheap serial programmer hardware by Jens Madsen, and
I wanted to use that one as it was so simple to build. Only later did
I learn about serp-0.5. Anyway, that one directly programmed PC style
serial port hardware while I wanted to use standard UNIX methods of
accessing serial ports. Linux was missing an IOCTL to force BREAK
condition (steady +12V) on the serial data transmit line. This kind
of functionality existed for example in Solaris. No problem, I
created a patch for Linux kernel versions 2.0.30 and 2.1.42, submitted
it, and it was included in mainline kernel versions 2.0.32 and
2.1.45.</P>
<P>Since the time I first wrote the software I did not work with
microcontrollers at all for years, though I maintained Picprog by
fixing obvious compilation problems and updating documentation.
Version 1.0.1 was put together in May 2001 and included mainly
documentation fixes. In June 1997 I had worked on adding support for
different memory sizes of different PIC chips, and these changes and
again documentation updates were released as version 1.1 in February
2002. I also found the programmer hardware I thought I lost a few
years back, and was able test that it still works.</P>
<P>Picprog-1.0 was ported to FreeBSD and included in the distribution
around September 1999. <A HREF="http://maslab.lcs.mit.edu/">MIT
MASLab 6.186</A>, a student-run robotics course, seems to have used it
since January 2001. Recently this documentation page has attracted
steadily over 1000 visits per month, so I guess someone is finding
it useful.</P>
<p>
Nowadays I mostly test Picprog with new chips, and sometimes I start a
new project like <a href="http://www.iki.fi/hyvatti/kansat/">KanSat
satellite</a> or <a href="http://www.iki.fi/hyvatti/pic/pong/">8-PIN
PONG</a>, and never finish them..
</p>
<H2><A NAME="15">15. Copyright notice</A></H2>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation. <P>
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <A
HREF="COPYING">GNU General Public License</A> for more details. <P>
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. <P>
The author may be contacted at: <P>
Email: <A HREF="mailto:Jaakko.Hyvatti@iki.fi">Jaakko.Hyvatti@iki.fi</A><BR>
URL: <A HREF="http://www.iki.fi/hyvatti/">http://www.iki.fi/hyvatti/</A>
<p>
Please send any suggestions, bug reports, success stories etc. to the
Email address above. To avoid my spam filters, please put the word
'picprog' somewhere on the subject line.
</p>
<p>
<!-- Begin PayPal -->
<FORM ACTION="https://www.paypal.com/cgi-bin/webscr" METHOD="POST">
<INPUT TYPE="hidden" NAME="cmd" VALUE="_xclick">
<INPUT TYPE="hidden" NAME="business" VALUE="jaakko.hyvatti@iki.fi">
<INPUT TYPE="hidden" NAME="return" VALUE="http://www.iki.fi/hyvatti/pic/picprog.html">
<!-- INPUT TYPE="hidden" NAME="undefined_quantity" VALUE="1" -->
<INPUT TYPE="hidden" NAME="item_name" VALUE="Donation to Jaakko">
<!-- INPUT TYPE="hidden" NAME="amount" VALUE="1.00" -->
<INPUT TYPE="hidden" NAME="no_shipping" VALUE="1">
<INPUT TYPE="hidden" NAME="cancel_return" VALUE="http://www.iki.fi/hyvatti/pic/picprog.html">
If you want to support the developement of picprog, please make a donation to
<INPUT TYPE="submit" NAME="Jaakko" ALT="Jaakko" VALUE="Jaakko">
via PayPal (click on the button).
</FORM>
<!-- End PayPal -->
</p>
<HR>
<A HREF="http://www.anybrowser.org/campaign/"><IMG
SRC="anybrowser3.png" WIDTH="88" HEIGHT="31" ALT="Best viewed with any
browser" BORDER="0" ALIGN="right"></A>
<ADDRESS>
<A HREF="http://www.iki.fi/hyvatti/">Jaakko Hyvätti</A>/<A
HREF="mailto:Jaakko.Hyvatti@iki.fi">Jaakko.Hyvatti@iki.fi</A>/+358 40 5011222
</ADDRESS>
</BODY>
</HTML>
|