Peter's electronic projects

About the PIC

PIC is the name for the Microchip microcontroller (MCU) family, consisting of a microprocessor, I/O ports, timer(s) and other internal, integrated hardware. The main advantages of using the PIC are low external part count, a wide range of chip sizes (now from 5-pin up!) available, nice choice of compilers (assembly, C, BASIC, etc.) good wealth of example/tutorial source code and easy programming. Once bought, the PIC's program memory is empty, and needs to be programmed with code (usually HEX files) to be usable in a circuit. For the purpose, a wide range of simple programmer hardware docs and software is downloadable from the net.

If you are a beginner with PICs, a PIC 16F628 or 16F877 device is a good choice to start with. For code snippets and ideas check The PIClist web page and mailing list archives.

FAQ

Q: How do I compile a HEX file from multiple source files (linked project) ?

Q: How do I compile a HEX file from a source file containing CODE directives?

A: Here is how to do it in MPLAB v5. Create a project (project/new) and in the project files area select the root node (HEX file). Click node properties, select MPLINK as language tool. Enter appropriate linker file name (eg 16f628.lkr) into additional command line options. Close window. Click add node to add all the source files one by one. Place the specified lkr file (eg 16f628.lkr) in the directory containing the sources. The linker file can usually be copied from your mplab(/lkr) program directory. Choose the file matching your processor.

MPLAB v6: Start the new project wizard, and when asked, add all assembly, header files and the linker script to the project.

Explanation: There are two incompatible source types for one-file absolute and multiple-file linked projects, you can't write code both type. If you want to build modular code which can be combined with other libraries, code must be written in the linkable format, even if it is the only source file in the beginning. But linkable format source must be compiled differently, in two steps: first compiled into an intermediate object format, then linked into a HEX file.