PIC-FAQ Issue 2.02 This article is a collection of information sources for the PIC family of micro controllers (and variants). The following topics are addressed: 0 ) Index 1 ) ABOUT THIS FAQ 1.1) Who put this FAQ together? 1.2) How can I contribute to this FAQ? 1.3) What newsgroups will this FAQ be posted to? 1.4) Mailing lists of interest to PIC fanglers 1.5) Other FAQs of possible interest 1.6) Can I distribute this FAQ or post it somewhere else? 2 ) ABOUT THE PIC 2.1) The PIC micro controller 2.2) PIC variants 2.3) Notes for programmers 2.4) PIC contacts and representatives 3 ) PIC Utilities 3.1) FTP sites for the PIC 3.2) BBSs that support the PIC 3.3) Programming languages (3rd Party) 3.4) Programming hardware (3rd Party) 4 ) PIC DOCUMENTATION 4.1) Periodicals that cover the PIC 4.2) Books on the PIC 4.3) Miscellaneous documentation on the PIC 5 ) What's next. ============================================================================= 1) ABOUT THIS FAQ 1.1) Who put this FAQ together? The denizens of "The Internet" i.e. yourselves. 1.2) How can I contribute to this list? Please, if you have any suggestions corrections or additions, notify me by E-MAIL. : Tom@takdsign.demon.co.uk Thank you. 1.3) What newsgroups will this FAQ be posted to? This FAQ will be posted to the following newsgroups: sci.electronics.repair comp.robotics And the PIC mailing list. The schedule for posting will be once a month. 1.4) Mailing lists of interest To subscribe to the PIC mailing list; Mail to: listserv@mitvma.mit.edu Header: () leave blank, not used. Text: SUBscribe PIC to subscribe or UNSUBscribe PIC to un subscribe or HELP to get help The pic list address is: PIC@mitvma.mit.edu 1.5) Other FAQs of possible interest The 8051FAQ posted by Russ Hersch - sibit@datasrv.co.il Available in comp.sys.intel comp.realtime comp.robotics comp.lang.forth sci.electronics 1.6) Can I post this FAQ to my local BBS? I am putting no restrictions on the use of this FAQ except - It must be distributed in its entirety and no financial gain may be realised from it. ============================================================================= 2) ABOUT THE PIC ----------------------------------------------------------------------------- 2.1) The PIC micro controller The PIC series are eprom based 8-bit micro controllers developed by Microchip Technology ----------------------------------------------------------------------------- 2.2) PIC Variants PIC processors are available in three families, which Microchip refers to as the PIC16C5x, PIC16Cxx, and PIC17Cxx families. PIC16C5x: 12 bit program word size, 33 instructions, 2 level stack, no interrupts Program Data Max. Voltage Typical Digikey memory memory I/O freq. Range Current Price (words) (bytes) pins (MHz) (Volts) (mA) (US $) ---------- --------- --------- ----- ----- -------- ------- ------- PIC16C54 512 25 12 20 2.5-6.25 2 4.39 PIC16C54A 512 25 12 20 2.5-6.25 2 PIC16CR54 512 ROM 25 12 20 2.0-6.25 1 PIC16CR54A 512 ROM 25 12 20 2.0-6.25 1 PIC16C55 512 24 20 20 2.5-6.25 2 5.44 PIC16C56 1024 25 12 20 2.5-6.25 2 5.03 PIC16C57 2048 72 20 20 2.5-6.25 2 6.24 PIC16CR57A 2048 ROM 72 20 20 2.0-6.25 1 PIC16C58A 2048 73 12 20 2.5-6.25 1 PIC16Cxx: 14 bit word size, 35 instructions, 8 level stack Program Data Max. Voltage Typical Digikey memory memory I/O freq. Range Current Price (words) (bytes) pins (MHz) (Volts) (mA) (US $) ---------- --------- --------- ----- ----- -------- ------- ------- PIC16C64 2048 128 33 20 2.0-6.0 3 11.05 PIC16C71 1024 36 13 16 3.0-6.0 2 14.38 PIC16C74 4096 192 PIC16C84 1024 EE 36 + 64 EE 13 10 2.0-6.0 2 10.15 PIC17Cxx: 16 bit word size, 55 instructions, 16 level stack: Program Data Max. Voltage Typical Digikey memory memory I/O freq. Range Current Price (words) (bytes) pins (MHz) (Volts) (mA) (US $) ---------- --------- --------- ----- ----- -------- ------- ------- PIC17C42 2048 256 33 25 4.5-5.5 6 15,15 PIC17C44 8192 480 33 25 Notes: 1. Program memory is EPROM unless otherwise noted. 2. Data memory is number of usable bytes, not including special function registers. 3. Digikey prices are quantity 10 prices for 4 MHz DIP packaged OTP parts with RC oscillator option (where applicable), except that the 16C84 uses EE PROM program memory, and the slowest speed 17C42 is rated at 16 MHz. Prices are from Digikey catalogue number 943 for May/June 1994. Other distributors often have lower prices, but typically also have high minimum order requirements. Digikey also usually has plenty of parts in stock. Windowed EPROM parts cost substantially more. ----------------------------------------------------------------------------- 2.3) Notes for programmers: All PIC instructions are a single word. The equivalent of the immediate address mode of other processors is the literal mode, used by instructions ending in "LW", such as MOVLW, ADDLW, SUBLW, ANDLW, IORLW, XORLW, and RETLW. The byte of data used by these instructions is directly encoded in the instruction itself. All PIC instructions take a single instruction cycle (four oscillator cycles) to execute, unless a conditional test is TRUE or the program counter is changed as a result of an instruction, in this case the execution takes two instruction cycles. For example: movlw 37 goto next next: movwf porta The goto instruction takes two cycles (1 to get the value of label "next" and 1 to load that value into the program counter) This is useful as a two-cycle NOP, and is often written as "goto .+1" to avoid the need for a label. The W register is equivalent to the accumulator on other processors. Almost all data movement, arithmetic, and logic operations use W. Instructions that operate on W and a register (i.e., instructions ending in "WF", like ADDWF and MOVWF) allow the result to be placed in either W or the register (but not both). This is specified by a ",W" or ",F" after the operand. The default is ",F", which will place the result in the register. This can cause a lot of confusion if you're not careful, so I recommend always specifying the destination explicitly. An example of a confusing instruction: incf foo,w ; w := foo+1 note that foo is unchanged! If you want the result in both W and the register, you can use either: incf foo,w mowwf foo or: incf foo,f movf foo,w The stack is not accessible to the programmer in any way other than the call and return instructions. There is no way to push or pull data, or even to examine the stack pointer. On the 16C5x family the stack has only two levels, so it is frequently necessary to write code in a different style than would be used on a typical processor; you can only call subroutines from your main code, or from a subroutine called from main, but no deeper. If you try to make a 3rd CALL, the 2nd return address is over-written so that the return from the 3rd CALL is OK but the return from the 2nd CALL ends up where the 1st CALL should return to. The 16CXX parts which implement an 8 level stack do so in a circular fashion, so that the 9th CALL over-writes the return address for the 1st CALL. The 16C5x family doesn't have a normal return instruction; instead it has RETLW, which stands for RETurn Literal Word. RETLW loads an eight bit constant into W (just as a MOVLW instruction would), then returns from the subroutine. This can be useful, but is aggravating if you want to return a computed value. On the newer PIC families there is a normal RETURN instruction. With the exception of the 17Cxx family, there is no way for software to read an arbitrary location of program memory. In order to implement lookup tables, it is necessary to combine the use of the ADDWF and RETLW instructions. For example, the following code implements a lookup table of the first four odd prime numbers: primes: addwf pcl retlw 3 retlw 5 retlw 7 retlw 11 To use the table, load the appropriate index (in this case, 0 to 3) into W, and "call primes". The addwf instruction adds the contents of W to the PC, which has already been incremented to point to the "retlw 3". The table will return with the value in W. The total time taken is 6 instruction cycles, or 24 oscillator cycles. Note that while on most processors the use of an out-of-range index will result in the use of incorrect data, but the program execution will continue normally, on the PIC a bad index value will cause the execution of arbitrary instructions! i.e. the computed address must be in the top 1/2 of page. Normally the index would range from 0 to the size of the table minus one, but it is possible to use other ranges by putting the retlw instructions somewhere other than immediately following the "addwf pcl". It is also possible to implement tables using a "subwf pcl", or perhaps other instructions with pcl as the destination. The subtract instructions (SUBWF and SUBLW) work differently than most people expect. SUBWF subtracts W *from* the contents of the register, and SUBLW subtracts W *from* the literal. (SUBLW is not available on the 16C5x family.) If you want to subtract a literal from W, it is easiest to use the ADDLW instruction with the two 's complement of the literal. For example: addlw 0feh ; w := w - 2 Some assemblers allow this to be written as: addlw -2 There is no instruction to take the two 's complement of W (like the NEG instruction on Motorola processors), but because of the way the subtract instructions work you can use: sublw 0 On the 16C5x family, the CALL instruction can only address the first 256 words of a bank of program memory. It is common practice to use "call extenders", which are simply GOTO instructions in the first 256 words with a target in the last 256 words. On the 16C57 and 16C58, if you plan to use indirect addressing (via the FSR and IND registers), it is vitally important that your reset code clear FSR before using any other RAM locations. Otherwise you may start up in an arbitrary bank, and as soon as you change FSR all your carefully set up variables will effectively disappear. ----------------------------------------------------------------------------- 2.4) PIC contacts and representatives I don't know where these are for sure. Advanced Trans Data Tel:(214) 980- 2960 Programmer PGM16 & PGM 16x8 Gang Prog. fax:(214) 980-2937 No further information is available at this time Micro Engineering Labs tel:(719) 520-5323 makes PIC-Proto boards Myriad Development tel:(303) 692-3836 CCS - C compiler tel: (414) 781-2794 extension 30 Digi-Key tel:1-800-344-4539 Order electronic parts, carry 16C54,55,56,57,&71. ED Teck. Pubs tel:407-454-9905 Fred Eady BBS:407-454-3198 Writes articles for popular magazines. Has a PIC programmer kit for $70. BBS good source of information, very helpful. FAI tel:1-800-303-5701 Ask for Chris Electronics distributor, carry PIC's, Needham Electronics tel:(916) 924-8037 I don't know if they make PIC stuff, fax:(916) 972-9960 but they make an EPROM programmer, the PB-10 bbs:(916) 972-8042 Their emp-20 is great for Pics,Pals,Gala,EEproms etc but is ~$500 It can be set to auto program on start up. It takes about 4 seconds for a bat file to reassemble the source with new EQU's from the command line, recompile and program a part. Protel tel:1-800-544-4186 Builder of EASYTRAX, which is free-ware and a bunch of new stuff. Call Ext 225 ask for Louise Markham. bbs:1-408-243-0125 Bell Industries tel:1-800-525-6666 Electronic Distributor, including PIC's ......................................................................... Australia Microchip Technology tel:61 03 890 0970 Product information No further information is available at this time ......................................................................... Canada AP Circuits BBS 1-403-291-9342 (Canada) Can download EASYTRAX(V2.06), various utilities, GERBER file proofers, etc. You can upload PCB files and they will make boards and ship to you in about week. (about $100) Baradine Products Ltd tel:604-988-9853 Programmer Micro-Burner No further information is available at this time ......................................................................... Europe Data I/O Corp. tel:31(0)-6622866 Programmer Unisite with Site-48 module No further information is available at this time ......................................................................... France Arizona Microchip Technology SARL tel:33 01 6930 9090 2, Rue Du Buisson aux Fraises fax:33 01 6930 9079 F-91300 Massy, France Product information ......................................................................... Germany Arizona Microchip Technology GMBH tel:49 089 609 6072 Alte Landstrasse 12-14 fax:49 089 609 1997 D-8012 Ottobrunn, Germany Product information SMS tel:49-7522-4460 Programmer Sprint Expert No further information is available at this time ......................................................................... Hong Kong Microchip Technology Inc. tel:852 410 2716 Unit No. 2520-2525 fax: 852 418 1600 Tower 1, Metroplaza Hing Fong Road, Kwai Fong N.T., Hong Kong Product information ......................................................................... Italy Microchip Technology tel:39 039 689 9939 Product information No further information is available at this time ......................................................................... Japan Data I/O Corp. tel:(03) 432- 6991 Programmer Unisite with Site-48 module No further information is available at this time Microchip Technology International Inc. tel:81 45/471-6166 Shinyokohama Gotoh Bldg. 8F, 3-22-4 fax: 81 45/471-6122 Shinyokohama, Kohoku-Ku, Yokohama-Shi Kanagawa 222 Japan Product information ......................................................................... Korea Microchip Technology tel:82 2 518 8181 Product information No further information is available at this time ......................................................................... Singapore Microchip Technology tel:65 222 4962 Product information No further information is available at this time .........................................................................