Microchip PIC
Microchip is a manufacturer of the PIC series of microcontrollers, along with many support devices.
Development Tools
MPLAB is Microchip's free integrated development environment for most PIC's. It includes an assembler, linker, and simulator.
There is a free C compiler for the 16F84 (with associated manual) from Hi-Tech Software.
* SDCC is not only free, but also open-source. There are many C compilers for the PIC.
* There are many languages available for the PIC, some of them are free. There are many BASIC compilers for the PIC. Some people are working on Forth for the PIC.
* Here are some PIC simulators.
Data Sheets
Please DO NOT print these out (on our printers) as they are very long and will waste a lot of paper. Get used to reading PDF files on the screen and using the PDF navigation resources to move around quickly.
[http://ww1.microchip.com/downloads/en/DeviceDoc/41239A.pdf PIC10FXXX], a new 6-pin microcontroller in an SOT-23 package!
[http://claymore.engineer.gvsu.edu/~steriana/courses/Downloads/PIC12C5XX.pdf PIC12C5XX] (also: [http://www.microchip.com/download/lit/suppdoc/errata/80063d.pdf rev. B errata], [http://www.microchip.com/download/lit/suppdoc/errata/80024b.pdf rev. A errata])
[http://claymore.engineer.gvsu.edu/~steriana/courses/Downloads/PIC16F84A.pdf PIC16F84A] (also: [http://www.microchip.com/download/lit/suppdoc/errata/80083b.pdf errata])
[http://www.microchip.com/download/lit/pline/picmicro/families/16c62x/40300c.pdf PIC16F628A] (also: [http://www.microchip.com/download/lit/suppdoc/errata/80073f.pdf errata])
[http://claymore.engineer.gvsu.edu/~steriana/courses/Downloads/PIC16F81X.pdf PIC16F818/819] (also: [http://www.microchip.com/download/lit/suppdoc/errata/80132c.pdf SSP module errata], [http://www.microchip.com/download/lit/suppdoc/errata/80159a.pdf errata])
[http://claymore.engineer.gvsu.edu/~steriana/courses/Downloads/PIC16F87XA.pdf PIC16F87XA]
Application Notes
Microchip has lots of application notes for their products. Here is a small selection of the ones that we've used recently.
Using the PICmicro SSP for [http://www.microchip.com/download/appnote/pic16/00734.zip Slave I2C Communication]
In-circuit Serial Programming for [http://www.microchip.com/download/appnote/pic16/91016b.pdf PIC16F8X MCU's] (note, this is not for low-voltage serial programming).
Some routines for [http://www.microchip.com/1010/suppdoc/appnote/func/algorhyth/math/index.htm math]
A [http://www.microchip.com/download/appnote/devspec/16cxx/00555c.pdf software UART] implementation
Using the [http://www.microchip.com/download/appnote/pic16/00774a.pdf hardware USART]
[http://www.microchip.com/download/appnote/devspec/16c78x/00823a.pdf Analog Design in a Digital World] -- read this. Twice.
Notes on [http://www.microchip.com/download/appnote/power/00786a.pdf Driving Power MOSFET's]
[http://www.microchip.com/download/appnote/power/00799a.pdf Matching MOSFET Drivers to MOSFET's]
Other Resources
Mark Witt has put together a [http://claymore.engineer.gvsu.edu/~steriana/courses/Downloads/PIC16FXXInstructionSet.xls spreadsheet] summarizing the PIC16FXX instruction set.
the PicList has a huge amount of tips, tricks and advice for the Microchip PIC and other EE stuff. Have you read the PIC FAQ ? Have you read the Beginner's Checklist ? http://piclist.org/
Silly Bug List
Here is a list of gotchas that have caused many hours of frustration for students (and...ummm...faculty) in the past.
- On many PIC's (but not all), Port A pin 4 is open collector hence cannot actively drive high.
- On PIC's with A/D converters, the A/D port pins default as being analog inputs. Thus, you have to do some work (most likely write to the ADCON1 register) if you want to use these pins as digital I/O.
- The PIC instruction cycle clock is 1/4 the frequency of the external clock.
- You really have to watch your bank bits. Writing to a register in the wrong bank is an extremely common mistake.
The default CONFIG word for PIC template files is most likely NOT what you want. You must especially take care to:
Turn off the watchdog timer if not using it
- Select the right kind of oscillator for your application
- Turn low-voltage programming ON or OFF, depending on whether you are or aren't using it
If you don't know what a config option does, FIND OUT! Don't just use the default.
- Many peripheral interrupt sources have their own individual enable flag, plus a flag for all peripherals (PEIE), plus you have to enable the global interrupt flag (GIE). Many people forget PEIE.
- The TRISA/TRISB/etc. registers use a 1 for Input and 0 for Output (1 looks like I, 0 looks like O). This is the opposite scheme from the ones used by Atmel and Motorola where 1 is output and 0 is input.
- You must tie the MCLR\ pin to a valid logic level (either Vcc or some kind of reset circuit) else the chip will never come out of reset.
The subtract instructions (subfw, sublw) set the Carry bit if there is NO borrow. The add instructions (addfw, addlw) set the carry bit if there IS a carry.
Be careful with instructions that skip the next instruction and macros. A btfsc instruction, for example, followed by a macro call will only skip the first instruction of the expanded macro sequence.
- Vdd means Vcc and Vss means GND. Hook them up backwards, toast a chip.
- The MPLAB assembler doesn't like files without the DOS end-of-line characters (0x0D, 0x0A). Files created on a Unix system have only 0x0A line endings and you will get weird error messages. Fixes:
In VIM, type the command ":set fileformat=dos" then save the file.
- In a DOS box, use the EDIT program to load then save your file. EDIT always saves files in DOS format.
You cannot move data from one location to another in just one instruction, for example: "movf PORTB,temp". Worse, the assembler will not complain loudly because what comes after the comma determines the destination (F or W) of the move, and the assembler only cares if it's 0 or not. You must write "movf PORTB,W; movwf temp".
You cannot use the move instructions on single bits. Students would love to say "movfw PORTB,3" to get bit 3 out of Port B. It doesn't work.
