Things to Keep in Mind
Each PIC μC part number (e.g. PIC10F206) is a unique device, so you must find the spec sheet for the device you are using. Do not simply copy someone else’s example unless they are using the same device, the same programming method and the same development tools.
Applying these devices relies on your jack-of-all-trades mentality. These devices give you control over absolutely everything and the admission price is to put aside any assumptions.
So, first things first. Necessary documents:
- the Data Sheet for your PIC μC
- the Memory Programming Specification for your PIC μC
- documentation for the development environment (MPLAB X IDE).
- documentation for the compiler (XC8). Especially useful is “MPLAB XC8 Getting Started Guide” which you can find in the XC8 installation directory: ./xc8/vx.xx/docs. This 30-page document is worth a quick scan.
One Two Things I Have Stumbled On
Programming Voltage Requirements
The PICkit3 is able to provide power to your embedded system. But, it is limited to 25 milliamps and 5 volts. During programming, the amount of power required to bulk erase the μC FLASH will be insufficient if you set the supplied voltage to match a 3-volt battery! I fixed this problem by powering the system with a 9-volt battery and setting the voltage level on the PICDEM board to 4.5 volts.
Micro-Controller Configuration
The Data Sheet explains the internal features of the μC and reveals that for most device types, each pin on the device can host 2 or more chip features. So, you need to decide which feature(s) you want to use and learn how to configure the device to connect each feature to the pin. Configuration is in two parts:
- Some configuration bits in the device are set as part of programming the chip. These settings cannot be changed by your run time code.
- Initializing certain registers in the run time start-up code allows you to change the features on the fly. Typically, this is done during power-on reset initialization.
I banged my head against this while trying an example written for a PIC10F200 and running it on the PIC10F206. The simple example failed to work because the PIC10F206 has a Comparator feature which uses the GP1 pin my application needed to drive an LED. Until I disabled the Comparator, the LED could not possibly turn on!