PCD COMMAND LINE COMPILER Custom Computer Services Inc (CCS), PCD COMMAND LINE COMPILER Datasheet
![PCD C-COMPILER PIC24, DSPIC](/photos/9/32/93268/pcd_command_line_compiler_sml.jpg)
PCD COMMAND LINE COMPILER
Specifications of PCD COMMAND LINE COMPILER
Related parts for PCD COMMAND LINE COMPILER
PCD COMMAND LINE COMPILER Summary of contents
Page 1
PCD C Compiler Reference Manual January 2011 ...
Page 2
...
Page 3
... This manual documents software version 4. Review the readme.txt file in the product directory for changes made since this version. Copyright © 1994, 2011 Custom Computer Services, Inc. All rights reserved worldwide. No part of this work may be reproduced or copied in any form or by any means- electronic, graphic, or mechanical, including photocopying, recording, taping, or ...
Page 4
...
Page 5
Overview ........................................................................................................................................................ 1 PCD ................................................................................................................................................1 Technical Support ........................................................................................................................1 Directories ....................................................................................................................................2 File Formats ..................................................................................................................................2 Invoking the Command Line Compiler .......................................................................................4 PCW Overview ..............................................................................................................................6 Program Syntax ........................................................................................................................................... 17 Overall Structure ........................................................................................................................ 17 Comment ..................................................................................................................................... 17 Trigraph Sequences ................................................................................................................... 19 Multiple Project Files ...
Page 6
Functional Overviews ................................................................................................................................. 53 I2C................................................................................................................................................ 53 ADC ............................................................................................................................................. 54 Analog Comparator .................................................................................................................... 56 CAN Bus ...................................................................................................................................... 57 Configuration Memory ............................................................................................................... 60 CRC ............................................................................................................................................. 61 DAC ............................................................................................................................................. 62 Data Eeprom ............................................................................................................................... 63 DCI ............................................................................................................................................... 64 DMA ............................................................................................................................................. 65 General Purpose I/O ...
Page 7
#HEXCOMMENT...................................................................................................................... 114 #ID ............................................................................................................................................ 114 #IF exp #ELSE #ELIF #ENDIF ................................................................................................ 115 #IFDEF #IFNDEF #ELSE #ELIF #ENDIF ................................................................................ 116 #IGNORE_WARNINGS ........................................................................................................... 117 #IMPORT (options) ................................................................................................................. 117 #INCLUDE ............................................................................................................................... 119 #INLINE .................................................................................................................................... 119 #INT_xxxx ................................................................................................................................ 120 #INT_DEFAULT ....................................................................................................................... 123 __LINE__ ................................................................................................................................. ...
Page 8
Built-in-Functions ..................................................................................................................................... 155 BUILT-IN-FUNCTIONS .............................................................................................................. 155 abs( ) ........................................................................................................................................ 159 adc_done( ) adc_done2( ) ...................................................................................................... 159 assert( ) ................................................................................................................................... 160 atoe( ) ....................................................................................................................................... 160 atof( ) atof48( ) atof64( ) .......................................................................................................... 161 atoi( ) atol( ) atoi32( ) atoi48( ) ...
Page 9
getenv( ) .................................................................................................................................. 189 gets( ) fgets( ) .......................................................................................................................... 191 goto_address( ) ...................................................................................................................... 192 high_speed_adc_done( ) ....................................................................................................... 193 i2c_isr_state( ) ........................................................................................................................ 193 i2c_poll( ) ................................................................................................................................. 194 i2c_read( ) ............................................................................................................................... 195 i2c_slaveaddr( ) ...................................................................................................................... 196 i2c_start( ) ............................................................................................................................... 196 i2c_stop( ) ...
Page 10
pmp_write( ) ............................................................................................................................ 224 port_x_pullups ( ) ................................................................................................................... 224 pow( ) pwr( ) ............................................................................................................................ 225 printf( ) fprintf( ) ...................................................................................................................... 226 psp_output_full( ) psp_input_full( ) psp_overflow( ) ........................................................... 227 psp_read( ) .............................................................................................................................. 228 psp_write( ) ............................................................................................................................. 229 putc( ) putchar( ...
Page 11
set_pullup( ) ............................................................................................................................ 256 set_pwm_duty( ) ..................................................................................................................... 257 set_ticks( ) ............................................................................................................................... 258 set_timerx( ) ............................................................................................................................ 258 set_timerxy( ) .......................................................................................................................... 259 set_tris_x( ) ............................................................................................................................. 259 set_uart_speed( ) .................................................................................................................... 260 setjmp( ) .................................................................................................................................. 261 setup_adc(mode) .................................................................................................................... 261 setup_adc2(mode) .................................................................................................................. 261 setup_adc(mode) .................................................................................................................... ...
Page 12
STANDARD STRING FUNCTIONS( ) memchr( ) memcmp( ) strcat( ) strchr( ) strcmp( ) strcoll( ) strcspn( ) .................................................................................................................. 292 strerror( ) stricmp( ) strlen( ) strlwr( ) strncat( ) strncmp( ) strncpy( ) strpbrk( ) ...
Page 13
... What is an easy way for two or more PICs® to communicate? ........................................... 341 What is the format of floating point numbers? ...................................................................... 342 Why does the .LST file look out of order? ............................................................................. 344 Why is the RS-232 not working right? .................................................................................... 345 EXAMPLE PROGRAMS ............................................................................................................................. 347 EXAMPLE PROGRAMS ............................................................................................................ 347 SOFTWARE LICENSE AGREEMENT ....................................................................................................... 359 SOFTWARE LICENSE AGREEMENT ...................................................................................... 359 xiii ...
Page 14
...
Page 15
... Extended constructs like bit arrays, multiple address space handling and effective implementation of constant data in Rom make code generation very effective. Technical Support Compiler, software, and driver updates are available to download at: http://www.ccsinfo.com/download Compilers come with days of download rights with the initial purchase. One year maintenance plans may be purchased for access to updates as released ...
Page 16
Directories The compiler will search the following directories for Include files. Directories listed on the command line Directories specified in the .PJT file The same directory as the source file By default, the compiler files are put in C:\Program Files\PICC ...
Page 17
This is the symbol map which shows each register location and what program variables are stored in each location. .STA The statistics file shows the RAM, ROM, and STACK usage. It provides information on the source codes structural and ...
Page 18
Invoking the Command Line Compiler The command line compiler is invoked with the following command: CCSC [options] [cfilename] Valid options: +FB Select PCB (12 bit) +FM Select PCM (14 bit) +FH Select PCH (PIC18XXX) +Yx Optimization level x (0-9) +FS ...
Page 19
Generate a symbol file (.SYM not create symbol file +J Create a project file (.PJT not create PJT file +ICD Compile for use with an ICD #xxx="yyy" Set a global #define for id xxx with ...
Page 20
PCW Overview Beginning in version 4.XXX of PCW, the menus and toolbars are set-up in specially organized Ribbons. Each Ribbon relates to a specific type of activity an is only shown when selected. CCS has included a "User Toolbar" Ribbon ...
Page 21
Project Menu Ribbon Project Open an existing project (.PJT) file as specified and the main source file is loaded. PIC This command is a fast way to start a new project. It will bring up a screen with fill-in- Wizard ...
Page 22
Edit Menu Ribbon Undo Undoes the last deletion Redo Re-does the last undo Cut Moves the selected text from the file to the clipboard. Copy Copies the selected text to the clipboard. Paste Applies the clipboard contents to the cursor ...
Page 23
Search Menu Ribbon Find Locate text in file. Find Text Searches all files in project for specific text string. in Project Find Next Locates the next occurrence of the text selected in the file. Word at Cursor Goto Line Cursor ...
Page 24
... Allows user to define the set-up of editor properties for Windows options. Properties Tools Window display of User Defined Tools and options to add and apply. Software Ability for user to select which software to update, frequency to remind Updates Properties user and where to archive files. Properties Printer Set the printer port and paper and other properties for printing ...
Page 25
Compile Menu Ribbon Compile Compiles the current project in status bar using the current compiler. Build Compiles one or more files within a project. Compiler Pull-down menu to choose the compiler needed. Lookup Choose a device and the compiler needed ...
Page 26
View Menu Ribbon Valid This displays a list of valid interrupts used with the #INT_keyword for the chip used in Interrupts the current project. The interrupts for other chips can be viewed using the drop down menu. Valid This displays ...
Page 27
Tools Menu Ribbon Device Editor This tool is used to edit the device database used by the compiler to control compilations. The user can edit the chip memory, interrupts, fuses and other peripheral settings for all the supported devices. Device ...
Page 28
Debug Menu Ribbon Enable Enables the debugger. Opens the debugger window, downloads the code and on- Debugger chip debugger and resets the target into the debugger. Reset This will reset the target into the debugger. Single Executes one source code ...
Page 29
Document Menu Ribbon Format This utility formats the source file for indenting, color syntax highlighting, and other Source formatting options. Generate This will call the document generator program which uses a user generated template Document in .RTF format to merge ...
Page 30
... Technical Support wizard to directly contact Technical Support via email and the Support ability to attach files. Check for Automatically invokes Download Manager to view local and current versions of Software software. Updates Internet Direct links to specific CCS website pages for additional information. About Shows the version of compiler(s) and IDE installed. ...
Page 31
PROGRAM SYNTAX Overall Structure A program is made up of the following four elements in a file: Comment Pre-Processor Directive Data Definition Function Definition Every C program must contain a main function which is the starting point of the program ...
Page 32
For example: //*PURPOSE This program implements a Bootloader. //*AUTHOR John Doe A '//' followed will tell the compiler that the keyword which follows it will be the named comment. The actual comment that follows it will be ...
Page 33
Trigraph Sequences The compiler accepts three character sequences instead of some special characters not available on all keyboards as follows: Sequence Same as ??= # ??( [ ??/ \ ??) ] ??' ^ ??< { ??! | ??> } ??- ...
Page 34
Multiple Compilation Units Traditionally, the CCS C compiler used only one compilation unit and multiple files were implemented with #include files. When using multiple compilation units, care must be given that pre-processor commands that control the compilation are compatible across ...
Page 35
Compilation Files: *.o Relocatable object file that is generated by each unit. *.err Error file that is generated by each unit. *.osym Unit symbol file that is generated by each unit. project.hex Final load image file generated by the project. ...
Page 36
Using Command Line to Re-Build Changed Files in a Project: Using a text editor, create the file project.pjt based off of the following example in order to include the files that need to be linked for the project. Using a ...
Page 37
Using a text editor, create the file linker.bat based off of the following example in order to compile the files and build the project. · The path should point to the CCSC.exe file in the PIC-C installation directory. · Add ...
Page 38
To compile the files in a project and build the project itself, select either the Compile tab in the ribbon along the top of the main window, in the menu bar if the IDE view style has been changed, or ...
Page 39
Using the MPLAB IDE with Multiple Compilation Units: Open the MPLAB IDE, select the Project tab in the menu bar and select the New option. A window will be displayed asking to select the main source file of the project. ...
Page 40
Add source files to the project by either selecting the Project tab in the menu bar and then the Add File to Project option or by right-clicking on the Source Files folder in the project window and selecting Add Files. ...
Page 41
Select the Project tab in the menu bar and select Build Options. This will allow changes to be made to the output directory, include directories, output files generated, etc for the entire project or just individual units. To compile the ...
Page 42
Additional Note: If there is only one source file in the project, it will be compiled and linked in one step, a *.o file will not be created. A *.o file, that has already been compiled can be added to ...
Page 43
When a setting such as a pre-processor directive is included in the main include file between the units, a library is created in each of the units. The linker is able to determine that the libraries are duplicates and removes ...
Page 44
...
Page 45
STATEMENTS Statements STATEMENT if (expr) stmt; [else stmt;] while (expr) stmt; do stmt while (expr); for (expr1;expr2;expr3) stmt; switch (expr) { case cexpr: stmt; //one or more case [default:stmt] ... } return [expr]; goto label; label: stmt; break; continue; expr; ...
Page 46
The if-else statement is used to make decisions. The syntax (expr) stmt-1; [else stmt-2;] The expression is evaluated true stmt-1 is done false then stmt-2 is done. else-if This ...
Page 47
Statement: do stmt while (expr); Example putc(c=getc()); } while (c!=0); Also See: Statements , While do-while It differs from While and For loop in that the termination condition is checked at the bottom of the loop rather ...
Page 48
Switch is also a special multi-way decision maker. The syntax is switch (expr) { case const1: stmt sequence; break; ... [default:stmt] } This tests whether the expression matches one of the constant values and branches accordingly. If none of ...
Page 49
Statement: goto label; The goto statement cause an unconditional branch to the label. The syntax is goto label; A label has the same form as a variable name, and is followed by a colon. The goto's are used sparingly, ...
Page 50
Statement: continue; The continue statement causes the next iteration of the enclosing loop(While, For, Do) to begin. The syntax is continue; It causes the test part to be executed immediately in case of do and while and the control ...
Page 51
EXPRESSIONS Expressions Constants: Decimal 123 0123 Octal 0x123 Hex 0b010010 Binary 'x' Character Octal Character '\010' Hex Character '\xA5’ Special Character. Where c is one of: '\c' \n Line Feed - Same as \x0a \r Return Feed - Same as ...
Page 52
Operators + Addition Operator += Addition assignment operator, x+=y, is the same as x=x+y &= Bitwise and assignment operator, x&=y, is the same as x=x&y & Address operator & Bitwise and operator ^= Bitwise exclusive or assignment operator, x^=y, is ...
Page 53
PIN DESCENDING PRECEDENCE (expr) ++expr expr++ !expr ~expr (type)expr *expr expr*expr expr/expr expr+expr expr-expr expr<<expr expr>>expr expr<expr expr<=expr expr==expr expr!=expr expr&expr expr^expr expr | expr expr&& expr expr || expr expr ? expr: expr lvalue = expr lvalue+=expr ...
Page 54
Reference Parameters The compiler has limited support for reference parameters. This increases the readability of code and the efficiency of some inline procedures. The following two procedures are the same. The one with reference parameters will be implemented with greater ...
Page 55
Here is a function that calculates and returns the sum of all variables: int Sum(int count, ...) { //a pointer to the argument list va_list al; int x, sum=0; //start the argument list //count is the first variable before the ...
Page 56
Overloaded Functions Overloaded functions allow the user to have multiple functions with the same name, but they must accept different parameters. The return types must remain the same. Here is an example of function overloading: Two functions have the same ...
Page 57
DATA DEFINITIONS Basic and Special types This section describes what the basic data types and specifiers are and how variables can be declared using those types all the variables should be declared before they are used. They can ...
Page 58
Note: All types, except char, by default are signed; however, may be preceded by unsigned or signed (Except int64 may only be signed) . Short and long may have the keyword INT following them with no effect. Also see #TYPE ...
Page 59
The id after ENUM is created as a type large enough to the largest constant in the list. The ids in the list are each created as a constant. By default the first id is set to zero and they ...
Page 60
For example: union u_tab { int ival; long lval; float fval; }; float If typedef is used with any of the basic or special types it creates a new type name that can be used in declarations. The identifier does ...
Page 61
Declarations A declaration specifies a type qualifier and a type specifier, and is followed by a list of one or more variables of that type. For e.g.: int a,b,c,d; mybit e,f; mybyte g[3][2]; char *h; colors j; struct data_record data[10]; ...
Page 62
Example: void DataEE_Read(int32 addr, int8 * ram, int bytes) { int i; for(i=0;i<bytes;i++,ram++,addr++) *ram=read_eeprom(addr); } void DataEE_Write(int32 addr, int8 * ram, int bytes) { int i; for(i=0;i<bytes;i++,ram++,addr++) write_eeprom(addr,*ram); } addressmod (DataEE,DataEE_read,DataEE_write,5,0xff); // would define a region called DataEE between // ...
Page 63
Using Program Memory for Data CCS C Compiler provides a few different ways to use program memory for data. The different ways are discussed below: Constant Data: The CONST qualifier will place the variables into program memory. If the keyword ...
Page 64
Another method is to use #rom to assign data to program memory. The syntax is: #rom address = {data, data, … , data} For example: Places 1,2,3,4 to ROM addresses starting at 0x1000 #rom 0x1000 = {1, 2, ...
Page 65
Function Definition The format of a function definition is as follows: qualifier id ( [type-specifier id Optional See Below Zero or more comma separated. See Data Types The qualifiers for a function are as follows: VOID type-specifier ...
Page 66
...
Page 67
... I2C™ popular two-wire communication protocol developed by Phillips. Many PIC microcontrollers support hardware-based I2C™. CCS offers support for the hardware-based I2C™ and a software-based master I2C™ device. (For more information on the hardware-based I2C module, please consult the datasheet for you target device; not all PICs support I2C™.) ...
Page 68
Example Code: #define Device_SDA PIN_C3 #define Device_SLC PIN_C4 #use i c(master, sda=Device_SDA, 2 scl=Device_SCL BYTE data; i c_start(); 2 i c_write(data c_stop(); 2 ADC These options let the user configure and use the analog to digital ...
Page 69
Relevant Interrupts: INT_AD INT_ADOF Relevant Include Files: None, all functions built-in Relevant getenv() parameters: ADC_CHANNELS ADC_RESOLUTION Example Code: #DEVICE ADC=10 ... long value; ... setup_adc(ADC_CLOCK_INTERNA L); setup_adc_ports(ALL_ANALOG); set_adc_channel(0); delay_us(10); value=read_adc(); read_adc(ADC_START_ONLY); value=read_adc(ADC_READ_ONLY ); Interrupt fires when a/d conversion is complete ...
Page 70
Analog Comparator These functions sets up the analog comparator module. Only available in some devices. Relevant Functions: setup_comparator(mode) Relevant Preprocessor: None Relevant Interrupts: INT_COMP Relevant Include Files: Relevant getenv() parameters: COMP Example Code: setup_comparator(A4_A5_NC_NC); if(C1OUT) output_low(PIN_D0); else output_high(PIN_D1); 56 Enables ...
Page 71
CAN Bus These functions allow easy access to the Controller Area Network (CAN) features included with the MCP2515 CAN interface chip and the PIC24, dsPIC30 and dsPIC33 MCUs. These functions will only work with the MCP2515 CAN interface chip and ...
Page 72
CAN_FILTER_ASSOCIATION filter) can_associate_filter_to_mask (CAN_MASK_FILTER_ASSOCIATION mask, CAN_FILTER_ASSOCIATION filter) can_fifo_getd(int32 &id, int8 *data, int8 &len, ...
Page 73
For PICs that have two CAN or ECAN modules all the above function are available for the second module, and they start with can2 instead of can. Relevant Preprocessor: None Relevant Interrupts: #INT_CAN1 #INT_CAN2 Relevant ...
Page 74
Relevant getenv() Parameters: None Example Code: can_init(); can_putd(0x300,data,8,3,TRUE,FALSE); can_getd(ID,data,len,stat); Configuration Memory On all dsPIC30, dsPIC33 and PIC24s the configuration memory is readable and writeable. The configuration memory contains the configuration bits for things such as the oscillator mode, watchdog timer ...
Page 75
... CRC The programmable Cyclic Redundancy Check (CRC) in the PIC24F is a software configurable CRC checksum generator. (Other members of the PCD family do not have this peripheral at the time of writing this manual). The checksum is a unique number associated with a message or a block of data containing several bytes. The built-in CRC module has the following features: · ...
Page 76
DAC These options let the user configure and use the digital to analog converter module. They are only available on devices with the DAC hardware. The options for the functions and directives vary depending on the chip and are listed ...
Page 77
Data Eeprom The data eeprom memory is readable and writable in some chips. These options lets the user read and write to the data eeprom memory. These functions are only available in flash chips. Relevant Functions: (8 bit or 16 ...
Page 78
DCI DCI is an interface that is found on several dsPIC devices in the 30F and the 33FJ families multiple-protocol interface peripheral that allows the user to connect to many common audio codecs through common (and highly ...
Page 79
DMA The Direct Memory Access (DMA) controller facilitates the transfer of data between the CPU and its peripherals without the CPU's assistance. The transfer takes place between peripheral data registers and data space RAM. The module has 8 channels and ...
Page 80
General Purpose I/O These options let the user configure and use the I/O pins on the device. These functions will affect the pins that are listed in the device header file. Relevant Functions: output_high(pin) Sets the given pin to high ...
Page 81
Example Code: #use fast_io(b) ... Int8 Tris_value= 0x0F; int1 Pin_value; ... set_tris_b(Tris_value); //Sets B0:B3 as output_high(PIN_B7); //Set the pin B7 to High If(input(PIN_B0)){ //Read the value on pin B0, set B7 to low if pin B0 is high output_high(PIN_B7) ;} ...
Page 82
Internal Oscillator Two internal oscillators are present in PCD compatible chips, a fast RC and slow RC oscillator circuit. In many cases (consult your target datasheet or family data sheet for target specifics) the fast RC oscillator may be connected ...
Page 83
Relevant Preprocessor: #INT_XXX level int 0-7, that selects the interrupt priority level for that interrupt. #INT_XXX fast This directive makes use of shadow registers for fast register save. This directive can only be used in one ISR ...
Page 84
Linker The linker allows allows multiple files to be compiled into multiple objects (.o files) and finally linked together to form a final .hex file. The linker can be used from inside the PCW IDE, through the MPLAB IDE and ...
Page 85
Replacing the linker command line with a linker script: 1. Create a file named project.c with the following lines: #import( report.o ) #import( filter.o ) #import( main Compile each unit (report, filter, main). 3. Compile project.c Using the ...
Page 86
Using MPLAB IDE to work with Multiple Compilation Units · Create a new project by selecting “Project -> New” from the toolbar. Follow the dialog boxes to specify the project name and project path. · Make sure MPLAB is configured ...
Page 87
Notes · By default variables declared at the unit level (outside a function) are visible to all other units. To make a variable private to the unit use the keyword static. Notice report.c defines the variable report_line_number. If the definition ...
Page 88
Output Compare/PWM Overview The following functions are used to configure the output compare module. The output compare has three modes of functioning. Single compare, dual compare, and PWM. In single compare the output compare module simply compares the value of ...
Page 89
Motor Control PWM These options lets the user configure the Motor Control Pulse Width Modulator (MCPWM) module. The MCPWM is used to generate a periodic pulse waveform which is useful is motor control and power control applications. The options for ...
Page 90
PMP The Parallel Master Port(PMP parallel 8-bit I/O module specifically designed to communicate with a wide variety of parallel devices. Key features of the PMP module are: · 8 Data lines · Programmable Address Lines ...
Page 91
Example Code: setup_pmp( PAR_ENABLE | Sets up Master mode with address lines PMA0:PMA7 PAR_MASTER_MODE_1 | PAR_STOP_IN_IDLE,0x00FF ); If ( pmp_output_full ( )) { pmp_write(next_byte); } Program Eeprom The flash program memory is readable and writable in some chips and is ...
Page 92
Relevant Preprocessor: #ROM address={list} #DEVICE(WRITE_EEPROM=ASYNC) Relevant Interrupts: INT_EEPROM Relevant Include Files: None, all functions built-in Relevant getenv() parameters PROGRAM_MEMORY READ_PROGRAM FLASH_WRITE_SIZE FLASH_ERASE_SIZE Example Code: #ROM 0x300={1,2,3,4} erase_program_eeprom(0x00000300); write_program_eeprom(0x00000300,0x123456 ); value=read_program_eeprom(0x00000300); write_program_memory(0x00000300,data,12); read_program_memory(0x00000300,value,12); For chips where getenv(“FLASH_ERASE_SIZE”) > getenv(“FLASH_WRITE_SIZE”) WRITE_PROGRAM_EEPROM WRITE_PROGRAM_MEMORY ...
Page 93
WRITE_ROM_MEMORY ERASE_PROGRAM_EEPROM For chips where getenv(“FLASH_ERASE_SIZE”) = get(“FLASH_WRITE_SIZE”) WRITE_PROGRAM_EEPROM WRITE_PROGRAM_MEMORY WRITE_ROM_MEMORY ERASE_PROGRAM_EEPROM QEI The Quadrature Encoder Interface (QEI) module provides the interface to incremental encoders for obtaining mechanical positional data. Relevant Functions: setup_qei(options, filter,maxcount) qei_status( ) qei_set_count(value) qei_get_count( ) Relevant ...
Page 94
... Return true when a character is received in the buffer in case of hardware RS232 or when the first bit is sent on the RCV pin in case of software RS232. Useful for polling without waiting in getc. Used to change the baud rate of the hardware UART at run- time. Specifying stream is optional. Refer to the help for more ...
Page 95
Relevant Preprocessor: #USE RS232(options) Relevant Interrupts: INT_RDA INT_TBE Some chips have more than one hardware uart, and hence more interrupts. Relevant Include Files: None, all functions built-in Relevant getenv() parameters: UART – Returns the number of UARTs on ...
Page 96
RTCC The Real Time Clock and Calendar (RTCC) module is intended for applications where accurate time must be maintained for extended periods of time with minimum or no intervention from the CPU. The key features of the module are: · ...
Page 97
RTOS These functions control the operation of the CCS Real Time Operating System (RTOS). This operating system is cooperatively multitasking and allows for tasks to be scheduled to run at specified time intervals. Because the RTOS does not use interrupts, ...
Page 98
Relevant Preprocessor: #USE RTOS(options) This directive is used to specify several different RTOS attributes including the timer to use, the minor cycle time and whether or not statistics should be enabled. #TASK(options) This directive tells the compiler that ...
Page 99
... SPI™ fluid standard for wire, full duplex communications named by Motorola. Most PIC devices support most common SPI™ modes. CCS provides a support library for taking advantage of both hardware and software based SPI™ functionality. For software support, see Relevant Functions: setup_spi(mode) Configure the hardware SPI to the specified mode ...
Page 100
Timers The 16-bit DSC and MCU families implement 16 bit timers. Many of these timers may be concatenated into a hybrid 32 bit timer. Also, one timer may be configured to use a low power 32.768 kHz oscillator which may ...
Page 101
Example Code: /* Setup timer1 as an external real time clock that increments every 16 clock cycles */ setup_timer1(T1_EXTERNAL_RTC | T2_DIV_BY_16 ); /* Setup timer2 as a timer that increments on every instruction cycle and has a period of 0x0100 ...
Page 102
WDT or Watch Dog Timer Different chips provide different options to enable/disable or configure the WDT. Relevant Functions: setup_wdt() Enables/disables the wdt or sets the prescalar. restart_wdt() Restarts the wdt, if wdt is enables this must be periodically called to ...
Page 103
PRE-PROCESSOR DIRECTIVES PRE-PROCESSOR Pre-processor directives all begin with a # and are followed by a specific command. Syntax is dependent on the command. Many commands do not allow other syntactical elements on the remainder of the line. A table of ...
Page 104
Memory #BYTE Control #WORD #USE DYNAMIC_MEMORY #CASE Compiler Control #IGNORE_WARNINGS #IMPORT Linker #TASK RTOS 90 #FILL_ROM #ROM #LOCATE #TYPE #ORG #ZERO_RAM #RESERVE #BANKX #BANK_DMA #BANKY #OPT #MODULE #OCS #EXPORT #BUILD #USE RTOS ...
Page 105
Syntax: #ASM or #ASM ASIS code #ENDASM Elements: code is a list of assembly language instructions Purpose: The lines between the #ASM and #ENDASM are treated as assembly code to be inserted. These may be used anywhere an ...
Page 106
ADD Wa,Wb,Wd ADD f,W ADD lit10,Wd ADD Wa,lit5,Wd ADD f,F ADD acc ADD Wd,{lit4},acc ADD.B lit10,Wd ADD.B f,F ADD.B Wa,Wb,Wd ADD.B Wa,lit5,Wd ADD.B f,W ADDC f,W ADDC lit10,Wd ADDC Wa,lit5,Wd ADDC f,F ADDC Wa,Wb,Wd ADDC.B lit10,Wd ADDC.B Wa,Wb,Wd ADDC.B Wa,lit5,Wd ...
Page 107
BCLR f,B f.bit = 0 BCLR Wd,B Wa.bit = 0 BCLR.B Wd,B Wa.bit = 0 (byte) BRA a Branch unconditionally BRA Wd Branch PC+Wa BRA BZ a Branch if Zero BRA C a Branch if Carry (no borrow) BRA GE ...
Page 108
BTST.C Wa,Wd BTST.C Wd,B BTST.Z Wd,B BTST.Z Wa,Wd BTSTS f,B BTSTS.C Wd,B BTSTS.Z Wd,B CALL a CALL Wd CLR f,F CLR acc,da,dc,pi CLR f,W CLR Wd CLR.B f,W CLR.B Wd CLR.B f,F CLRWDT COM f,F COM f,W COM Wa,Wd COM.B ...
Page 109
CPSEQ.B Wa,Wd Skip (byte) CPSGT Wa,Wd Skip if Wa > Wb CPSGT.B Wa,Wd Skip if Wa > Wb (byte) CPSLT Wa,Wd Skip if Wa < Wb CPSLT.B Wa,Wd Skip if Wa < Wb (byte) CPSNE Wa,Wd ...
Page 110
INC.B Wa,Wd INC.B f,F INC.B f,W INC2 f,W INC2 Wa,Wd INC2 f,F INC2.B f,W INC2.B f,F INC2.B Wa,Wd IOR lit10,Wd IOR f,F IOR f,W IOR Wa,lit5,Wd IOR Wa,Wb,Wd IOR.B Wa,Wb,Wd IOR.B f,W IOR.B lit10,Wd IOR.B Wa,lit5,Wd IOR.B f,F LAC Wd,{lit4},acc ...
Page 111
MOV Wa,Wd+lit [Wd + Slit10 MOV.B lit8, lit8 (byte) MOV.B W (byte) MOV.B f (byte) MOV.B f (byte) MOV.B Wa+lit, [Wa +Slit10] (byte) MOV.B Wa,Wd+lit ...
Page 112
PWRSAV lit1 RCALL a RCALL Wd REPEAT lit14 REPEAT Wd RESET RETFIE RETLW lit10,Wd RETLW.B lit10,Wd RETURN RLC Wa,Wd RLC f,F RLC f,W RLC.B f,F RLC.B f,W RLC.B Wa,Wd RLNC Wa,Wd RLNC f,F RLNC f,W RLNC.B f,W RLNC.B Wa,Wd RLNC.B ...
Page 113
SETM.B f 0xFFFF (byte) SETM.B f 0xFFFF (byte) SFTAC acc,Wd Arithmetic shift Acc by (Wa) SFTAC acc,lit5 Arithmetic shift Acc by Slit6 SL f << Wa,Wb, << Wb ...
Page 114
SUBBR.B Wa,Wb,Wd SUBBR.B Wa,lit5,Wd SUBR Wa,lit5,Wd SUBR f,F SUBR Wa,Wb,Wd SUBR f,W SUBR.B Wa,Wb,Wd SUBR.B f,F SUBR.B Wa,lit5,Wd SUBR.B f,W SWAP Wd SWAP.B Wd TBLRDH Wa,Wd TBLRDH.B Wa,Wd TBLRDL Wa,Wd TBLRDL.B Wa,Wd TBLWTH Wa,Wd TBLWTH.B Wa,Wd TBLWTL Wa,Wd TBLWTL.B Wa,Wd ...
Page 115
Syntax: #BANK_DMA Elements: None Purpose: Tells the compiler to assign the data for the next variable, array or structure into DMA bank Examples: #bank_dma struct { int r_w; int c_w; long unused :2; long data: 4; }a_port; //the data ...
Page 116
Syntax: #BANKY Elements: None Purpose: Tells the compiler to assign the data for the next variable, array, or structure into Bank Y. Examples: #banky struct { int r_w; int c_d; long unused : 2; long data : 4; } ...
Page 117
Syntax: #BUILD(segment = address) #BUILD(segment = address, segment = address) #BUILD(segment = start:end) #BUILD(segment = start: end, segment = start: end) #BUILD(nosleep) #BUILD(segment = size) : For STACK use only #BUILD(ALT_INTERRUPT) Elements: segment is one of the following memory ...
Page 118
Examples: /* assign the location where the compiler will place the reset and interrupt vectors */ #build(reset=0x200,interrupt=0x208) /* assign the location and fix the size of the segments used by the compiler for the reset and interrupt vectors */ #build(reset=0x200:0x207, ...
Page 119
... Example Files: ex_cust.c Also See: None _DATE_ Syntax: __DATE__ Elements: None Purpose: This pre-processor identifier is replaced at compile time with the date of the compile in the form: "31-JAN-03" Examples: printf("Software was compiled on "); printf(__DATE__); Example Files: None Also See: None //global 105 ...
Page 120
Syntax: #DEFINE id text or #DEFINE id(x,y...) text Elements preprocessor identifier, text is any text, x,y and so on are local preprocessor identifiers, and in this form there may be one or more identifiers separated by ...
Page 121
Syntax: #DEVICE chip options #DEVICE Compilation mode selection Elements: Chip Options- chip is the name of a specific processor (like: dsPIC33FJ64GP306 ), To get a current list of supported devices: START | RUN | CCSC +Q Options are qualifiers ...
Page 122
Compilation mode selection- The #DEVICE directive supports compilation mode selection. The valid keywords are CCS2, CCS3, CCS4 and ANSI. The default mode is CCS4. For the CCS4 and ANSI mode, the compiler uses the default fuse settings NOLVP, PUT for ...
Page 123
Syntax: value = definedinc( variable ); Parameters: variable is the name of the variable, function, or type to be checked. Returns status for the type of id entered as follows: 0 – not known 1 – typedef ...
Page 124
Syntax: #ERROR text #ERROR / warning text #ERROR / information text Elements: text is optional and may be any text Purpose: Forces the compiler to generate an error at the location this directive appears in the file. The text ...
Page 125
RANGE=start:stop Only addresses in this range are included in the hex file. OFFSET=address Hex file address starts at this address (0 by default) ODD Only odd bytes place in hex file. EVEN Only even bytes placed in hex file. Purpose: ...
Page 126
Syntax: __FILE__ Elements: None Purpose: The pre-processor identifier is replaced at compile time with the file path and the filename of the file being compiled. Examples: if(index>MAX_ENTRIES) printf("Too many entries, source file: " __FILE__ " at line " __LINE__ ...
Page 127
Syntax: #FUSES options Elements: options vary depending on the device. A list of all valid options has been put at the top of each devices .h file in a comment for reference. The PCW device edit utility can modify ...
Page 128
Syntax: #HEXCOMMENT text comment for the top of the hex file #HEXCOMMENT\ text comment for the end of the hex file Elements: None Purpose: Puts a comment in the hex file Some programmers (MPLAB in particular) do not like ...
Page 129
Syntax: #if expr code #elif expr //Optional, any number may be used code #else //Optional code #endif Elements: expr is an expression with constants, standard operators and/or preprocessor identifiers. Code is any standard c source ...
Page 130
Syntax: #IFDEF id code #ELIF code #ELSE code #ENDIF #IFNDEF id code #ELIF code #ELSE code #ENDIF Elements preprocessor identifier, code is valid C source code. Purpose: This directive acts much like ...
Page 131
Syntax: #ignore_warnings ALL #IGNORE_WARNINGS NONE #IGNORE_WARNINGS warnings Elements: warnings is one or more warning numbers separated by commas Purpose: This function will suppress warning messages from the compiler. ALL indicates no warning will be generated. NONE indicates all warnings ...
Page 132
RANGE=start:stop Only addresses in this range are read from the hex file. LOCATION=id The identifier is made a constant with the start address of the imported data. SIZE=id The identifier is made a constant with the size of the imported ...
Page 133
Syntax: #INCLUDE <filename> or #INCLUDE "filename" Elements: filename is a valid PC filename. It may include normal drive and path information. A file with the extension ".encrypted" valid PC file. The standard compiler #INCLUDE directive will accept ...
Page 134
Syntax: #INT_AC1 #INT_AC2 #INT_AC3 #INT_AC4 #INT_ADC1 #INT_ADC2 #INT_ADCP0 #INT_ADCP1 #INT_ADCP2 #INT_ADCP3 #INT_ADCP4 #INT_ADCP5 #INT_ADDRERR #INT_C1RX #INT_C1TX #INT_C2RX #INT_C2TX #INT_CAN1 #INT_CAN2 #INT_CNI #INT_COMP #INT_CRC #INT_DCI #INT_DCIE #INT_DMA0 #INT_DMA1 #INT_DMA2 #INT_DMA3 #INT_DMA4 #INT_DMA5 #INT_DMA6 #INT_DMA7 #INT_DMAERR #INT_EEPROM #INT_EX1 #INT_EX4 #INT_EXT0 #INT_EXT1 ...
Page 135
External interrupt #3 #INT_EXT4 External interrupt #4 #INT_FAULTA PWM Fault A #INT_FAULTA2 PWM Fault A 2 #INT_FAULTB PWM Fault B #INT_IC1 Input Capture #1 #INT_IC2 Input Capture #2 #INT_IC3 Input Capture #3 #INT_IC4 Input Capture #4 #INT_IC5 Input Capture ...
Page 136
Elements: NoCear, LEVEL=n, HIGH, FAST Purpose: These directives specify the following function is an interrupt function. Interrupt functions may not have any parameters. ...
Page 137
This interrupt will not interrupt any interrupt in progress. #INT_xxxx FAST Compiler does a FAST save/restore of key registers. Only one is allowed in a program. #INT_xxxx HIGHLevel=3 Interrupt is enabled when levels 3 and below are enabled. #INT_GLOBAL Compiler ...
Page 138
Syntax: __line__ Elements: None Purpose: The pre-processor identifier is replaced at compile time with line number of the file being compiled. Examples: if(index>MAX_ENTRIES) printf("Too many entries, source file: " __FILE__" at line " __LINE__ "\r\n"); Example Files: assert.h Also ...
Page 139
Syntax: #LINE number filename Elements: Number is non-negative decimal integer. File name is optional. Purpose: The C pre-processor informs the C Compiler of the location in your source code. This code is simply used to change the value of ...
Page 140
Syntax: #MODULE Elements: None Purpose: All global symbols created from the #MODULE to the end of the file will only be visible within that same block of code (and files #INCLUDE within that block). This may be used to ...
Page 141
Syntax: #OPT n Elements: All dsPIC30/dsPIC33/PIC24 Devices the optimization level 0-9 Purpose: The optimization level is set with this directive. This setting applies to the entire program and may appear anywhere in the file. The default is ...
Page 142
Examples: #ORG 0x1E00, 0x1FFF MyFunc() { //This function located at 1E00 } #ORG 0x1E00 Anotherfunc(){ // This will be somewhere 1E00-1F00 } #ORG 0x800, 0x820 {} //Nothing will be at 800-820 #ORG 0x1C00, 0x1C0F CHAR CONST ID[10}= {"123456789"}; //This ID ...
Page 143
Syntax: __PCD__ Elements: None Purpose: The PCD compiler defines this pre-processor identifier. It may be used to determine if the PCD compiler is doing the compilation. Examples: #ifdef __pcd__ #device dsPIC33FJ256MC710 #endif Example Files: ex_sqw.c Also See: ...
Page 144
T2CK Timer2 External Clock T3CK Timer3 External Clock T4CK Timer4 External Clock T5CK Timer5 External Clock IC1 Input Capture 1 IC2 Input Capture 2 IC3 Input Capture 3 IC4 Input Capture 4 IC5 Input Capture 5 OCFA Output Compare Fault ...
Page 145
Syntax: #PRAGMA cmd Elements: cmd is any valid preprocessor directive. Purpose: This directive is used to maintain compatibility between C compilers. This compiler will accept this directive before any other pre-processor command case does this compiler require ...
Page 146
Syntax: #RECURSIVE Elements: None Purpose: Tells the compiler that the procedure immediately following the directive will be recursive. Examples: #recursive int factorial(int num (num <= 1) return 1; return num * factorial(num-1); } Example Files: None Also ...
Page 147
This will put a value at address that is a crc16 of all the program memory except the specified address #ROM address = crc8 This will put a value at address that is a crc16 of ...
Page 148
Examples: #separate ARG=W0:W7 AVOID=W8:W15 DND=W8:W15 swapbyte (int *a, int *b) { int t; t=*a; *a=*b; *b=t; } Example Files: ex_cust.c Also See: #INLINE #SERIALIZE Syntax: #SERIALIZE(id=xxx, next="x" | file="filename.txt" " | listfile="filename.txt", "prompt="text", log="filename.txt") - Or-#SERIALIZE(dataee=x, binary=x, next="x" | file="filename.txt" ...
Page 149
... Purpose: Assists in making serial numbers easier to implement when working with CCS ICD units. Comments are inserted into the hex file that the ICD software interprets. Examples: //Prompt user for serial number to be placed //at address of serialNumA //Default serial number = 200int8 const serialNumA=100; ...
Page 150
... Also See: #USE RTOS __ TIME __ Syntax: __TIME__ Elements: None Purpose: This pre-processor identifier is replaced at compile time with the time of the compile in the form: "hh:mm:ss" Examples: printf("Software was compiled on "); printf(__TIME__); Example Files: None Also See: None 136 ...
Page 151
Syntax: #TYPE standard-type=size #TYPE default=area #TYPE unsigned #TYPE signed #TYPE char=signed #TYPE char=unsigned #TYPE ARG=Wx:Wy #TYPE DND=Wx:Wy #TYPE AVOID=Wx:Wy #TYPE RECURSIVE #TYPE CLASSIC Elements: standard-type is one of the C keywords short, int, long, float, or double size is ...
Page 152
Examples: #TYPE SHORT INT LONG= 16, FLOAT=48 #TYPE default=area addressmod (user_ram_block, 0x100, 0x1FF); #type default=user_ram_block // in this area will be in #type default= // back to normal #TYPE SIGNED #TYPE RECURSIVE #TYPE ARG=W0:W7 #TYPE AVOID=W8:W15 ...
Page 153
DELAY Syntax: #USE DELAY (options)) Elements: Options may be any of the following separated by commas: clock=speed speed is a constant 1-100000000 ( 100 mhz). This number can contains commas. This number also supports the following denominations: ...
Page 154
PLL //to upscale it to 40Mhz. #use delay(oscillator=10Mhz, clock=40Mhz) //application will use the internal oscillator at 8MHz. //compiler will set config bits, and set the internal //oscillator to 8MHz. #use ...
Page 155
FAST_IO Syntax: #USE FAST_IO (port) Elements: port ALL Purpose: Affects how the compiler will generate code for input and output instructions that follow. This directive takes effect until ...
Page 156
... The I C library contains functions to implement remains in effect for the I2C_START, I2C_STOP, I2C_READ, I2C_WRITE and I2C_POLL functions until another USE I2C is encountered. Software functions are generated unless the FORCE_HW is specified. The SLAVE mode should 142 Sets to the master mode Set the multi_master mode ...
Page 157
... Use baud=0 to not init the UART and pins C6 and C7 can still be used for input-output functions. #USE RS232(baud=0,options) To make printf work with NOINIT option, use: setup_uart(9600); Set transmit pin Set receive pin Will generate software serial I/O routines even when the UART pins are specified. i c_write, 2 143 ...
Page 158
BRGH1OK ENABLE=pin DEBUGGER RESTART_WDT INVERT PARITY=X BITS =X FLOAT_HIGH ERRORS SAMPLE_EARLY RETURN=pin MULTI_MASTER 144 Allow bad baud rates on chips that have baud rate problems. The specified pin will be high during transmit. This may be used to enable 485 ...
Page 159
... This is for 9 bit data formats. Will cause interrupts to be disabled when the routines get or put a character. This prevents character distortion for software implemented I/O and prevents interaction between I/O in interrupt handlers and the main program when using the UART. To set the number of stop bits (default is 1). This works for both UART and non-UART ports ...
Page 160
The definition of the RS232_ERRORS is as follows: No UART: Bit 7 is 9th bit for 9 bit data mode (get and put). Bit 6 set to one indicates a put ...
Page 161
Purpose: This directive tells the compiler which timer on the PIC to use for monitoring and when to grant control to a task. Changes to the specified timer's prescaler will effect the rate at which tasks are executed. This directive ...
Page 162
... Consult your PIC’s data sheet as to where the pins for hardware SPI are. If hardware SPI is not used, then software SPI will be used. Software SPI is much slower than hardware SPI, but software SPI can use any pins to transfer and receive data other than just the pins tied to the PIC’ ...
Page 163
STANDARD_IO Syntax: #USE STANDARD_IO (port) Elements: port ALL Purpose: This directive affects how the compiler will generate code for input and output instructions that follow. This directive takes ...
Page 164
... If utilizing multiple touch pads, each pad will use xx milliseconds to scan for one key press. Default is 32ms. PIN=char If a valid key press is determined on “PIN”, the software will return the character “char” in the function touchpad_getc(). (Example: PIN_B0='A') 150 ...
Page 165
Purpose: This directive will tell the compiler to initialize and activate the Capacitive Sensing Module (CSM) on the microcontroller. The compiler requires use of the TIMER0 and TIMER1 modules, and global interrupts must still be activated in the main program ...
Page 166
Syntax: #WORD Elements valid C identifier variable or a constant Purpose: If the id is already known variable then this will locate the variable at address ...
Page 167
Syntax: #ZERO_RAM Elements: None Purpose: This directive zero's out all of the internal registers that may be used to hold variables before program execution begins. Examples: #zero_ram void main Example Files: ex_cust.c Also See: None 153 ...
Page 168
...
Page 169
BUILT-IN-FUNCTIONS BUILT-IN-FUNCTIONS The CCS compiler provides a lot of built-in functions to access and use the pic microcontroller's peripherals. This makes it very easy for the users to configure and use the peripherals without going into in depth details of ...
Page 170
BIT/BYTE MANIPULATION bit_test( ) bit_first( ) abs( ) acos( ) asin( ) STANDARD atan MATH atan2( ) atoe( ) atof48( ) atof64( ) VOLTAGE setup_low_volt_detect( ) REF/ setup_comparator( ) COMPARE adc_done( ) A/D adc_done2( ...
Page 171
STANDARD longjmp MEMORY malloc( ) memchr( ) set_pwm_duty( ) set_motor_unit( ) CAPTURE/ setup_motor_pwm( ) COMPARE/ setup_capture( ) PWM get_capture( ) setup_power_pwm( ) erase_program_memory( ) NON- read_eeprom( ) VOLATILE read_configuration_memory( ) MEMORY read_rom_memory( ) bsearch( ...
Page 172
DCI dci_transmit_ready( ) rtc_alarm_read( ) RTC rtc_read( ) crc_calc(mode) CRC crc_calc8( ) dac_write( ) D/A setup_high_speed_adc_pair( ) high_speed_adc_done( ) CONVERSION setup_high_speed_adc( ) touchpad_getc( ) CAPACITIVE TOUCH PAD pmp_address(address) pmp_overflow( ) Parallel Port psp_input_full( ) psp_read( ) setup_pmp(option, address_mask) ...
Page 173
Syntax: value = abs(x) Parameters any integer or float type. Returns: Same type as the parameter. Function: Computes the absolute value of a number. Availability: All devices Requires: #INCLUDE <stdlib.h> Examples: signed int target,actual; ... error ...
Page 174
Syntax: assert (condition); Parameters: condition is any relational expression Returns: Nothing Function: This function tests the condition and if FALSE will generate an error message on STDERR (by default the first USE RS232 in the program). The error ...
Page 175
Syntax: result = atof (string) or result = atof48(string) or result=atof64(string) Parameters: string is a pointer to a null terminated string of characters. Returns: Result is a floating point number in single, extended or ...
Page 176
Syntax: ivalue = atoi(string) or lvalue = atol(string) or i32value = atoi32(string) or i48value=atoi48(string) or i64value=atoi64(string) Parameters: string is a pointer to a null terminated string of characters. Returns: ivalue ...
Page 177
Syntax: bit_clear(var, bit) Parameters: var may be a any bit variable (any lvalue) bit is a number 0- 63 representing a bit number the least significant bit. Returns: undefined Function: Simply clears the specified bit in ...
Page 178
Syntax bit_last (value, var bit_last(var) Parameters: value search for var bit integer. Returns: An 8-bit integer Function: The first function will find the first occurrence ...
Page 179
Syntax: bit_set(var, bit) Parameters: var may be any variable (any lvalue) bit is a number 0- 63 representing a bit number the least significant bit. Returns: Undefined Function: Sets the specified bit in the given variable. ...
Page 180
Examples: if( bit_test(x,3) || !bit_test (x,1) ){ //either bit bit if(data!=0) for(i=31;!bit_test(data, i);i--) ; // i now has the most significant bit in data // that is set Example ...
Page 181
Syntax: ptr=calloc(nmem, size) Parameters: nmem is an integer representing the number of member objects, and size is the number of bytes to be allocated for each one of them. Returns: A pointer to the allocated memory, if any. ...
Page 182
Syntax: clear_interrupt(level) Parameters: level - a constant defined in the devices.h file Returns: undefined Function: Clears the interrupt flag for the given level. This function is designed for use with a specific interrupt, thus eliminating the GLOBAL level ...
Page 183
Syntax: crc_init (data); Parameters: data - This will setup the initial value used by write CRC shift register. Most commonly, this register is set to 0x0000 for start of a new CRC calculation. Returns: undefined Function: Configures the CRCWDAT ...
Page 184
Examples: int setup_dac(DAC_VDD | DAC_OUTPUT); while(1){ i++; dac_write(i); } int setup_dac(DAC_RIGHT_ON, 5); while(1){ i++; dac_write(DAC_RIGHT | i); } Also See: setup_dac( ), DAC Overview, see header file for device selected delay_cycles( ) Syntax: delay_cycles ...
Page 185
Syntax: dci_data_received() Parameters: none Returns: An int1. Returns true if the DCI module has received data. Function: Use this function to poll the receive buffers. It acts as a kbhit() function for DCI. Availability: Only available on devices ...
Page 186
Requires: None Examples: while(1) { dci_read(&left_channel, &right_channel); dci_write(&left_channel, &right_channel); } Example Files: None Also See: DCI Overview, dci_data_received( ) dci_start( ) Syntax: dci_start(); Parameters: None Returns: undefined Function: Starts the DCI module’s transmission. DCI operates in a continous transmission mode ...
Page 187
Syntax: dci_transmit_ready() Parameters: None Returns: An int1. Returns true if the DCI module is ready to transmit (there is space open in the hardware buffer). Function: Use this function to poll the transmit buffers. Availability: Only available on ...
Page 188
Availability: Only available on devices with DCI Requires: None Examples: while(1) { dci_read(&left_channel, &right_channel); dci_write(&left_channel, &right_channel); } Example Files: None Also See: DCI Overview, dci_data_received( ) delay_ms( ) Syntax: delay_ms (time) Parameters: time - a variable 0-65535(int16 constant ...
Page 189
Syntax: delay_us (time) Parameters: time - a variable 0-65535(int16 constant 0-65535 Note: Previous compiler versions ignored the upper byte of an int16, now the upper byte affects the time. Returns: undefined Function: Creates code to perform ...
Page 190
Syntax: disable_interrupts (name) disable_interrupts (INTR_XX) disable_interrupts (expression) Parameters: name - a constant defined in the devices .h file INTR_XX – Allows user selectable interrupt options like INTR_NORMAL, INTR_ALTERNATE, INTR_LEVEL expression – A non-constant expression Returns: When INTR_LEVELx is ...
Page 191
Syntax: idiv=div(num, denom) ldiv =ldiv(lnum, ldenom) Parameters: num and denom are signed integers. num is the numerator and denom is the denominator. lnum and ldenom are signed longs , signed int32, int48 or int64 lnum is ...
Page 192
Syntax: dma_start(channel, mode, addressA, addressB, count); Parameters: Channel- The channel used in the DMA transfer mode - The mode used for the DMA transfer. addressA- The start RAM address of the buffer to use located within the DMA ...
Page 193
Syntax: enable_interrupts (name) enable_interrupts (INTR_XX) Parameters: name- a constant defined in the devices .h file INTR_XX – Allows user selectable interrupt options like INTR_NORMAL, INTR_ALTERNATE, INTR_LEVEL Returns: undefined Function: Name -Enables the interrupt for the given name. Valid ...
Page 194
Syntax: erase_program_memory (address); Parameters: address is 32 bits. The least significant bits may be ignored. Returns: undefined Function: Erases FLASH_ERASE_SIZE bytes to 0xFFFF in program memory. FLASH_ERASE_SIZE varies depending on the part. Family dsPIC30F dsPIC33FJ PIC24FJ PIC24HJ NOTE: Each ...
Page 195
Availability: All devices Requires: #INCLUDE <math.h> Examples: // Calculate x to the power of y x_power_y = exp log(x) ); Example Files: None Also See: pow(), log(), log10() ext_int_edge( ) Syntax: ext_int_edge (source, edge) Parameters: source is a ...
Page 196
Syntax: result=fabs (value) Parameters: value is any float type Returns: result is a float with precision to value Function: The fabs function computes the absolute value of a float Availability: All devices. Requires: #INCLUDE <math.h> Examples: double result; ...
Page 197
Syntax: result= fmod (val1, val2) Parameters: val1 is any float type val2 is any float type Returns: result is a float with precision equal to input parameters val1 and val2 Function: Returns the floating point remainder of val1/val2. ...
Page 198
Syntax: result=frexp (value, & exp); Parameters: value is any float type exp is a signed int. Returns: result is a float with precision equal to value Function: The frexp function breaks a floating point number into a normalized ...
Page 199
Examples: setup_timer3(TMR_INTERNAL | TMR_DIV_BY_8); setup_capture(2, CAPTURE_FE | CAPTURE_TIMER3); while(TRUE) { timerValue = get_capture(2, TRUE); printf(“Capture 2 occurred at: %LU”, timerValue); } Example Files: None Also See: setup_capture( ), get_motor_pwm_count( ) Syntax: Data16 = get_motor_pmw_count(pwm); Parameters: pwm- Defines the pwm module ...
Page 200
Syntax: value=get_timer1( ) value=get_timer2( ) value=get_timer3( ) value=get_timer4( ) value=get_timer5( ) value=get_timer6( ) value=get_timer7( ) value=get_timer8( ) value=get_timer9( ) Parameters: None Returns: The current value of the timer as an int16 Function: Retrieves the value of the timer, ...