C2C help index.

(valid from the compiler version 2.0)

Variables
Pointers
Built-in variables
 for PIC target
 for SX target
Arrays
Expressions
Functions
 Special functions
  main
  interrupt
 Built-in functions
Standard C
Built-in assembler
Libraries
Preprocessor
Limitations

Variables.

8-bit and 16-bit variables are supported. They can be defined as
global or local ones. Local variables can have unique
addresses or will share the same address space.
Example:

const char a = 10;

char fun( char a )
{
return a+5;
}

main()
{
char b;
b = 0;
fun( b ); //after the call b will be equal to 5
}

Note by choosing the second option be very careful. A
call of the function which uses local variables may change
the values of the local variables in the calling function.
This option may be useful if local variables are used before
any calls (for example as counters).
Example:

void fun1( void )
{
char a;
a = 10;
}

void fun2( void )
{
char b;
b = 1;
fun1(); //After the call b may be equal to 10
}

Variable can be declared as const. It will be stored
in the program area.

The 8 bit long variables are should be declared as char. The 16 bit long variables may be declared as
short, int or long.
Example:

char x; //8bit variable
short y; //16bit variable
long z; //16bit variable, the same as short z;

One-dimensional arrays are supported. If an array is declared as const it can have only char type.

Built-in variables are supported. They are placed into program space.

Index

Pointers

Only const char * pointers are supported now as shown in the example below:

const char *txt = "This is a text";
output_port_b( txt[1] ); //the 'h' character will be put into port b

Index

Built-in variables

For PIC target:
INDF indf register( 0x00 )
TMR0 8-bit real-time clock/counter( 0x01 )
PCL low order 8 bits program counter( 0x02, 0x82 )
STATUS status register( 0x03, 0x83 )
FSR indirect data memory address pointer( 0x04, 0x84 )
PORTA port A( 0x05 )
PORTB port B( 0x06 )
EEDATA EEPROM data register( 0x08 )
EEADR EEPROM address register( 0x09 )
PCLATH high order 5 bits program counter( 0x0A, 0x8A )
INTCON intcon register( 0x0b, 0x8b )
OPTION_REG option register( 0x81 )
TRISA port A data direction register( 0x85 )
TRISB port B data direction register( 0x86 )
EECON1 EEPROM control register( 0x88 )
EECON2 EEPROM control register( 0x89 )

For SX target:
RTCC real-time clock/counter
PC program counter
STATUS status register
FSR file select register
RA port A
RB port B
RC port C
INDF indf register
Index

Arrays

one-dimensional arrays are supported. They can have only char type.

Example:
char a[35], b[] = { 'A', 'B', 'C', 'D' };

Const arrays are supported. They can have only char type.They have to be initialised.

Example:
const char z[] = { 2, 'x', 0xFE, 012 };

Index

Expressions

8 bit expressions can be as complex as needed.

Example:
~b * 4 <= 8 != c++ - fun(5) / 2

16 bit expressions usually can have only 2 operands.

Examples:
a16 + b16
a16 & b16++

Note that a complex expression will produce temporary variables.

Use 16 bit variables only if you really need them. They need much mode code than 8 bit variables.

The operations *, / and % are supported . The implementation
can be defined as a function or inline code.

Index

Functions

Functions can have void, char, short, int or long return types.
They can have void or several char, short, int or long parameters.
Example:

char fun1( char p1, short p2, char p3 );
short fun2( void );

If the return type is not specified it is char.
Example:

fun( char a ); //is the same as char fun( char a );

If the parameter is not specified it is void.
Example:

fun(); //is the same as char fun( void );

There are two special functions for entry point and interrupt.
Built-in functions can be used to access micro controller features.

Index

Special functions

The special functions are main and interrupt.

main

It is the entry point and should be declared as:

void main( void )

It is called after global variables initialisation.
If main presents in the code some prefix and postfix
code will be added to asm file.
If main is not present only variable table and code will
be produced for asm file. This is done in case the generated
asm file is included into the other asm file.

interrupt

It is the entry point for interrupt. It has no
return value and no parameters and must be declared as:

void interrupt( void )

If no interrupt function is declared there is an option to
add a default one or do not add any.

Index

Built-in functions

clear_wdt
enable_interrupt
disable_interrupt
set_tris_a
set_tris_b
output_port_a
output_port_b
output_high_port_a
output_high_port_b
output_low_port_a
output_low_port_b
input_port_a
input_port_b
input_pin_port_a
input_pin_port_b
sleep
nop
set_bit
clear_bit

void enable_interrupt( NUMBER or MPASM predefined constant );

Enables the relevant interrupt .

Example:
enable_interrupt( GIE );

Index

void clear_wdt( void );

Resets the watchdog timer.

Example:
clear_wdt();

Index

void disable_interrupt(NUMBER or MPASM predefined constant );

Disables the relevant interrupt.

Example:
disable_interrupt( T0IE );

Index

void set_tris_a( expression );

Sets the trisa register by the expression result.

Example:
set_tris_a( a>=10 );

Index

void set_tris_b( expression );

Sets the trisb register by the expression result.

Example:
set_tris_b( a+b+c );

Index

void output_port_a( expression );

Puts the expression result into porta.

Example:
output_port_a( 'A' );

Index

void output_port_b( expression );

Puts the expression result into portb.

Example:
output_port_b( 0xff );

Index

void output_high_port_a( NUMBER or expression );

Sets a pin of porta.

Example:
output_high_port_b( 7 );

Index

void output_high_port_b( NUMBER or expression );

Sets a pin of portb.

Example:
output_high_port_b( x );

Index

void output_low_port_a( NUMBER or expression );

Clears a pin of porta.

Example:
output_low_port_b( i++ );

Index

void output_low_port_b( NUMBER or expression );

Clears a pin of portb.

Example:
output_low_port_b( 0 );

Index

char input_port_a( void );

Inputs from porta.

Example:
while( input_port_a() )

Index

char input_port_b( void );

Inputs from portb.

Example:
a = input_port_b();

Index

char input_pin_port_a( NUMBER );

Inputs from pin of porta.

Example:
if( input_pin_port_a( 7 ) )

Index

char input_pin_port_b( NUMBER );

Inputs from pin of portb.

Example:
a = input_pin_port_b( 0 );

Index

void sleep( void );

Puts the micro controller into sleep mode.

Example:
sleep();

Index

void nop( void );

Generates an empty instruction.

Example:
nop();

Index

void set_bit( VARIABLE, NUMBER or MPASM predefined constant );

Sets a bit in variable.

Example:
set_bit( STATUS, RP0 );

Index

void clear_bit( VARIABLE, NUMBER or MPASM predefined constant );

Clears a bit in variable.

Example:
clear_bit( a, 1 );

Index

Standard C

· if, else, while, for, return, break, continue, extern, switch, case, default;
· goto and labels;
· char, short, int, long, void;
· ~, ++, --, +, -, <, <=, >, >=, ==, !=, =, !, &, |, ^, &&, ||, *, /, %, <<, >>, <<=, >>=;
· one-dimensional arrays;
· const char pointers;
· const variables and arrays;
· functions with no/one/many parameters and void/char/short return types;
· built-in assembler;
· #include
· #define, #undef
· #ifdef, #ifndef, #else, #endif

Index

Built-in assembler

Assembler code can be included into c-code with asm operator.
C- variables or call c-functions calls can be referred to. To refer to
them put underscore in front of variable/function name. In case
a variable is local add underscore and function name after its
name.

Example:

...
char a; //a global variable
...
void fun1( char a )
{
...
}
...
void fun2( void )
{
char b; //a local variable
...
//The code below is equal to b = 5;
asm movlw 5
asm movwf _b_fun2
...
//The code below is equal to fun1( a );
asm
{
movf _a, W
movwf param00_fun1
call _fun1
}
...
}
...

To produce assembler lines started from the left column (for example to produce labels) in the
output .asm file add ':' after the 'asm' keyword.

Example:

asm: myLabel
asm:
{
myOtherLabel
}

Index

Libraries

The compiler can generate and consume libraries.

Index

Preprocessor

The supported preprocessor directives are listed below:
#include "file_name"
#include
The directive inserts the contents of the file specified by file_name into the current file.
#define identifier
#define identifier subs_text
The directive replaces all subsequent cases of identifier with the subst_text.
#ifdef identifier The directive tests whether identifier is currently defined.
#ifndef identifier The directive tests whether identifier is currently undefined.
#else
#endif
#undef identifier The directive removes the current definition of identifier.

The predefined identifiers:
_C2C_ is always defined
_EXT_VERSION_ defined in extended version
_PIC defined if PIC target is selected
_SX _SX defined if SX target is selected
Index

Limitations

The compiler has the following limitations:
· SX target doesn't support 16bit arithmetic;
· function calls usually can not be used in expressions which contain 16bit operands;
· a 16bit expression usually can have only 2 operands;
· only one type of auto arrays is supported: char;
· only one constant type is supported: const char;
· the const array size can not exceed 256 bytes;
· the maximum function parameter number is 32.

These limitations are ranged. The ones in the beginning probably will be solved in the coming compiler
releases (after the version 2.0).

Index