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
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.
const char *txt = "This is a text";
output_port_b( txt[1] ); //the 'h' character 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 );
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.
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.
void interrupt( void )
If no interrupt function is declared there is an option to
add a default one or do not add any.
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 );
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 );
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_high_port_a( NUMBER or expression );
Sets a pin of porta.
Example:
output_high_port_b( 7 );
void output_high_port_b( NUMBER or expression );
Sets a pin of portb.
Example:
output_high_port_b( x );
void output_low_port_a( NUMBER or expression );
Clears a pin of porta.
Example:
output_low_port_b( i++ );
void output_low_port_b( NUMBER or expression );
Clears a pin of portb.
Example:
output_low_port_b( 0 );
Inputs from porta.
Example:
while( input_port_a() )
Inputs from portb.
Example:
a = input_port_b();
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 );
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 );
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
}
#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 |
These limitations are ranged. The ones in the beginning probably will
be solved in the coming compiler
releases (after the version 2.0).