Pointer-less C Compiler For PIC18Fxxxx MCUs - PLCC18
by Mengjin Su
(originally published on "Embedded Systems Design, pp16~21, Sept., 2006. Vol. 19, Num. 9")
PLCC18 v1.00, implemented in 2007, is a newer version of PLC compiler which has been re-written since PLCC18 v0.4x. It does not only have fixed a lot of bugs, but also has some improvements and grammar definition changes. Together with the compiler, it comes with the assembler (AS18) and a linker (LK18). With this change, the intermediate code, generated after assembling, is highly dynamic and locatable. Moreover, PLCC18 v1.00 and higher can support recursive function call, even in PIC18Fxxxx legacy instruction mode!
Why Pointer-less C
Frankly, 'pointer', as well as its related operations, is one of the most important features in C. It brings a tremendous efficiency and power to the language. But on the other side, C programmers, especially those beginners, sometimes complain about the ambiguity and the confusing using pointer in their programming. Today, a lot of MCUs used in embedded applications are in Harvard architecture that allocates ROM and RAM into two separate spaces. Each one needs to be accessed using different scheme or instructions (e.g. all the MCU products from Microchip are in this case). So the standard C pointer and its grammar notations may or may not work.
Pointer-less, Under the hood
PLCC uses different rules or syntax to do the same thing as that in standard C. In PLCC, only those basic data types exist: char, int and long (currently, 'float' data type has not been implemented in PLCC18). The following tables illustrate how PLCC works to access the memory:
'struct' and 'union' operations:
PLCC18 is a small, efficient and easy to use compiler that supports PIC18Fxxxx series MCUs from Microchip. It works on both Windows and Linux platforms, under terminal/console mode. For convenience, we still use '.c' as extension for source files.
At present, only char(8-bit) int(16-bit) and long(32-bit) basic data types are supported (float might be supported in future). All basic arithmetic operations ('+', '-', '*', '/', '%') and logical operations ('&', '|', '^') are supported. Plus, in-line assembly code insertion is allowed. And the following pre-processors are accepted:
#pragma symbol [expression]
#define symbol expression
#define symbol(arg1, arg2, ...) expression
No function recursive calling allowed in version PLCC18 v0.4x! (will be supported in higher version for those PIC devices with extended instruction set)
NOTE: PLCC18 v1.00 adds 'short' as the 24-bit integer type.
 Install the compiler
Unzip and extract all file, and then put them into a folder (e.g. PLCC). And then put the path into the environment, like
[NOTE, you can make batch file (filename with extension '.bat') to set the path].
In this folder, you should see following files:
plcc18.exe - PLCC compiler
as18.exe - PIC18 assembler/linker
lk18.exe - PIC18 assembler/linker
/lib - library folder (legacy instruction mode)
/xlib - library folder (extended instruction mode)
/include - header files holder
 Compiling command:
After compiling, if no error detected, assembly code(file) will be generated for each source file, ended with '.s'. The assembly code is very readable, and you can check what result exactly is.
where the options are:
-L generate assembly code in LIB mode
-s short jump instruction needed (default = long jump instruction)
-Dsymbol<=xxxx> define symbol (with or without value)
 Assembling and linking
where the options are:
-device_name(mandatory) specify PIC device (for example: -pic18f452)
-code=xxxx code start address (default = 0x0000), no space allowed
-data=xxxx RAM data start address (default = 0x0002)
-sp=xxxx specify stack pointer initial value.
 Resources used by Compiler
PLCC18 will use following registers for compilation:
WREG PRODL PRODH FSR0L FSR0H FSR1L FSR1H FSR2L FSR2H TABLAT TBLPTRL TBLPTRH TBLPTRU STATUS BSR
Users should pay great attention when accessing any of those register in the code.
Further more, RAM location 0x0000 and 0x0001 (first two locations in bank0) are reserved for holding function return value (lower 16 bits). User should never use these location for any purpose. Index registers are used by compiler for index addressing. Among them FSR0L and FSR0H are use as software stack pointer. FSR1L, FSR1H, FSR2L and FSR2H are used for temporary storage dynamically*. BSR is cleared at power-on reset, and should never be modified afterwards.
(NOTE*: PICC18 version 0.5x or higher will use FSR2L and FSR2H as the software stack pointer)
 Download PLCC18