CC5X C compiler for PICmicro

CC5X
PRICES
BUY NOW
DOWNLOAD

Introduction
Features
- math library
- installation and
  MPLAB support
- supported chips

Examples red_ball.gif (129 bytes)
FAQ
NEWS
Planned
Feedback
Support
Links
Distributors

CC8E
Leanslice
HOME

Example code

The example code are supplied in TXT files including the generated ASM files.
(Please use the BACK button on your browser to get back to this page).

int16xx.txt   (asm) : simple interrupt example
delay.txt      (asm) : implementing delays
state.txt       (asm) : state machine example
serial.txt      (asm) : simple serial data receiving and sending
div16_8.txt (asm) : fast unsigned divide, 16 bit / 8 bit
fmath1.txt   (-asm) : fixed and floating point math example
scaling.txt   (asm) : linear scaling, up to 16 bit

Small C example

The remaining of this page contains a small C program example and some of the files generated by CC5X.

  1. SAMPLE1.C        ;source code
  2. SAMPLE1.OCC  ;compiler output file
  3. SAMPLE1.ASM  ;generated assembly file
  4. SAMPLE1.FCS   ;function call structure
  5. SAMPLE1.VAR  ;variable layout

 

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)
{
    char i;      /* a local variable */

    /* generate 20 pulses */
    for ( i = 0; i < 20; i++)  {
        out = 1;
        nop();
        out = 0;
    }
}

void main( void)
{
    // if (TO == 1 && PD == 1 /* power up */)  {
    //   WARM_RESET:
    //     clearRAM(); // clear all RAM if required
    // }

 /* 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 */
    TRISA = 0b.1111.0001;  /* xxxx 0001 */

    a = 9;  /* value assigned to global variable */

    do  {
        if (in == 0)  /* stop if 'in' is low */
             break;
        sub();
    } while ( -- a > 0);  /* 9 iterations */

    // if (some condition)
    //    goto WARM_RESET;

    /* main is terminated by a SLEEP instruction */
}

SAMPLE1.OCC

CC5X Version 3.1A, Copyright (c) B Knudsen Data, Norway 1992-2000
 --> STANDARD edition, 8-24 bit int, 24-32 bit float, 8k code
test\sample1.c:
 28. Oct 2000  10:50
 Chip = 16C54
 RAM: 00h : -------= .6****** ******** ********
RAM usage: 3 bytes (1 local), 22 bytes free
 File 'sample1.fcs'
 Optimizing - removed 3 instructions (-11 %)
 File 'sample1.var'
 File 'sample1.asm'
 File 'sample1.lst'
 File 'sample1.cod'
 File 'sample1.hex'
Total of 24 instructions (4 %)

SAMPLE1.ASM

; CC5X Version 3.1A, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************  28. Oct 2000  10:50  *************

        processor  16C54
        radix  DEC

PORTA       EQU   0x05
Carry       EQU   0
a           EQU   0x08
in          EQU   0
out         EQU   1
i           EQU   0x07

  ; 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;
        BSF   0x06,out
                        ;        nop();
        NOP  
                        ;        out = 0;
        BCF   0x06,out
                        ;    }
        INCF  i,1
        GOTO  m001
                        ;}
m002    RETLW .0
                        ;
                        ;void main( void)
                        ;{
main
                        ;    // if (TO == 1 && PD == 1 /* power up */)  {
                        ;    //   WARM_RESET:
                        ;    //     clearRAM(); // clear all RAM if required
                        ;    // }
                        ;
                        ; /* 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
        MOVWF PORTA
                        ;    TRISA = 0b.1111.0001;  /* xxxx 0001 */
        MOVLW .241
        TRIS  PORTA
                        ;
                        ;    a = 9;  /* value assigned to global variable */
        MOVLW .9
        MOVWF a
                        ;
                        ;    do  {
                        ;        if (in == 0)  /* stop if 'in' is low */
m003    BTFSS 0x06,in
                        ;             break;
        GOTO  m004
                        ;        sub();
        CALL  sub
                        ;    } while ( -- a > 0);  /* 9 iterations */
        DECFSZ a,1
        GOTO  m003
                        ;
                        ;    // if (some condition)
                        ;    //    goto WARM_RESET;
                        ;
                        ;    /* main is terminated by a SLEEP instruction */
                        ;}
m004    SLEEP

        ORG 0x01FF
        GOTO main
        END

SAMPLE1.FCS

CC5X Version 3.1A, Copyright (c) B Knudsen Data.
* FUNCTION CALL STRUCTURE

F: sub                    :#1 

F: main                   :#0 
    sub                   : #1 


 L0  main
 L1    sub

SAMPLE1.VAR

CC5X Version 3.1A, Copyright (c) B Knudsen Data.
* VARIABLE LIST FILE
Source 'test\sample1.c'
Chip = 16C54

=== Sorted by address ===

   [-] 0x000   :  0:  INDF
   [-] 0x001   :  0:  TMR0
   [-] 0x002   :  0:  PCL
   [-] 0x003   :  0:  STATUS
   [-] 0x003.0 :  1:  Carry
   [-] 0x003.1 :  0:  DC
   [-] 0x003.2 :  0:  Zero_
   [-] 0x003.3 :  0:  PD
   [-] 0x003.4 :  0:  TO
   [-] 0x003.5 :  0:  PA0
   [-] 0x003.6 :  0:  PA1
   [-] 0x003.7 :  0:  PA2
   [-] 0x004   :  0:  FSR
   [-] 0x004.5 :  0:  FSR_5
   [-] 0x004.6 :  0:  FSR_6
   [-] 0x005   :  2:  PORTA
   [-] 0x006   :  0:  PORTB
 R [-] 0x006.0 :  1:  in
 R [-] 0x006.1 :  2:  out
 L [-] 0x007   :  3:  i
 G [-] 0x008   :  2:  a
 G [-] 0x009.0 :  0:  b1
 G [-] 0x009.1 :  0:  b2

End line