PIC microcontrollers are
RISC chips which follow the
Harvard architecture, that is, there are separate buses for code and data. The data bus is 8 bits wide, indeed, while code words are 14 bits wide for the PIC16F series.
Thus is it easy to design a fast microcontroller, though there is the occasional difficulty for the programmer: For example, it is not entirely straightforward to access certain registers, or to use long jumps or long tables. Unexpected results can occur if a port is accessed in consecutive instructions. However, other microcontroller families also restrict port access -if not always for the same reason- and the PIC18F family does address problems associated with memory bank switching.

The PC parallel port was used in early programming boards for the PIC, though there may be issues when accessing this port under Win NT/ XP, unless you are using a driver such as
Porttalk. Therefore, newer boards are connected to the serial port.
There are reverse biased protection diodes from every PIC input to the power supply and ground, some people point out, so they drive PIC pins from the serial port through 22k resistors. Some designs add (faster) external protective diodes, but otherwise do much the same. This page will err on the side of caution: A buffer is very inexpensive, but those PIC devices ridden with features are not.
Much the same board can be used for both the PIC16F and PIC18F series, but beware that the pin numbers for RB7 (program data), RB6 (program clock), MCLR' (programming voltage), Vcc and ground will be different. Do not be tempted to omit the resistors at the buffer outputs: A PIC output can source or sink more than 20 milliamps of current, and will soon destroy the buffer if shorted to it. If shorted to the power supply, ground or a complimentary output, it will destroy itself
very soon! Again, the output voltage (and current) is enough for a short RS232 loop, but a buffer is still a good idea, in case you solder RB7 to the wrong pin on the serial connector.
There is a diode in the ground circuit of the 12 Volt regulator, to ensure the programming voltage is between 12 and 14 Volts. (Modern devices may not actually need a high programming voltage.) It is better not to omit the protection diode at the input: Some people power PIC boards from battery eliminators which feature a polarity reversal switch- you have been warned!
While some boards try to derive the programming voltage from the serial port by using a voltage doubler, this arrangement is questionable: Serial ports on portable computers may only provide -5 to +5 Volts.
If any gates driving RB7, RB6 and MCLR' can be tristated, in-circuit serial programming (
ICSP) is perfectly feasible.
I don't usually complain, but the schematic at some sites does not seem to be in concert with the driving software. One program reads a configuration file (complaining if the pin for any signal is not defined) and then ignores it! A
pulse lengthener stretches even a single pulse to a full second, and so you will not blame the board or the PIC when they are not at fault: You can see which pins are driven and when, but please notice that the input voltage is only 5 Volts unless you include the Zener attenuator.

The WinPic software was used without trouble. The following options were chosen:
-
On the interface tab, select JDM(2) on the serial port, usually COM1.
- On the device-config tab select the PIC type. You will usually disable the watchdog timer and code protection, but enable the power up timer. The absolute minimum cost is obtained for an external timing resistor and capacitor for non-critical applications, but many designs involve a 4 MHz crystal which is selected by the HS option.
Readback (or verification of programming) may run into trouble. For example, the CTS pin may not be available at all times on some machines. While the documenatation states no other serial pins are acceptable for this task, the March 2006 version seems to cope with DSR, for instance. If the problem persists, you could edit the devices.ini file to read 'canRead=0' for the device under use. Although you will not be able to read back the code or verify it, at least programming will not be interrupted. Often, it is easy to tell whether the PIC is doing as it has been told.
The ability of microcontrollers to set, clear or test a bit in a single instruction is notable. (General purpose microprocessors will probably need three.) The 8051 family can also compliment in a single instruction, but only some special bits.
Logic and arithmetic operations always involve the
working register, while the second operand can be a constant (a 'literal' in PIC parlance). Alternatively, the second operand is provided by another register (a 'file') and, in this case, the result goes either to the working register or the file. You are urged to use the 'w' and 'f' designators, rather than '0' and '1', or the default. The flow is controlled by skipping the next instruction (probably a GOTO) whenever some bit is set or clear. (It may well be the zero or carry flag in the status register.)
Subroutines may be nested 8 levels deep if interrupts are not used, but there is no direct access to the stack for the PIC16F series. The RETLW instruction returns from a subroutine with a literal in the working register and is often used to implement tables. Interrupts of course save the program counter, but you have to take care of the working register and flags yourself. Most instructions are executed in one machine cycle (four oscillator pulses), unless the program counter is modified: Then the pipeline has to be flushed, and a second machine cycle is needed.

A frequency synthesiser (
code) is presented for illustration. (This has already been presented for the
8051, and you may still use the
individual and
sweep programs included there.) It is controlled by the serial port, and the serial reception routine is interrupt driven. I know that newer PIC devices feature serial data reception at RB1, but for the PIC16F84 (A) the external interrupt is needed, and this is at RB0.
While the PIC16F84A is old, it is still popular: It is inexpensive, will do for simple tasks, and it is easy to find a lot of material on it. The PIC16F628 on the other hand, is a superior replacement: It is not more expensive, features twice the memory, three timers, a hardware serial port and a PWM module. However, you will want to disable analogue features at power-on and place your registers above 0x20.
Newer PIC devices include the PIC16F877 and PIC18F452. Features include a 40 MHz clock, up to five ports, four timers and an analogue to digital converter. The very last dsPIC family includes on-chip DSP facilities.
Essential external links for the PIC:
If you do not want 7 Megabytes (or more) of download and don't mind the text interface, Picemu is perfectly adequate: Apart from the interrupt driven serial reception routine, it has been used to debug a sweep audio oscillator and frequency counter which will appear soon.
These pages may be of interest:
Out of sight, out of mind |
For my own code up to this point:
Valid XHTML 1.0!