
CC5X - C Compiler for the PICmicro Devices

Copyright (c) B Knudsen Data, Trondheim - Norway, 1992-2001


*** INTRODUCTION

Compact code and efficient RAM usage is the strength of CC5X.
Writing code for the PIC controllers is a challenge because of the
limited code and RAM space. The CC5X compiler was designed to offer
assembly level efficiency.

Local variables are supported. The compiler performs a safe
compression by checking the scope of the variables and reusing the
locations when possible. The limited variable space is therefore
used efficiently.

Interrupt support can be tricky. The compiler allows every statement
to be written in C code. Interrupt service routines can contain
local variables and function calls.

The compiler can extend the call level beyond the 2 or 8 level
restrictions by using GOTO statements when possible. This feature is
almost required for the 12 bit core devices having 2 call levels
only.

The bank selection bits are automatically updated using global
optimization. This is a real challenge. The advanced algorithm saves
code space compared to simpler compiler implementations.

The first version was released in April 1992 and contains a lot of
experience from project use. A selected subset of C syntax is
supported. Demo compiler editions can be downloaded and tested.



*** MORE FEATURES:

Main features: 
- Supports midrange PICmicro devices (12 and 14 bit core):
  PIC12CXXX, PIC14CXXX, PIC16CXXX, PIC16F8XX
- Compact code
- 1, 8, 16, 24 and 32 bit variables, signed and unsigned
- Automatic update of the page and bank selection bits
- Efficient reuse of local variable space
- Extended call level by using GOTO instead of CALL when possible
- Inline assembly
- New chip definition files can be created

Generated files:
- Hex file: for chip programming
- Assembly file: for inspection, or as input to assemblers
- List file: for inspection
- COD file: for use by MPLAB, debuggers and simulators
- Error file: list warnings and errors
- Function outline: for inspection of the call structure
- Variable file: for inspection of variable addresses
- Compiler output file: summary of code and RAM usage

Details:
- A RAM allocation map is generated
- Multiplication, division and modulo
- Structures and unions, bitfields, typedef
- Typecast
- Arrays and pointers
- Direct bit manipulation
- Many parameters in function calls
- Easy lookup tables: #pragma return[] = "Hello world"
- Integrated interrupt support
- COD file generated for debugger and MPLAB support
- Configuration info in source code (like oscillator type, code
  protection, etc.)
- Preprocessor offering macro's, conditional compilation and include
  files
- Automatic links to "hidden" subroutines in the PIC16C5X chips
- Access to all assembly instructions through corresponding C
  statements.
- The generated assembly file includes symbolic names and the C
  source code. Many options allows the format to be adapted to suit
  different needs.
- Binary constants: 0b01011000




*** EXAMPLE CODE

All examples are shown with C and assembly statements side by side.
The different formats are all produced by the CC5X compiler by using
different command line options.


************************************************

        processor  16C84

PORTA       EQU   0x05
TRISA       EQU   0x85
Carry       EQU   0
RP0         EQU   5
a           EQU   0x0D
in          EQU   0
out         EQU   1
i           EQU   0x0C

        GOTO main

  ; FILE test\sample1.c
                        ;
                        ;/* global variables */
                        ;char a;
                        ;bit b1, b2;
                        ;
                        ;/* assign names to port pins */
                        ;#pragma bit in  @ PORTB.0
                        ;#pragma bit out @ PORTB.1
                        ;
                        ;void sub( void)
                        ;{
sub
                        ;    char i;      /* a local variable */
                        ;
                        ;    /* generate 20 pulses */
                        ;    for ( i = 0; i < 20; i++)  {
        CLRF  i
m001    MOVLW .20
        SUBWF i,W
        BTFSC 0x03,Carry
        GOTO  m002
                        ;        out = 1;
        BCF   0x03,RP0
        BSF   0x06,out
                        ;        nop();
        NOP  
                        ;        out = 0;
        BCF   0x06,out
                        ;    }
        INCF  i,1
        GOTO  m001
                        ;}
m002    RETURN
                        ;
                        ;void main( void)
                        ;{
main
                        ; /* first decide the initial output level
                        ;    on the output port pins, and then
                        ;    define the input/output configuration.
                        ;    This avoids spikes at the output pins. */
                        ;
                        ;    PORTA =      0b.0010;  /* out = 1 */
        MOVLW .2
        BCF   0x03,RP0
        MOVWF PORTA
                        ;    TRISA = 0b.1111.0001;  /* xxxx 0001 */
        MOVLW .241
        BSF   0x03,RP0
        MOVWF TRISA
                        ;
                        ;    a = 9;
        MOVLW .9
        MOVWF a
                        ;
                        ;    do  {
                        ;        if (in == 0)  /* stop if 'in' is low */
m003    BCF   0x03,RP0
        BTFSS 0x06,in
                        ;             break;
        GOTO  m004
                        ;        sub();
        CALL  sub
                        ;    } while ( -- a > 0);  /* 9 iterations */
        DECFSZ a,1
        GOTO  m003
                        ;
                        ;
                        ;}
m004    SLEEP
        GOTO main

        END
