C2C help index.(valid from the compiler version 3.27.3) |
const char a = 10;
char fun( char a )
{
return a+5;
}
main()
{
char b;
b = 0;
b = 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.
<address> + <bank_number> * 16
Example for the PIC target:
char a@20; //Variable ‘a’ will be placed on address
20
char b@0x20; //Variable ‘b’ will be placed on address 32
Example for the SX target:
char a@32; //Variable ‘a’ will be placed on address
0
//bank 0
char b@0x31; //Variable ‘b’ will be placed on address 17
//bank 1
char c@85; //Variable ‘c’ will be placed on address 21
//bank 2
const char *txt = "This is a text";
output_port_b( txt[1] ); //the ‘h’ will be put into port b
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 ) |
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 |
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 };
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.
char fun1( char p1, short p2, char p3 );
short fun2( void );
void printf( const char* );
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.
To place a function on an absolute address place @ 0x<ADDR>
after it.
Example:
//This function will be placed started from 0x200
void fun( void ) @ 0x200
{
…
}
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.
The main code has separate from the interrupt code temporary variables.
void interrupt( void )
If no interrupt function is declared there is an option to
add a default one or do not add any.
The interrupt code has separate from the main code temporary variables.
void enable_interrupt( NUMBER or MPASM predefined constant );
Enables the relevant interrupt .
Example:
enable_interrupt( GIE );
Resets the watchdog timer.
Example:
clear_wdt();
void disable_interrupt(NUMBER or MPASM predefined constant );
Disables the relevant interrupt.
Example:
disable_interrupt( T0IE );
Sets the mode register by the expression result (only for the SX target).
Example:
set_mode( 10 );
void set_option( expression );
Sets the option register by the expression result (only for the SX target).
Example:
set_option( 0 );
void set_tris_a( expression );
Sets the trisa register by the expression result.
Example:
set_tris_a( a>=10 );
void set_tris_b( expression );
Sets the trisb register by the expression result.
Example:
set_tris_b( a+b+c );
void set_tris_c( expression );
Sets the trisc register by the expression result.
Example:
set_tris_c( 'A' );
void output_port_a( expression );
Puts the expression result into porta.
Example:
output_port_a( ‘A’ );
void output_port_b( expression );
Puts the expression result into portb.
Example:
output_port_b( 0xff );
void output_port_c( expression );
Puts the expression result into portc.
Example:
output_port_c( 0xff );
void output_high_port_a( NUMBER );
Sets a pin of porta.
Example:
output_high_port_b( 7 );
void output_high_port_b( NUMBER );
Sets a pin of portb.
Example:
output_high_port_b( 6 );
void output_high_port_c( NUMBER );
Sets a pin of portc.
Example:
output_high_port_c( 0 );
void output_low_port_a( NUMBER );
Clears a pin of porta.
Example:
output_low_port_b( 1 );
void output_low_port_b( NUMBER );
Clears a pin of portb.
Example:
output_low_port_b( 0 );
void output_low_port_c( NUMBER );
Clears a pin of portc.
Example:
output_low_port_c( 04 );
Inputs from porta.
Example:
while( input_port_a() )
Inputs from portb.
Example:
a = input_port_b();
Inputs from portc.
Example:
x = input_port_c();
char input_pin_port_a( NUMBER );
Inputs from pin of porta.
Example:
if( input_pin_port_a( 7 ) )
char input_pin_port_b( NUMBER );
Inputs from pin of portb.
Example:
a = input_pin_port_b( 0 );
char input_pin_port_c( NUMBER );
Inputs from pin of portb.
Example:
a = input_pin_port_c( 5 );
Puts the micro controller into sleep mode.
Example:
sleep();
Generates an empty instruction.
Example:
nop();
void set_bit( VARIABLE, NUMBER or MPASM predefined constant );
Sets a bit in variable.
Example:
set_bit( STATUS, RP0 );
void clear_bit( VARIABLE, NUMBER or MPASM predefined constant );
Clears a bit in variable.
Example:
clear_bit( a, 1 );
Writes a character into RS232 port. The RS232 parameters could be setup
using pragmas :
RS232_TXPORT, RS232_TXPIN, RS232_BAUD, TRUE_RS232, CLOCK_FREQ, TURBO_MODE.
Example:
putchar( 'A' );
Reads a character from RS232 port. Doesn't return till a character is
read. The RS232 parameters could be setup using pragmas
:
RS232_RXPORT, RS232_RXPIN, RS232_BAUD, TRUE_RS232, CLOCK_FREQ, TURBO_MODE.
Example:
a = getchar();
Delays for the given number of seconds. The timing parameters could
be setup using pragmas :
CLOCK_FREQ, TURBO_MODE.
Example:
delay_s( 15 ); //delays for 15 seconds
Delays for the given number of milliseconds. The timing parameters could
be setup using pragmas :
CLOCK_FREQ, TURBO_MODE.
Example:
delay_ms( 100 ); //delays for 100 milliseconds
Delays for the given number of microseconds. The timing parameters could
be setup using pragmas :
CLOCK_FREQ, TURBO_MODE.
Example:
delay_us( d ); //delays for d microseconds
char char_to_bcd( expression );
Converts the expression result into a BCD number and returns it. The expression result must be between 0 and 99.
Example:
output_port_b( char_to_bcd( 10 ) ); //write 10(bcd) into port
B
char bcd_to_char( expression );
Converts the expression result as a BCD value into a decimal number and returns it. The expression result must a valid BCD number.
Example:
a = bcd_to_char( input_port_b() ); //reads port B as a BCD number
and converts it into decimal
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
}
Example:
char b;
...
//The code below is equal to b = 5;
asm mov w, #5
asm bank _b
asm mov _b, w
The library stores all conditional directives and all code from the files the library was built from.
#include "file_name"
#include <file_name> |
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 |
#pragma RS232_RXPORT <num> | Port used to receive RS232 data. Default value is PORTA. |
#pragma RS232_TXPORT <num> | Port used to transmit RS232 data. Default value is PORTA. |
#pragma RS232_RXPIN <num> | Pin used to receive RS232 data. Default value is 1. |
#pragma RS232_TXPIN <num> | Pin used to transmit RS232 data. Default value is 2. |
#pragma RS232_BAUD <num> | RS232 baudrate. Default value is 9600bps. |
#pragma TRUE_RS232 <num> | Voltage level for '1' and '0' is SR232 communication. Default value is 1 ( high level for '1' and low level for '0') |
#pragma CLOCK_FREQ <num> | Processor clock frequency in Hz. Default value for PIC is 4000000 and for SX 50000000. |
#pragma TURBO_MODE <num> | Processor mode. Used only for SX (ignored for PIC). Default value is 1. |
Data Type | Syntax | Example |
Decimal | XXXXX | 1563 |
Octal | 0XXXX | 0234 |
Hexadecimal | 0xXXXX | 0xFFA8 |
Binary | XXXXXb | 10000001b |
ASCII | 'X' | 'S' |
These limitations are ranged. The ones in the beginning probably will
be solved in the coming compiler
releases.