CCS C Compiler Manual
PCD
July 2016
ALL RIGHTS RESERVED.
Copyright Custom Computer Services, Inc. 2016
i
PCD 07202016.doc
Table of Contents
Overview ........................................................................................................................... 15
C Compiler..................................................................................................................... 15
PCD ............................................................................................................................... 15
Technical Support.......................................................................................................... 16
Directories ..................................................................................................................... 16
File Formats................................................................................................................... 17
Invoking the Command Line Compiler ........................................................................... 19
PCW Overview .............................................................................................................. 21
Menu ............................................................................................................................. 22
Editor Tabs .................................................................................................................... 22
Slide Out Windows ........................................................................................................ 22
Editor ............................................................................................................................. 23
Debugging Windows ...................................................................................................... 23
Status Bar ...................................................................................................................... 24
Output Messages .......................................................................................................... 24
Program Syntax ................................................................................................................ 25
Overall Structure............................................................................................................ 25
Comment ....................................................................................................................... 25
Trigraph Sequences ...................................................................................................... 27
Multiple Project Files ..................................................................................................... 27
Multiple Compilation Units ............................................................................................. 28
Full Example Program ................................................................................................... 28
Statements ........................................................................................................................ 31
Statements .................................................................................................................... 31
if..................................................................................................................................... 32
while .............................................................................................................................. 33
do-while ......................................................................................................................... 33
for .................................................................................................................................. 33
switch ............................................................................................................................ 34
return ............................................................................................................................. 35
goto ............................................................................................................................... 35
label ............................................................................................................................... 35
break ............................................................................................................................. 36
continue ......................................................................................................................... 36
expr ............................................................................................................................... 37
; ..................................................................................................................................... 37
stmt................................................................................................................................ 37
Expressions ...................................................................................................................... 39
Constants ...................................................................................................................... 39
Identifiers ....................................................................................................................... 40
Operators....................................................................................................................... 40
ii
Table of Contents
Operator Precedence .................................................................................................... 42
Data Definitions ................................................................................................................. 43
Data Definitions ............................................................................................................. 43
Type Specifiers .............................................................................................................. 43
Type Qualifiers .............................................................................................................. 44
Enumerated Types ........................................................................................................ 46
Structures and Unions ................................................................................................... 46
typedef ........................................................................................................................... 47
Non-RAM Data Definitions ............................................................................................ 48
Using Program Memory for Data ................................................................................... 50
Named Registers ........................................................................................................... 52
Function Definition ............................................................................................................ 53
Function Definition ......................................................................................................... 53
Overloaded Functions ................................................................................................... 54
Reference Parameters .................................................................................................. 54
Default Parameters........................................................................................................ 55
Variable Argument Lists ................................................................................................ 55
Functional Overview.......................................................................................................... 57
I2C ................................................................................................................................. 57
ADC ............................................................................................................................... 58
Analog Comparator ....................................................................................................... 59
CAN Bus ........................................................................................................................ 60
Code Profile ................................................................................................................... 64
Configuration Memory ................................................................................................... 65
CRC ............................................................................................................................... 66
DAC ............................................................................................................................... 67
Data Eeprom ................................................................................................................. 68
DCI ................................................................................................................................ 69
DMA .............................................................................................................................. 70
Data Signal Modulator ................................................................................................... 72
Extended RAM .............................................................................................................. 73
General Purpose I/O...................................................................................................... 74
Input Capture ................................................................................................................. 75
Internal Oscillator........................................................................................................... 76
Interrupts ....................................................................................................................... 77
Output Compare/PWM Overview .................................................................................. 78
Motor Control PWM ....................................................................................................... 79
PMP/EPMP.................................................................................................................... 81
Program Eeprom ........................................................................................................... 82
QEI ................................................................................................................................ 84
RS232 I/O ...................................................................................................................... 85
RTCC ............................................................................................................................ 88
RTOS ............................................................................................................................ 89
SPI................................................................................................................................. 91
Timers ........................................................................................................................... 93
iii
PCD 07202016.doc
TimerA ........................................................................................................................... 94
TimerB ........................................................................................................................... 95
Voltage Reference ......................................................................................................... 96
WDT or Watch Dog Timer ............................................................................................. 97
interrupt_enabled() ........................................................................................................ 98
Stream I/O ..................................................................................................................... 98
PreProcessor .................................................................................................................. 101
PRE-PROCESSOR DIRECTORY ............................................................................... 101
__address__ ................................................................................................................ 101
_attribute_x .................................................................................................................. 102
#asm
#endasm #asm asis ................................................................................. 103
#bank_dma .................................................................................................................. 111
#bankx ......................................................................................................................... 112
#banky ......................................................................................................................... 112
#bit............................................................................................................................... 113
__buildcount__ ............................................................................................................ 114
#build ........................................................................................................................... 114
#byte ............................................................................................................................ 116
#case ........................................................................................................................... 116
_date_ ......................................................................................................................... 117
#define ......................................................................................................................... 118
definedinc .................................................................................................................... 119
#device ........................................................................................................................ 120
_device_ ...................................................................................................................... 123
#if expr
#else #elif #endif ..................................................................................... 124
#error ........................................................................................................................... 125
#export (options).......................................................................................................... 125
__file__ ........................................................................................................................ 127
__filename__ ............................................................................................................... 127
#fill_rom ....................................................................................................................... 128
#fuses .......................................................................................................................... 128
#hexcomment .............................................................................................................. 129
#id................................................................................................................................ 130
#if expr
#else #elif #endif ..................................................................................... 131
#ifdef
#ifndef #else #elif #endif......................................................................... 132
#ignore_warnings ........................................................................................................ 132
#import (options).......................................................................................................... 133
#include ....................................................................................................................... 134
#inline .......................................................................................................................... 135
#int_xxxx ..................................................................................................................... 136
Syntax:
....................................................................................................................... 136
#INT_DEFAULT .......................................................................................................... 140
__line__ ....................................................................................................................... 140
#list .............................................................................................................................. 141
#line ............................................................................................................................. 141
iv
Table of Contents
#locate ......................................................................................................................... 142
#module ....................................................................................................................... 143
#nolist .......................................................................................................................... 144
#ocs ............................................................................................................................. 144
#opt ............................................................................................................................. 145
#org ............................................................................................................................. 145
#pin_select .................................................................................................................. 147
__pcd__ ....................................................................................................................... 151
#pragma ...................................................................................................................... 151
#profile ......................................................................................................................... 152
#recursive .................................................................................................................... 153
#reserve ...................................................................................................................... 153
#rom ............................................................................................................................ 154
#separate .................................................................................................................... 155
#serialize ..................................................................................................................... 156
#task ............................................................................................................................ 158
__time__ ...................................................................................................................... 159
#type ............................................................................................................................ 160
#undef ......................................................................................................................... 162
_unicode ...................................................................................................................... 162
#use capture ................................................................................................................ 163
#use delay ................................................................................................................... 165
#use dynamic_memory ............................................................................................... 166
#use fast_io ................................................................................................................. 167
#use fixed_io ............................................................................................................... 167
#use i2c ....................................................................................................................... 168
#use profile()................................................................................................................ 170
#use pwm() .................................................................................................................. 170
#use rs232 ................................................................................................................... 172
#use rtos ...................................................................................................................... 178
#use spi ....................................................................................................................... 179
#use standard_io ......................................................................................................... 181
#use timer .................................................................................................................... 182
#use touchpad ............................................................................................................. 184
#warning ...................................................................................................................... 185
#word ........................................................................................................................... 185
#zero_ram ................................................................................................................... 186
Built-in Functions............................................................................................................. 189
BUILT-IN FUNCTIONS ................................................................................................ 189
abs( ) ........................................................................................................................... 189
sin( )
cos( ) tan( ) asin( ) acos() atan() sinh() cosh() tanh() atan2() .................. 190
adc_done( )
adc_done2( ) .................................................................................... 191
adc_read() ................................................................................................................... 192
adc_status() ................................................................................................................. 193
adc_write() ................................................................................................................... 193
v