This section of the Embed Inc web site contains general information and example source code for the Microchip PIC line of microcontrollers.
Be sure to read the legal notice before using any software found on this web site.
Embed Inc is a custom embedded systems development company. We have done many projects using the Microchip PIC line of microcontrollers and have converged on a structure and methodology for PIC projects that is suitable for the majority of cases. This includes a set of standard macros, subroutines, modules, and host tools.
When possible, we use our common framework for PIC firmware projects. The framework has evolved over many projects, and will continue to evolve. It consists of two master include files (STD_DEF.INS.ASPIC and STD.INS.ASPIC), a common naming scheme and structure for the modules of a project, and a few standard modules for capabilities required by most PIC projects.
We use the naming convention PPP_MMM.ASPIC, where PPP is the project name and MMM is the name of the module within the project. For example, "hal_intr.aspic" is the source file for the INTR module within the HAL project. Many examples here use a three letter project name and 4 letter module name. This is because MPLAB version 5 and earlier only allowed 8.3 "DOS" file name. Fortunately this was changed in MPLAB version 6.
So what's with this ASPIC stuff? We use a preprocessor on all our PIC source code. The .aspic file name suffix indicates to our build system that it is a PIC assembler module that must be run thru the preprocessor to create a .asm file. The .asm file produced by the preprocessor is assembled directly by the MPASM PIC assembler.
Below are the standard include files, and templates for the standard modules and additional include files. The project name of the templates is "qqq". The strings "qqq" and "QQQ" in the template files are intended to be replaced with the actual project name via global substitution in a text editor.
This module also disables any analog inputs the chip might have, which are usually enabled on power up. If used, these would be specifically enabled by the modules that handle them. Initializing all analog inputs to off eliminates some common bugs in porting from a PIC without an analog peripheral to one that has an analog peripheral.
In general, each module contains the qqq_INIT routine, which performs any module-specific initialization. The qqq_INIT routines are called from the STRT module after a reset.
We use wrapper programs around each of the Microchip build tools: MPASM, MPLIB, and MPLINK. This is partly because the Microchip tools are too brain dead to return a bad program exit status when they fail. Our build system, like most build systems, requires a tool to return something other than 0 program exit status when the build failed. Our wrappers also deal with some file naming and other issues.
In addition to plain wrappers for the Microchip executables, we have created a Microchip assembler preprocessor. This allows us to add directives to the assembler source code that enable better programming practises than raw MPASM does. See the doc file for details.
Here is the list of some of the PIC development tools. Click on a tool name to view its documentation file.
PREPIC - PIC assembler preprocessor. Required by ASMPIC if assembling .ASPIC files.
ASMPIC - Wrapper around MPASMWIN. Requires PREPIC if assembling .ASPIC files.
LIBPIC - Wrapper around MPLIB.
LINKPIC - Wrapper around MPLINK.
ASPIC_FIX - Fixes formatting, removes tabs, etc, of an arbitrary PIC assembler file. Same resulting format as used for all examples here.
A combined document is available that contains much of the information in a single place. This was produced by Jan-Erik Söderholm, and is available on his web site www.jescab.se/embedinc. It is mostly a PDF file compilation of the documentation here, plus some additional information of his own. Embed Inc takes no responsibility for this document.