User Tools

Site Tools


С compiler for PIC16 microcontrollers

Some time ago I developed a simple C compiler for Microchip PIC16 microcontrollers.

The package contains:

  • C compiler
  • Assembler with original mnemonics
  • Disassembler
  • Target defines for PIC 12C5xx family

Simplified language

The language is very simplified.

1) No structs, unions and typedefs. No float point.

2) Functions may have not more that two arguments. The total size of arguments cannot exceed 4 bytes.

3) Size of long is 4 bytes, short - 2 bytes, char and int - 1 byte. The simple pointer has the size of 1 byte, far pointer - 2 bytes.

4) The type of pointer to pointer is equivalent to (char*) for simple pointers, and (short*) for far pointers.

5) All functions must be declared before use. The argument lists in function declarations are not supported.

6) Bit operations are supported, for example:

if (a.1)
	b.4 = 1;

The only operations for bits are:

  • assignment of zero (a.N = 0);
  • assignment of one (a.N = 1);
  • xor with one (a.N ^= 1);
  • conditional check (if (a.N) or if (! a.N)).

7) Direct placement of data and functions is supported, for example:

short PROD @ 0x18;
void startup () @ 0
{ ... }

The startup() function will be placed in command memory at address 0, the variable PROD references the data memory at address 18h.

pic/pic16-c-compiler.txt · Last modified: 2022/05/15 22:26 by

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki