CCS C Compiler
The compiler is comprised with Standard C operators and built-in libraries that are
specific to PIC
®
MCU registers, and access to hardware features from C.
PIC10 / PIC12 / PIC14 / PIC16 / PIC18
1, 8, 16, 32-bit integer types & 32-bit floating point
Bit Arrays and Fixed Point Decimals
#BIT and #BYTE will allow C variables to be
placed at absolute addresses to map registers
to C variables
Standard one-bit type (Short Int) permits the
compiler to generate very efficient Bit-oriented code
Constants (including strings and arrays) are
saved in program memory
Flexible Handling of Constant Data
Variable length Constant Strings
AddressMod capability to create user defined
address spaces in memory device
Constants in ROM
Enhanced oscillator control to choose from
a multitude of clock sources, PLL and power
saving options
Function recursion allows for interactive
processing algorithms
#BIT #BYTE and #WORD will allow C variables
,
to be placed at absolute addresses to map registers
Features
Advanced Features in PIC24 & dsPIC
®
DSCs
Also 48 & 64-bit floating point make calculations
requiring greater precision or broader range easier
Processor &
Peripheral Controls
The CCS C Compiler for PIC10, PIC12,
PIC14, PIC16, PIC18 and PIC24
microcontrollers has over 180 Built-in-
Functions to access PIC® MCU hardware
is easy and produces efficient and highly
optimized code.
Functions such as timers, A/D, EEPROM,
SSP PSP USB, I2C and more:
,
,
• Built-in libraries that work with all chips for RS-232 serial I/O, I
2
C,
discrete I/O and precision delays
• Serial I/O functions allow standard functions such as GETC() and
PRINTF() to be used for RS-232 like I/O
• Formatted printf allows for easy formatting and display in HEX or
decimal
• Multiple I
2
C and RS232 ports may be easily defined
• #use rs232() offers options to specify a maximum wait time for getc
• Hardware transceiver used when possible, but for all other occasions
the compiler generates a software serial transceiver
• Microcontroller clock speed may be specified in a PRAGMA to
permit built-in functions to delay for a given number of microseconds
or milliseconds
• Functions such as INPUT() and OUTPUT_HIGH() properly maintain
the tri-state registers
• Compiler directives determine if tri-state registers are refreshed on
every I/O or if the I/O is as fast as possible
• #USE SPI ()
• Simple functions like READ_ADC() to read a value from A/D
converter
• Source code drivers included for LCD modules, keypads, 24xx and
94xx serial EEPROM, X10, DS1302 and NJU6355 real time clocks,
Dallas touch memory devices, DS2223 and PCF8570, LTC1298
and PCF8591 A/D converters, temperature sensors, digital pots, I/O
expander and much more
Advanced
Functions
The compiler can handle inline or
separate functions, as well as parameter
passing in re-usable registers.
Transparent to the user, the compiler
handles calls across pages automatically
and analyzes program structure and
call tree processes to optimize RAM and
ROM Usage.
Additional features include:
• Efficient function implementation allow call trees deeper than the
hardware stack
• Automatic linking handles multiple code pages
• Assembly code may be inserted anywhere in the source and may
reference C variables
• Function Overloading allows for several functions with the same
name, but differences in number and type of parameters
• Default Parameters can be used in a function if arguments are not
used in a call
• Interrupt functions supported on PCM/PCH. The compiler generates
all startup and clean up code as well as identifying the correct
function to be called
• Reference parameters may be used to improve code readability and
inline function efficiency
• Generation Of Multiple HEX Files For Chips With External Memory
• Variable Number Of Parameters in a function
• Relocatable Objects / Multiple Compilation Unit (IDE Only)
• Automatic #fuses Configuration
Complete Example Programs
LCD
A/D
PWM
Comparator
PSP
Serial Interrupts
Magnetic Card Reader
Frequency counter
7 Seg LED
Data Logger
Pattern Generator
Stepper Motors
Tone Generation
Temperature Sensor
Fixed Point
TCP/IP
Floating Point
ICD Debugging
Advanced Macros
Memory Management
I2C
DTMF Tones
CRC Calculator
CCP
Watchdog Timer
Analog Comparator
Optical Encoder
USB
Boot Loader
CAN Bus
I/O for 8-in Parts
Sleep
Timers
Included C Driver:
Serial EEPROM/Flash
2041
24xx
25xx
93xx
AT2421
AT25256
AT29C1024
AT45DB021
CE51x
CE62x
CE67x
9512
MMC/SD
DS2?? (1-wire EEPROM)
A/D & D/A Converters
AD7705AD7715
ADS8320
LTC1298
MAX517
MCP4921
MCP3204
MCP3208
TLC545N
Real-Time Clock
DS1302
NJU6355
DS1305
ISL1209
LCD
GLCD
KS0108
LCD
LCD420
SED1335
Expanded Input/Output
74165
74595
MAX7300
SC28L19x
Other
Digital Compass
Keypad
Mag Card REader
PLL Inteface
Dallas One Wire
Sounds
WTS701
TONES
ISD4003
HDM64GS12
Serial RAM
68HC68R1
IR Decoder
Line Tracker
Servo Control
X10
Cyclic Redundancy Code
RS485
N9085UD
PNI11096
Temperature
DS1621
DS162M
68HC68R2
M68AF031
PCF8570
D41256
MT4264
Digital Pots
AD8400
DS1868
MCP41010
RFID
EM4095
EM4402
EM4150
DS1631
DS1624
LM75CIM3
Networking/Internet
CAN Functionality
TCP
PPP
S7600
RTL8019
ENC28J60
LMX2326
USB
Robotics
GP2D12
Line Tracking Sensors
USBN960x
PIC_USB
PIC18_USB
Accelerometer
ADXL210
MCP251x
8xxx8
18F4580
Seconds Counter
#include <18F4520.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use_delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define INTS_PER_SECOND 76
BYTE seconds;
BYTE int_count:
// (20000000/(4*256*256))
// A running seconds counter
// Number of interrupts left before a
// second has elapsed
//
//
//
//
This function is called every time
the RTCC (timer0) overflows (255->0).
For this program this is
apx 76 times per second.
Simple A/D
#include<16F877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main() {
int i, value, min, max;
printf(“Sampling:”);
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
do {
//Takes 30 samples from
min=255;
//pin A0 and displays the min and
max=0;
//max values for that 100ms peroid
for(i=0; I <= 30; ++i) {
delay_ms(100);
value=read_adc();
if(value < min)
min = value:
if(value > max)
max = value;
}
printf(“\n\rMin:%x MAX: %x”, min, max);
} while (TRUE);
}
#int_rtcc
void clock_isr() {
if(--int_count=0) {
++seconds;
int_count=INTS_PER_SECOND;
}
}
void main() {
BYTE start:
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_coutner(RTCC_INTERNAL, RTCC_DIV_256 | RTCC_*BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
{
printf(“Press any key to begin.\n\r”);
getc();
start=seconds;
printf(“Press any key to stop.\n\r”);
getc();
printf(“%u seconds.\n\r”,seconds-start);
}while (TRUE);
}
Preprocessors
STANDARD C
#define
#else
#elif
#endif
#error
#if
#ifdef
#include
#pragma
#undef
#ifndef
#list
#nolist
FUNCTION QUALIFIERS
#inline
#int_default
#int_global
#int_xxx
#separate
RTOS
#use rtos
#task
(RTOS only in PCW
and PCWH packages)
PRE-DEFINED IDENTIFIERS
_date_
_device_
_file_
_line_
_pcb_
MEMORY CONTROL
#asm
#bit
#byte
#endasm
#fill_rom
#locate
#reserve
#rom
#zero_ram
#org
COMPILER CONTROL
#case
#opt
#priority
#ignore_warnings
#export
#import
#module
BUILT-IN LIBRARIES
DEVICE SPECIFICATION
#device chip
#fuses
#id
#id checksum
#id number
#serialize
#hexcomment
#use delay
#use fast_io
#use fixed_io
#use i2c
#use rs232
#use standard_io
#use spi
_pcm_
_pch_
_time_
_filename_
LINKER
#import
#export
#build
#type
#word
Example C/ASM Listing
...................done=FALSE;
09C: BCF 3B, 1
...................while (!done&input(PIN_B2)) {
09D: BTFSC 3B, 1
09E: GOTO 0BC
09F: BTFSS 06, 2
0A0: GOTO 0BC
...................
level=limit*16;
0A1: MOVF 3D, W
0A2: MOVWF 3C
0A3: SWAPF 3C, F
0A4: MOVLW F0
0A5: ANDWF 3C, F
...................
if(get_rtcc()>71)
0A6: MOVF 01, W
0A7: MOVWF 20
0A8: MOVLW 48
0A9: SUBWF 20, W
0AA: BTFSS 03, 0
0AB: GOTO OAE
...................
output_high(PIN_B1);
0AC: BSF 06, 1
...................
else
0AD: GOTO 0AF
...................
output_low(PIN_B1);
0AE: BCF 06, 1
...................
if(++limit==0x24)
0AF: INCF 3D, F
0B0: MOVLW 24
0B1: SUBWF 3D, W
0B2: BTFSC 03,2
...................
limit=0;
0B3: CLRF 3D
...................
output_bit(PIN_B3,
...................
shift_left(&data,1,0));
0B4: BCF 03, 0
0B5: RLF 2D, F
0B6: BTFSC 03, 0
0B7: GOTO 0BA
0B8: BCF 06, 3
0B9: GOTO 0BB
0BA: BSF 06, 3
Standard C Syntax
•
if, else, while, do, switch, case,
for, return, goto, break, continue
•
! ˜ ++ -- * = = , & |
•
*/% << >> ^ && || ? :
•
<= < > >= == !=
•
= += -= *= /= %= >>= <<= &= ^=m |=
•
typedef, static, suto, const, enum, struct, union
•
Arrays up to 5 subscripts
•
Structures and Unions may be nested
•
Custom bit fields (1-8 bits) within structures
•
ENUMerated types
•
CONstant variables, arrays, structures, and strings
•
Full function parameter support (any number and kind)
•
C++ reference parameters and comments allowed
Standard C Syntax
•
Supports user defined data storage locations
•
C data types may reside in any type of storage
•
User-defined access routines
•
Implements a virtual memory scheme
•
Located C data in program memory
•
Targets with external memory can use the
external bus for data