All you need to know about Microchip for now is this:
- the current, supported IDE is MPLABX. Download it
here.
- the C compilers are XC8 for 8 bit devices, XC16 for 16 bit, and XC32 for 32 bit. Download the free versions of any of them
here, and install after you've installed MPLABX.
- ignore everybody who bitches and whines that the free compilers don't optimise. So what? You're learning the language, not trying to squeeze every last bit of performance out of a device. I've only needed optimisation for one design out of a dozen or so I've done over the last few years.
- my current favourite range of devices is the PIC18FxxK22 family. All you need to get started is a breadboard with a PIC18F26K22, programming header (6 pin 0.1in), a decoupling capacitor and a pull-up resistor on MCLR.
- Once you've started a new project in MPLABX, go to Window > PIC Memory Views > Configuration bits. Here you can set all the configuration bits for the device from a series of drop-down menus, then click 'Generate source code to output'. Copy and paste this code into your project, and all the chip's configuration bits are done. (I always put this lot into a header file called config.h and then #include it).
Other things you need to do in your project are:
- #include <xc.h> at the start of your main.c file, and any others which refer to device registers
- Set OSCCON to specify the clock source and speed that you want the chip to run at
- Set the ANSEL and TRIS bits for any pins you want to use as digital I/O
- Read inputs from PORT registers, but write outputs to LAT registers.
- You can access individual bits in registers by name, rather than having to write the whole register at a time. So, for example, you can turn on an LED connected to pin RA6 by writing LATAbits.LATA6 = 1. This register naming convention is used throughout.
- READ THE ERRATA for any PIC you're considering using. There are some absolute howlers which you really, really do need to know about.