0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
52203-609

52203-609

  • 厂商:

    CCS

  • 封装:

    -

  • 描述:

    PCD C-COMPILER PIC24, DSPIC

  • 数据手册
  • 价格&库存
52203-609 数据手册
CCS C Compiler Manual PCB, PCM, PCH, and PCD November 2021 ALL RIGHTS RESERVED. Copyright Custom Computer Services, Inc. 2021 1 Table of Contents Overview .......................................................................................................................................................... 20 PCB, PCM, PCH and PCD .......................................................................................................................... 20 Installation ................................................................................................................................................... 21 Technical Support ....................................................................................................................................... 21 Directories ................................................................................................................................................... 22 File Formats ................................................................................................................................................ 22 Invoking the Command Line Compiler ......................................................................................................... 24 Menu ........................................................................................................................................................... 26 Editor Tabs.................................................................................................................................................. 26 Slide Out Windows ...................................................................................................................................... 26 Editor .......................................................................................................................................................... 26 Debugging Windows ................................................................................................................................... 26 Status Bar ................................................................................................................................................... 27 Output Messages ........................................................................................................................................ 27 Program Syntax................................................................................................................................................ 28 Comment .................................................................................................................................................... 28 Trigraph Sequences .................................................................................................................................... 29 Multiple Project Files ................................................................................................................................... 30 Multiple Compilation Units ........................................................................................................................... 30 Full Example Program ................................................................................................................................. 31 Statements ....................................................................................................................................................... 33 if .................................................................................................................................................................. 33 while............................................................................................................................................................ 34 do-while....................................................................................................................................................... 35 for ............................................................................................................................................................... 35 switch .......................................................................................................................................................... 35 return .......................................................................................................................................................... 36 goto ............................................................................................................................................................. 36 label ............................................................................................................................................................ 37 break ........................................................................................................................................................... 37 continue ...................................................................................................................................................... 37 expr ............................................................................................................................................................. 38 stmt ............................................................................................................................................................. 38 Expressions ...................................................................................................................................................... 39 2 Constants .................................................................................................................................................... 39 Identifiers .................................................................................................................................................... 39 Operators .................................................................................................................................................... 40 Operator Precedence .................................................................................................................................. 41 Data Definitions ................................................................................................................................................ 42 Basic Types ................................................................................................................................................ 42 Type Qualifiers ............................................................................................................................................ 44 Enumerated Types ...................................................................................................................................... 45 Structures and Unions ................................................................................................................................. 45 typedef ........................................................................................................................................................ 46 Non-RAM Data Definitions .......................................................................................................................... 47 Using Program Memory for Data ................................................................................................................. 48 Named Registers ........................................................................................................................................ 50 Function Definition ............................................................................................................................................ 51 Overloaded Functions ................................................................................................................................. 52 Reference Parameters ................................................................................................................................ 52 Default Parameters ..................................................................................................................................... 53 Variable Argument Lists .............................................................................................................................. 53 Functional Overview ......................................................................................................................................... 55 I2C .............................................................................................................................................................. 55 ADC ............................................................................................................................................................ 56 Analog Comparator ..................................................................................................................................... 58 CAN Bus ..................................................................................................................................................... 59 CCP ............................................................................................................................................................ 64 Code Profile ................................................................................................................................................ 65 Configuration Memory ................................................................................................................................. 66 CRC ............................................................................................................................................................ 67 DAC ............................................................................................................................................................ 68 Data Eeprom ............................................................................................................................................... 69 DCI.............................................................................................................................................................. 71 DMA ............................................................................................................................................................ 72 Data Signal Modulator ................................................................................................................................. 73 Extended RAM ............................................................................................................................................ 74 External Memory ......................................................................................................................................... 75 General Purpose I/O ................................................................................................................................... 75 Input Capture .............................................................................................................................................. 76 3 Internal LCD ................................................................................................................................................ 77 Internal Oscillator ........................................................................................................................................ 78 Interrupts ..................................................................................................................................................... 80 Low Voltage Detect ..................................................................................................................................... 81 Output Compare/PWM Overview ................................................................................................................ 82 Motor Control PWM ..................................................................................................................................... 83 PMP/EPMP ................................................................................................................................................. 84 Power PWM ................................................................................................................................................ 85 Program EEPROM ...................................................................................................................................... 87 PSP............................................................................................................................................................. 89 QEI.............................................................................................................................................................. 90 RS232 I/O ................................................................................................................................................... 91 RTCC .......................................................................................................................................................... 92 RTOS .......................................................................................................................................................... 93 SPI .............................................................................................................................................................. 95 Timers ......................................................................................................................................................... 97 Timer0......................................................................................................................................................... 98 Timer1......................................................................................................................................................... 99 Timer2....................................................................................................................................................... 100 Timer3....................................................................................................................................................... 101 Timer4....................................................................................................................................................... 101 Timer5....................................................................................................................................................... 101 TimerA ...................................................................................................................................................... 102 TimerB ...................................................................................................................................................... 103 USB .......................................................................................................................................................... 104 Voltage Reference..................................................................................................................................... 107 WDT or Watch Dog Timer ......................................................................................................................... 107 Stream I/O................................................................................................................................................. 109 PreProcessor.................................................................................................................................................. 112 __address__ ............................................................................................................................................. 112 _attribute_x ............................................................................................................................................... 112 #asm, #endasm, #asm asis ....................................................................................................................... 113 #bank_dma ............................................................................................................................................... 124 #bankx ...................................................................................................................................................... 124 #banky ...................................................................................................................................................... 125 #bit ............................................................................................................................................................ 125 4 __buildcount__ .......................................................................................................................................... 126 #build ........................................................................................................................................................ 126 #byte ......................................................................................................................................................... 129 #case ........................................................................................................................................................ 130 __date__ ................................................................................................................................................... 130 #define ...................................................................................................................................................... 131 #definedinc................................................................................................................................................ 132 #device ..................................................................................................................................................... 133 _device__.................................................................................................................................................. 136 #if #else #elif #endif ......................................................................................................................... 136 #error ........................................................................................................................................................ 137 #export (options) ....................................................................................................................................... 138 __file__ ..................................................................................................................................................... 139 __filename__............................................................................................................................................. 140 #fill_rom .................................................................................................................................................... 140 #fuses ....................................................................................................................................................... 141 #hexcomment............................................................................................................................................ 142 #id ............................................................................................................................................................. 142 #ifdef #ifndef #else #endif ..................................................................................................................... 143 #ignore_warnings ...................................................................................................................................... 144 #import(options) ........................................................................................................................................ 145 #include..................................................................................................................................................... 146 #inline ....................................................................................................................................................... 147 #int_xxxx ................................................................................................................................................... 147 #int_default ............................................................................................................................................... 154 #int_global................................................................................................................................................. 155 __line__ .................................................................................................................................................... 156 #list ........................................................................................................................................................... 156 #line .......................................................................................................................................................... 157 #locate ...................................................................................................................................................... 157 #module .................................................................................................................................................... 158 #nolist ....................................................................................................................................................... 159 #ocs .......................................................................................................................................................... 159 #opt ........................................................................................................................................................... 160 #org........................................................................................................................................................... 160 #pin_select ................................................................................................................................................ 162 5 __pcb__ .................................................................................................................................................... 167 __pcd__ .................................................................................................................................................... 167 __pcm__ ................................................................................................................................................... 168 __pch__ .................................................................................................................................................... 168 #pragma .................................................................................................................................................... 169 #priority ..................................................................................................................................................... 169 #profile ...................................................................................................................................................... 170 #recursive ................................................................................................................................................. 171 #reserve .................................................................................................................................................... 171 #rom.......................................................................................................................................................... 172 #separate .................................................................................................................................................. 173 #serialize ................................................................................................................................................... 174 #task ......................................................................................................................................................... 176 __time__ ................................................................................................................................................... 177 #todo ......................................................................................................................................................... 177 #type ......................................................................................................................................................... 178 #undef ....................................................................................................................................................... 180 __unicode__ ............................................................................................................................................. 181 #use capture ............................................................................................................................................. 182 #use_delay................................................................................................................................................ 183 #use dynamic_memory ............................................................................................................................. 185 #use fast_io ............................................................................................................................................... 186 #use fixed_io ............................................................................................................................................. 186 #use i2c..................................................................................................................................................... 187 #use profile() ............................................................................................................................................. 190 #use pwm() ............................................................................................................................................... 190 #use rs232 ................................................................................................................................................ 192 use rtos ..................................................................................................................................................... 196 #use spi..................................................................................................................................................... 197 #use standard_io ....................................................................................................................................... 199 #use timer ................................................................................................................................................. 200 #use touchpad........................................................................................................................................... 201 #warning ................................................................................................................................................... 202 #word ........................................................................................................................................................ 203 #zero_local_ram ........................................................................................................................................ 204 #zero_ram ................................................................................................................................................. 205 6 Built-in Functions ............................................................................................................................................ 206 abs( )......................................................................................................................................................... 206 sin( ) cos( ) tan( ) asin( ) acos() atan() sinh() cosh() tanh() atan2() ............................................... 207 act_status( ) .............................................................................................................................................. 209 adc_done( ) adc2_done( ) adc_done2( ) ................................................................................................ 209 adc_read( )................................................................................................................................................ 210 adc_status() .............................................................................................................................................. 211 adc_write() ................................................................................................................................................ 212 assert( ) ..................................................................................................................................................... 212 atoe( ) ....................................................................................................................................................... 213 atof( ) atof48( ) atof64( ) strtof48( ) ...................................................................................................... 214 atoi( ) atol( ) atoi32( ) atol32( ) atoi48( ) atoi64( ) .................................................................................. 215 at_clear_interrupts( ) ................................................................................................................................. 216 at_disable_interrupts( ) .............................................................................................................................. 217 at_enable_interrupts( ) .............................................................................................................................. 218 at_get_capture( ) ....................................................................................................................................... 219 at_get_missing_pulse_delay( ) .................................................................................................................. 220 at_get_period( ) ......................................................................................................................................... 221 at_get_phase_counter( ) ........................................................................................................................... 221 at_get_resolution( ) ................................................................................................................................... 222 at_get_set_point( ) .................................................................................................................................... 223 at_get_set_point_error( ) ........................................................................................................................... 223 at_get_status( ) ......................................................................................................................................... 224 at_interrupt_active( ) ................................................................................................................................. 225 at_set_compare_time( )............................................................................................................................. 226 at_set_missing_pulse_delay( ) .................................................................................................................. 227 at_set_resolution( ).................................................................................................................................... 228 at_set_set_point( )..................................................................................................................................... 228 at_setup_cc( ) ........................................................................................................................................... 229 bit_clear( ) ................................................................................................................................................. 230 bit_first( ) ................................................................................................................................................... 231 bit_last( ) ................................................................................................................................................... 232 bit_set( ) .................................................................................................................................................... 232 bit_test( ) ................................................................................................................................................... 233 brownout_enable( ) ................................................................................................................................... 234 bsearch( ) .................................................................................................................................................. 235 7 calloc( ) ..................................................................................................................................................... 236 ceil( ) ......................................................................................................................................................... 237 clc1_setup_gate( ) clc2_setup_gate( ) clc3_setup_gate( ) clc4_setup_gate( ) ......................................... 237 clc1_setup_input() clc2_setup_input() clc3_setup_input() clc4_setup_input() ............................................ 238 clear_dmt( ) ............................................................................................................................................... 239 clear_interrupt( ) ........................................................................................................................................ 240 clear_pwm1_interrupt( ) clear_pwm2_interrupt( ) clear_pwm3_interrupt( ) clear_pwm4_interrupt( ) clear_pwm5_interrupt( ) clear_pwm6_interrupt( )....................................................................................... 241 cog_restart( ) cog2_restart( ) cog3_restart( ) cog4_restart() ................................................................... 242 cog_status( ) cog2_status( ) cog3_status( ) cog4_status( ) ..................................................................... 242 crc_calc(mode )......................................................................................................................................... 243 crc_init(mode) ........................................................................................................................................... 245 crc_read( )................................................................................................................................................. 245 crc_write( ) ................................................................................................................................................ 246 cwg_restart( ) cwg2_restart( ) cwg3_restart( ) ......................................................................................... 247 cwg_status( ) cwg2_status( ) cwg3_status( ) ........................................................................................... 247 dac_write( ) ............................................................................................................................................... 248 dci_data_received( ) .................................................................................................................................. 249 dci_read( ) ................................................................................................................................................. 250 dci_start( ) ................................................................................................................................................. 251 dci_transmit_ready( ) ................................................................................................................................. 252 dci_write( ) ................................................................................................................................................ 253 delay_cycles( ) .......................................................................................................................................... 254 delay_ms( ) ............................................................................................................................................... 254 delay_us( ) ................................................................................................................................................ 256 disable_dmt( ) ........................................................................................................................................... 257 disable_interrupts( )................................................................................................................................... 257 disable_pwm1_interrupt( ) disable_pwm2_interrupt( ) disable_pwm3_interrupt( ) disable_pwm4_interrupt( ) disable_pwm5_interrupt( ) disable_pwm6_interrupt( ) ............................................................................... 259 div( ) ldiv( ) ............................................................................................................................................... 260 dma_start( ) ............................................................................................................................................... 261 dma_status( ) ............................................................................................................................................ 263 dmt_status( ) ............................................................................................................................................. 264 enable_dmt( ) ............................................................................................................................................ 264 enable_interrupts( ) ................................................................................................................................... 265 erase_program_memory( ) ........................................................................................................................ 267 8 enable_pwm1_interrupt( ) enable_pwm2_interrupt( ) enable_pwm3_interrupt( ) enable_pwm4_interrupt( ) enable_pwm5_interrupt( ) enable_pwm6_interrupt( ) ................................................................................ 268 erase_eeprom( )........................................................................................................................................ 269 erase_program_memory( ) ........................................................................................................................ 269 exp( )......................................................................................................................................................... 270 ext_int_edge( ) .......................................................................................................................................... 271 fabs( )........................................................................................................................................................ 272 getc( ) getch( ) getchar( ) fgetc( ) ............................................................................................................ 272 gets( ) fgets( ) ........................................................................................................................................... 274 floor( ) ....................................................................................................................................................... 275 fmod( ) ...................................................................................................................................................... 275 printf( ) fprintf( ) ........................................................................................................................................ 276 putc( ) putchar( ) fputc( ) ............................................................................................................................ 278 puts( ) fputs( ) ............................................................................................................................................ 279 free( ) ........................................................................................................................................................ 280 frexp( ) ...................................................................................................................................................... 281 scanf( ) fscanf( ) ....................................................................................................................................... 282 get_adc_ports( ) ........................................................................................................................................ 284 get_capture( ) ............................................................................................................................................ 285 [PCD] get_capture( ) ................................................................................................................................ 286 get_capture32_ccp1( ) get_capture_ccp1( ) get_capture_ccp2() get_capture_ccp3( ) get_capture_ccp4( ) get_capture_ccp5( ) .................................................................................................................................. 287 [PCD] get_capture32_ccp1( ) get_capture32_ccp2( ) get_capture32_ccp3( ) get_capture32_ccp4( ) get_capture32_ccp5( ) .............................................................................................................................. 288 get_capture_event( ) ................................................................................................................................. 289 get_capture_time( ) ................................................................................................................................... 289 [PCD] get_capture32( )............................................................................................................................. 290 get_hspwm_capture( ) ............................................................................................................................... 291 get_hspwm_feedback( ) ............................................................................................................................ 291 get_hspwm_status( ) ................................................................................................................................. 292 get_motor_pwm_count( )........................................................................................................................... 293 get_nco_accumulator( ) ............................................................................................................................. 294 get_nco_inc_value( ) ................................................................................................................................. 295 get_ticks( ) ................................................................................................................................................ 295 get_timerA( ) ............................................................................................................................................. 296 get_timerB( ) ............................................................................................................................................. 297 get_timerx( ) .............................................................................................................................................. 297 9 get_timerxy( ) ............................................................................................................................................ 299 get_timer_ccp1( ) get_timer_ccp2( ) get_timer_ccp3( ) get_timer_ccp4( ) get_timer_ccp5( ) ................. 300 get_tris_x( ) ............................................................................................................................................... 301 get_wdt( ) .................................................................................................................................................. 301 getenv( ) .................................................................................................................................................... 302 goto_address( ) ......................................................................................................................................... 307 high_speed_adc_done( ) ........................................................................................................................... 308 hspwm_do_capture( )................................................................................................................................ 309 hspwm_stop_pwm( ) ................................................................................................................................. 310 hspwm_trigger_pwm( ) .............................................................................................................................. 310 hspwm_update( ) ...................................................................................................................................... 311 i2c_init( ) ................................................................................................................................................... 312 i2c_isr_state( )........................................................................................................................................... 313 i2c_poll( ) .................................................................................................................................................. 314 i2c_read( ) ................................................................................................................................................. 315 i2c_slaveaddr( )......................................................................................................................................... 316 i2c_speed( ) .............................................................................................................................................. 317 i2c_start( ) ................................................................................................................................................. 318 i2c_stop( ) ................................................................................................................................................. 319 i2c_transfer( ) ............................................................................................................................................ 320 i2c_transfer_in( ) ....................................................................................................................................... 321 i2c_transfer_out( ) ..................................................................................................................................... 322 i2c_write( ) ................................................................................................................................................ 323 input( )....................................................................................................................................................... 324 input_change_x( ) ..................................................................................................................................... 325 input_state( ) ............................................................................................................................................. 326 input_x( ) ................................................................................................................................................... 327 interrupt_active( ) ...................................................................................................................................... 328 interrupt_enabled() .................................................................................................................................... 329 isalnum(char) isalpha(char) iscntrl(x) isdigit(char) isgraph(x) islower(char) isspace(char) isupper(char) isxdigit(char) isprint(x) ispunct(x) .................................................................................. 330 isamong( ) ................................................................................................................................................. 331 itoa( )......................................................................................................................................................... 332 jump_to_isr( ) ............................................................................................................................................ 333 kbhit( ) ....................................................................................................................................................... 333 label_address( ) ........................................................................................................................................ 335 labs( ) ........................................................................................................................................................ 335 10 lcd_contrast( ) ........................................................................................................................................... 336 lcd_load( ) ................................................................................................................................................. 337 lcd_symbol( ) ............................................................................................................................................. 337 ldexp( ) ...................................................................................................................................................... 338 load_slave_program( ) .............................................................................................................................. 339 log( ).......................................................................................................................................................... 340 log10( ) ...................................................................................................................................................... 341 longjmp( ) .................................................................................................................................................. 342 make8( ) .................................................................................................................................................... 342 make16( ) .................................................................................................................................................. 343 make32( ) .................................................................................................................................................. 344 malloc( ) .................................................................................................................................................... 345 memcpy( ) memmove( ) ........................................................................................................................... 345 memset( ) .................................................................................................................................................. 346 modf( ) ...................................................................................................................................................... 347 msi_fifo_status( ) ....................................................................................................................................... 348 msi_mailbox_status( ) ............................................................................................................................... 349 msi_read_fifo( ) ......................................................................................................................................... 349 msi_read_mailbox( ) .................................................................................................................................. 350 msi_status( ) ............................................................................................................................................. 351 msi_write_fifo( ) ......................................................................................................................................... 352 msi_write_mailbox( ) ................................................................................................................................. 353 mul( )......................................................................................................................................................... 353 nargs( ) ..................................................................................................................................................... 354 offset( ) offsetofbit( ) ................................................................................................................................. 355 outputx( ) ................................................................................................................................................... 356 output_bit( ) ............................................................................................................................................... 357 output_drive( ) ........................................................................................................................................... 358 output_float( ) ............................................................................................................................................ 359 output_high( ) ............................................................................................................................................ 360 output_low( ) ............................................................................................................................................. 361 output_toggle( ) ......................................................................................................................................... 362 perror( ) ..................................................................................................................................................... 363 pid_busy( ) ................................................................................................................................................ 364 pid_get_result( ) ........................................................................................................................................ 364 pid_read( )................................................................................................................................................. 366 11 pid_write( ) ................................................................................................................................................ 367 pin_select( ) .............................................................................................................................................. 368 pll_locked( )............................................................................................................................................... 369 pmp_address(address )............................................................................................................................. 370 pmp_output_full( ) pmp_input_full( ) pmp_overflow( ) pmp_error( ) pmp_timeout( ) ................................... 370 pmp_read( ) .............................................................................................................................................. 371 pmp_write( ) .............................................................................................................................................. 372 port_a_current_source( ) ........................................................................................................................... 374 port_x_pullups( ) ....................................................................................................................................... 374 pow( ) pwr( ) ............................................................................................................................................. 375 prgx_status() ............................................................................................................................................. 376 printf( ) fprintf( ) ....................................................................................................................................... 377 profileout( ) ................................................................................................................................................ 379 psmc_blanking( ) ....................................................................................................................................... 380 psmc_deadband( ) .................................................................................................................................... 381 psmc_duty( ) ............................................................................................................................................. 382 psmc_freq_adjust( )................................................................................................................................... 383 psmc_modulation( ) ................................................................................................................................... 384 psmc_pins( ) ............................................................................................................................................. 385 psmc_shutdown( ) ..................................................................................................................................... 386 psmc_sync( ) ............................................................................................................................................. 387 psp_output_full( ) psp_input_full( ) psp_overflow( ) psp_error( ) psp_timeout( ) ..................................... 388 psp_read( )................................................................................................................................................ 389 psp_write................................................................................................................................................... 390 putc_send( ) fputc_send( )......................................................................................................................... 390 pwm_off( ) ................................................................................................................................................. 392 pwm_set_duty( )........................................................................................................................................ 392 pwm_set_duty_percent( ) .......................................................................................................................... 393 pwm_set_frequency( ) ............................................................................................................................... 394 pwm1_interrupt_active( ) pwm2_interrupt_active( ) pwm3_interrupt_active( ) pwm4_interrupt_active( ) pwm5_interrupt_active( ) pwm6_interrupt_active( ) ................................................................................... 394 [PCD] qei_get_capture() ........................................................................................................................... 395 qei_get_count( ) ........................................................................................................................................ 396 [PCD] qei_get_index_count().................................................................................................................... 397 [PCD] qei_get_interval_count()................................................................................................................. 398 [PCD] qei_get_velocity_count() ................................................................................................................ 398 qei_set_count( ) ........................................................................................................................................ 399 12 [PCD] qei_set_index_count() .................................................................................................................... 400 qei_status( ) .............................................................................................................................................. 401 qsort( ) ...................................................................................................................................................... 401 rand( ) ....................................................................................................................................................... 402 rcv_buffer_bytes( ) .................................................................................................................................... 403 rcv_buffer_full( ) ........................................................................................................................................ 404 read_adc( ) [PCD] read_adc2( ).............................................................................................................. 404 read_bank( ) .............................................................................................................................................. 406 read_calibration( ) ..................................................................................................................................... 407 read_calibration_memory( ) ....................................................................................................................... 408 read_config_info( ) .................................................................................................................................... 409 read_configuration_memory( )................................................................................................................... 409 read_device_info( ).................................................................................................................................... 410 read_dmt( ) ............................................................................................................................................... 411 read_eeprom( ) ......................................................................................................................................... 412 read_extended_ram( ) ............................................................................................................................... 413 read_program_memory( ).......................................................................................................................... 414 read_high_speed_adc( )............................................................................................................................ 414 read_program_memory( ).......................................................................................................................... 416 read_program_memory( ).......................................................................................................................... 417 read_program_memory8( ) ........................................................................................................................ 418 read_rom_memory( )................................................................................................................................. 418 read_sd_adc( ) .......................................................................................................................................... 419 realloc( ) .................................................................................................................................................... 420 release_io( ) .............................................................................................................................................. 421 reset_cpu( ) ............................................................................................................................................... 422 restart_cause( ) ......................................................................................................................................... 422 restart_wdt( ) ............................................................................................................................................. 423 rotate_left( )............................................................................................................................................... 424 rotate_right( )............................................................................................................................................. 425 rtc_alarm_read( ) ....................................................................................................................................... 426 rtc_alarm_write( ) ...................................................................................................................................... 427 rtc_read( ) ................................................................................................................................................. 428 [PCD] rtc_status( ) .................................................................................................................................... 429 [PCD] rtc_tsx_read() ................................................................................................................................. 429 rtc_write( ) ................................................................................................................................................. 430 13 rtos_await( ) .............................................................................................................................................. 431 rtos_disable( ) ........................................................................................................................................... 432 rtos_enable( ) ............................................................................................................................................ 432 rtos_msg_poll( ) ........................................................................................................................................ 433 rtos_msg_read( ) ....................................................................................................................................... 434 rtos_msg_send( ) ...................................................................................................................................... 434 rtos_overrun( )........................................................................................................................................... 435 rtos_run( ) ................................................................................................................................................. 436 rtos_signal( ) ............................................................................................................................................. 437 rtos_stats( ) ............................................................................................................................................... 437 rtos_terminate( ) ........................................................................................................................................ 438 rtos_wait( ) ................................................................................................................................................ 439 rtos_yield( ) ............................................................................................................................................... 440 set_adc_channel( ) set_adc2_channel( ) ................................................................................................. 441 set_adc_trigger( ) ...................................................................................................................................... 442 set_analog_pins( ) ..................................................................................................................................... 443 scanf( ) fscanf( ) ...................................................................................................................................... 443 [PCD] sent_getd( ).................................................................................................................................... 446 [PCD] sent_putd( ).................................................................................................................................... 447 [PCD] sent_status( ) ................................................................................................................................. 448 set_ccp1_compare_time( ) set_ccp2_compare_time( ) set_ccp3_compare_time( ) set_ccp5_compare_time( ) set_ccp5_compare_time( )............................................................................ 449 set_cog_blanking( ) set_cog2_blanking( ) set_cog3_blanking( ) set_cog4_blanking( )....................... 450 set_cog_dead_band( ) set_cog2_dead_band( ) set_cog3_dead_band( ) set_cog4_dead_band( )....... 451 set_cog_phase( ) set_cog2_phase( ) set_cog3_phase( ) set_cog4_phase( ) ...................................... 451 set_compare_time( ) ................................................................................................................................. 452 set_dedicated_adc_channel( )................................................................................................................... 453 set_hspwm_event( ) set_hspwm_secondary_event( ) ........................................................................... 455 set_hspwm_duty( ) .................................................................................................................................... 455 set_hspwm_duty_adjustment( ) ................................................................................................................. 456 set_hspwm_override( ) .............................................................................................................................. 457 set_hspwm_period( ) ................................................................................................................................. 458 set_hspwm_phase( ) ................................................................................................................................. 459 set_hspwm_scaling( )................................................................................................................................ 460 set_hspwm_scaling( )................................................................................................................................ 461 set_input_level_x( ) ................................................................................................................................... 462 set_motor_pwm_duty( ) ............................................................................................................................. 463 14 set_motor_pwm_event( ) ........................................................................................................................... 463 set_motor_unit( ) ....................................................................................................................................... 464 set_nco_accumulator( ) ............................................................................................................................. 465 set_nco_inc_value( ) ................................................................................................................................. 466 set_open_drain_x(value) ........................................................................................................................... 466 set_power_pwm_override( ) ...................................................................................................................... 467 set_power_pwmx_duty( ) .......................................................................................................................... 468 set_pulldown( ) .......................................................................................................................................... 469 set_pullup( ) .............................................................................................................................................. 470 set_pwm1_duty( ) set_pwm2_duty( ) set_pwm3_duty( ) set_pwm4_duty( ) set_pwm5_duty( ) .................. 470 set_pwm1_offset( ) set_pwm2_offset( ) set_pwm3_offset( ) set_pwm4_offset( ) set_pwm5_offset( ) set_pwm6_offset( ) .................................................................................................................................... 472 set_pwm1_period( ) set_pwm2_period( ) set_pwm3_period( ) set_pwm4_period( ) set_pwm5_period( ) set_pwm6_period( )................................................................................................................................... 473 set_pwmx_phase( ) ................................................................................................................................... 474 set_timerx( ) set_rtcc( ) set_timer0( ) set_timer1( ) set_timer2( ) set_timer3( ) set_timer4( ) set_timer5( ) .................................................................................................................................................................. 475 set_ticks( )................................................................................................................................................. 476 setup_sd_adc_calibration( ) ...................................................................................................................... 477 set_sd_adc_channel( ) .............................................................................................................................. 478 set_slow_slew_x() ..................................................................................................................................... 479 set_timerA( ) ............................................................................................................................................. 480 set_timerB( ) ............................................................................................................................................. 480 set_timerxy( ) ............................................................................................................................................ 481 set_timer_ccp1( ) set_timer_ccp2( ) set_timer_ccp3( ) set_timer_ccp4( ) set_timer_ccp5( ) set_timer_ccp6( ) .................................................................................................................................................................. 482 set_timer_period_ccp1( ) set_timer_period_ccp2( ) set_timer_period_ccp3( ) set_timer_period_ccp4( ) set_timer_period_ccp5( ) set_timer_period_ccp6( ) ................................................................................... 483 set_tris( ) ................................................................................................................................................... 484 set_uart_speed( ) ...................................................................................................................................... 485 setjmp( ) .................................................................................................................................................... 486 setup_act( ) ............................................................................................................................................... 487 setup_adc(mode) ...................................................................................................................................... 487 [PCD] setup_adc2(mode) ......................................................................................................................... 487 setup_adc_ports( ) .................................................................................................................................... 489 [PCD] setup_adc_ports2( ) ....................................................................................................................... 489 setup_adc_reference( ) setup_adc_reference2( ) ..................................................................................... 490 setup_adc_reference( ) setup_adc_reference2( ) ..................................................................................... 491 15 setup_at( ) ................................................................................................................................................. 492 setup_capture( ) ........................................................................................................................................ 493 setup_ccp1( ) setup_ccp2( ) setup_ccp3( ) setup_ccp4( ) setup_ccp5( ) setup_ccp6( ) setup_ccp8( ) setup_ccp9( ) setup_ccp10( ) ................................................................................................................... 494 setup_clc1() setup_clc2() setup_clc3() setup_clc4() .................................................................................. 497 setup_comparator( ) .................................................................................................................................. 498 [PCD]setup_comparator_dac( ) ................................................................................................................. 500 setup_comparator_filter( ) ......................................................................................................................... 501 setup_comparator_mask( ) ........................................................................................................................ 502 [PCD] setup_comparator_slope( ) ............................................................................................................ 503 setup_comparator_x( ) .............................................................................................................................. 504 setup_compare( ) ...................................................................................................................................... 505 setup_counters( ) ...................................................................................................................................... 505 setup_crc(mode) ....................................................................................................................................... 507 setup_cog( )setup_cog2( )......................................................................................................................... 508 setup_cwg( ) setup_cwg2( ) setup_cwg3( ) ............................................................................................. 509 [PCD] setup_current_source() .................................................................................................................. 510 setup_dac( ) .............................................................................................................................................. 510 setup_dci( ) ............................................................................................................................................... 511 setup_dedicated_adc( ) ............................................................................................................................. 513 setup_dma( ) ............................................................................................................................................. 514 setup_dmt( ) .............................................................................................................................................. 515 setup_dsm() .............................................................................................................................................. 516 setup_external_memory( )......................................................................................................................... 517 setup_high_speed_adc( ) .......................................................................................................................... 518 setup_high_speed_adc_pair( ) .................................................................................................................. 519 setup_hspwm( ) setup_hspwm_secondary( )........................................................................................... 520 setup_hspwm_blanking( ).......................................................................................................................... 521 setup_hspwm_chop_clock( ) ..................................................................................................................... 522 setup_hspwm_current_limit( ).................................................................................................................... 523 setup_hspwm_event( ) .............................................................................................................................. 524 setup_hspwm_fault( ) ................................................................................................................................ 525 setup_hspwm_feed_forward( ) .................................................................................................................. 525 setup_hspwm_logic_x( ) ............................................................................................................................ 526 setup_hspwm_sync( ) ............................................................................................................................... 527 setup_hspwm_trigger( ) ............................................................................................................................. 528 setup_hspwm_unit( ) ................................................................................................................................. 529 16 setup_hspwm_unit_chop_clock( ).............................................................................................................. 530 setup_lcd( ) ............................................................................................................................................... 531 setup_low_volt_detect( )............................................................................................................................ 533 setup_motor_pwm( ) ................................................................................................................................. 534 setup_msi( ) .............................................................................................................................................. 535 setup_nco( ) .............................................................................................................................................. 535 setup_opamp1( ) setup_opamp2( ) setup_opamp3( ) setup_opamp4( ) .................................................... 536 setup_opamp1( ) setup_opamp2( ) setup_opamp3( ) setup_opamp4( ).................................................... 537 setup_oscillator( ) ...................................................................................................................................... 538 setup_pga( ) .............................................................................................................................................. 540 setup_pid( ) ............................................................................................................................................... 540 setup_pmp(option,address_mask)............................................................................................................. 541 setup_power_pwm( ) ................................................................................................................................. 542 setup_power_pwm_faults( ) ...................................................................................................................... 544 setup_power_pwm_pins( ) ........................................................................................................................ 545 setup_prgx() .............................................................................................................................................. 545 setup_psmc( ) ........................................................................................................................................... 546 setup_psp(option,address_mask) .............................................................................................................. 548 setup_pwm1( ) setup_pwm2( ) setup_pwm3( ) setup_pwm4( ) .................................................................. 550 setup_qei( ) ............................................................................................................................................... 550 setup_rtc( ) ................................................................................................................................................ 551 setup_rtc_alarm( ) ..................................................................................................................................... 553 setup_sd_adc( ) ........................................................................................................................................ 553 [PCD] setup_sent( ) .................................................................................................................................. 554 setup_smtx( ) ............................................................................................................................................ 555 setup_spi( ) setup_spi2( ) setup_spi3( ) setup_spi4( ) ........................................................................... 556 setup_timerx( ) .......................................................................................................................................... 557 setup_timerA( ).......................................................................................................................................... 559 setup_timerB( ).......................................................................................................................................... 560 setup_timer0( ) .......................................................................................................................................... 560 setup_timer1( ) .......................................................................................................................................... 561 setup_timer2( ) .......................................................................................................................................... 562 setup_timer3( ) .......................................................................................................................................... 563 setup_timer4( ) .......................................................................................................................................... 564 setup_timer5( ) .......................................................................................................................................... 565 setup_uart( ) .............................................................................................................................................. 565 17 setup_vref( ) setup_vref2( ) ..................................................................................................................... 567 setup_wdt( ) .............................................................................................................................................. 568 setup_zcd( ) .............................................................................................................................................. 570 shift_left( ) ................................................................................................................................................. 571 shift_right( ) ............................................................................................................................................... 572 sleep( ) ...................................................................................................................................................... 573 sleep_ulpwu( ) ........................................................................................................................................... 574 smtx_read( ) .............................................................................................................................................. 575 smtx_reset_timer( ) ................................................................................................................................... 576 smtx_start( ) .............................................................................................................................................. 576 smtx_status( )............................................................................................................................................ 577 smtx_stop( ) .............................................................................................................................................. 578 smtx_write( ) ............................................................................................................................................. 578 smtx_update( ) .......................................................................................................................................... 579 spi_data_is_in( ) spi_data_is_in2( )spi_data_is_in3( ).............................................................................. 580 spi_init( ) ................................................................................................................................................... 581 spi_prewrite( ) ........................................................................................................................................... 581 spi_read( ) spi_read2( ) spi_read3( ) spi_read4( ) ................................................................................. 582 spi_set_txcnt( ) .......................................................................................................................................... 584 spi_speed() ............................................................................................................................................... 585 [PCD] spi_transfer_write() ........................................................................................................................ 585 spi_write( ) spi_write2( ) spi_write3( ) spi_write4( ) ................................................................................. 586 spi_xfer( ) .................................................................................................................................................. 588 spi_xfer_in( ) ............................................................................................................................................. 589 sprintf( ) ..................................................................................................................................................... 589 sqrt( ) ........................................................................................................................................................ 590 srand( ) ..................................................................................................................................................... 591 STANDARD STRING FUNCTIONS( ) memchr( ) memcmp( ) strcat( ) strchr( ) strcmp( ) strcoll( ) strcspn( ) strerror( ) stricmp( ) strlen( ) strlwr( ) strncat( ) strncmp( ) strncpy( ) strpbrk( ) strrchr( ) strspn( ) strstr( ) strxfrm( ) ....................................................................... 592 strcpy( ) strcopy( ) .................................................................................................................................... 593 strtod( ) [PCD] strtof( ) [PCD] strto48( ) ............................................................................................... 594 strtok( ) ...................................................................................................................................................... 595 strtol( )....................................................................................................................................................... 596 strtoul( ) ..................................................................................................................................................... 597 swap( ) ...................................................................................................................................................... 598 tolower( ) toupper( ) ................................................................................................................................. 599 18 touchpad_getc( ) ....................................................................................................................................... 599 touchpad_hit( ) .......................................................................................................................................... 600 touchpad_state( ) ...................................................................................................................................... 601 tx_buffer_available( ) ................................................................................................................................. 602 tx_buffer_bytes( ) ...................................................................................................................................... 603 tx_buffer_full( ) .......................................................................................................................................... 604 va_arg( ).................................................................................................................................................... 605 va_end( ) ................................................................................................................................................... 605 va_start( ) .................................................................................................................................................. 606 verify_slave_program( ) ............................................................................................................................. 607 write_bank( ) ............................................................................................................................................. 608 write_configuration_memory( ) .................................................................................................................. 609 write_eeprom( ) ......................................................................................................................................... 610 write_external_memory( ) .......................................................................................................................... 611 write_extended_ram( ) .............................................................................................................................. 612 write_program_eeprom( ) .......................................................................................................................... 613 write_program_memory( ) ......................................................................................................................... 614 write_program_memory8( ) ....................................................................................................................... 616 zcd_status( ) ............................................................................................................................................. 616 Standard C Include Files ................................................................................................................................ 618 errno.h ...................................................................................................................................................... 618 float.h ........................................................................................................................................................ 618 limits.h....................................................................................................................................................... 619 locale.h ..................................................................................................................................................... 620 setjmp.h .................................................................................................................................................... 620 stddef.h ..................................................................................................................................................... 620 stdio.h ....................................................................................................................................................... 620 stdlib.h ...................................................................................................................................................... 620 Software License Agreement .......................................................................................................................... 622 19 Overview OVERVIEW PCB, PCM, PCH and PCD The PCB, PCM, and PCH are separate compilers. PCB is for 12-bit opcodes, PCM is for 14-bit opcodes, and PCH is for 16-bit opcode PIC® microcontrollers. Due to many similarities, all three compilers are covered in this reference manual. Features and limitations that apply to only specific microcontrollers are indicated within. These compilers are specifically designed to meet the unique needs of the PIC® microcontroller. This allows developers to quickly design applications software in a more readable, highlevel language. PCD is a C Compiler for Microchip's 24bit opcode family of microcontrollers, which include the dsPIC30, dsPIC33 and PIC24 families. The compiler is specifically designed to meet the unique needs of the dsPIC® microcontroller. This allows developers to quickly design applications software in a more readable, high-level language. The compiler can efficiently implement normal C constructs, input/output operations, and bit twiddling operations. All normal C data types are supported along with pointers to constant arrays, fixed point decimal, and arrays of bits. [PCD] Special built in functions to perform common functions in the MPU with ease. Extended constructs like bit arrays, multiple address space handling and effective implementation of constant data in Rom make code generation very effective. [PCD] IDE Compilers (PCW, PCWH and PCWHD) have the exclusive C Aware integrated development environment for compiling, analyzing and debugging in real-time. Other features and integrated tools can be viewed here. When compared to a more traditional C compiler, PCB, PCM, and PCH have some limitations. As an example of the limitations, function recursion is not allowed. This is due to the fact that the PIC® has no stack to push variables onto, and also because of the way the compilers optimize the code. The compilers can efficiently implement normal C constructs, input/output operations, and bit twiddling operations. All normal C data types are supported along with pointers to constant arrays, fixed point decimal, and arrays of bits. PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries. REAL ICE™, ICSP™ and In-Circuit Serial Programming™ are trademarks of Microchip Technology Inc. in the U.S. and other countries. 20 Overview Installation Insert the CD ROM, select each of the programs you wish to install and follow the onscreen instructions. If the CD does not auto start run the setup program in the root directory. For help answering the version questions see the "Directories" Help topic. Key Questions that may come up: Keep Settings - Unless you are having trouble select this Link Compiler Extensions - If you select this the file extensions like .c will start the compiler IDE when you double click on files with that extension. .hex files start the CCSLOAD program. This selection can be change in the IDE. Install MP LAB Plug In - If you plan to use MPLAB and you don't select this you will need to download and manually install the Plug-In. Install ICD2, ICD3...drivers-select if you use these microchip ICD units. Delete Demo Files - Always a good idea Install WIN8 APP- Allows you to start the IDE from the MDL style (AKA Metro) Start Menus. Technical Support Compiler, software, and driver updates are available to download at: http://www.ccsinfo.com/download Compilers come with 30 or 60 days of download rights with the initial purchase. One year maintenance plans may be purchased for access to updates as released. The intent of new releases is to provide up-to-date support with greater ease of use and minimal, if any, transition difficulty. To ensure any problem that may occur is corrected quickly and diligently. It is recommended to send an email to: support@ccsinfo.com or use the Technical Support Wizard in PCW. Include the version of the compiler, an outline of the problem and attach any files with the email request. CCS strives to answer technical support timely and thoroughly. Technical Support is available by phone during business hours for urgent needs or if email responses are not adequate. Please call 262-522-6500 x32. 21 Overview Directories The compiler will search the following directories for Include files.  Directories listed on the command line  Directories specified in the .CCSPJT file (edit in the IDE under Options>Project>Include)  Directories specified in the ccs.ini file found using Start>All Programs>PICC>User Data Dir  The same directory as the source.directories in the ccsc.ini file By default, the compiler files are put in C:\Program Files\PICC and the example programs are in \PICC\EXAMPLES. The include files are in PICC\drivers. The device header files are in PICC\devices. The compiler itself is a DLL file. The DLL files are in a DLL directory by default in \PICC\DLL\5.xxx. It is sometimes helpful to maintain multiple compiler versions. For example, a project was tested with a specific version, but newer projects use a newer version. When installing the compiler you are prompted for what version to keep on the PC. IDE users can change versions using Help>about and clicking "other versions." Command Line users use start>all programs>PIC-C>compiler version. Two directories are used outside the PICC tree. Both can be reached with start>all programs>PIC-C. 1.) A project directory as a default location for your projects. By default put in "My Documents." This is a good place for VISTA and up. 2.) User configuration settings and PCWH loaded files are kept in %APPDATA%\PICC File Formats .c - This is the source file containing user C source code. .h - These are standard or custom header files used to define pins, register, register bits, functions and preprocessor directives. .pjt - This is the older pre- Version 5 project file which contains information related to the project. .ccspjt - This is the project file which contains information related to the project. .lst - This is the listing file which shows each C source line and the associated assembly code generated for that line. 22 Overview The elements in the .LST file may be selected in PCW under Options>Project>Output Files CCS Basic - Standard assembly with Opcodes - Includes the HEX opcode for each instruction Old Standard Symbolic - Shows variable names instead of addresses Mach code - Includes the HEX opcode for each instruction SRF names - Instead of an address, a name is used. For example, instead of 044, will show CORCON Symbols - Shows variable names instead of addresses Interpret - Adds a pseudo code interpretation to the right of assembly instruction to help understand the operation. For example: LSR W4,#8,W5 : W5=W4>>8 .sym - 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 textual complexities using Halstead and McCabe metrics. .tre - The tree file shows the call tree. It details each function and what functions it calls along with the ROM and RAM usage for each function. .hex - The compiler generates standard HEX files that are compatible with all programmers. The compiler can output 8-bet hex, 16-bit hex, and binary files. .cof - This is a binary containing machine code and debugging information. The debug files may be output as Microchip .COD file for MPLAB 1-5, Advanced Transdata .MAP file, expanded .COD file for CCS debugging or MPLAB 6 and up .xx .COF file. All file formats and extensions may be selected via Options File Associations option in Windows IDE. .cod - This is the binary file containing debug information. .rtf - The output of the Documentation Generator is exported in a Rich Text File format which can be viewed using the RTF editor or Wordpad. .rvf - The Rich View Format is used by the RTF Editor within the IDE to view the Rich Text File. .dgr - The .DGR file is the output of the flowchart maker. .esym or .xsym - These files are generated for the IDE users. The file contains Identifiers and Comment information. This data can be used for automatic documentation generation and for the IDE helpers. 23 Overview .o - Relocatable object file. .osym - This file is generated when the compiler is set to export a relocatable object file. This file is a .sym file for just the one unit. .err - Compiler error file. .ccsload - Used to link Windows Apps to CCSLoad .ccssiow - Used to link WindowsApps to Serial Port Monitor 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) +FD Select PCD (dsPIC30/dsPIC33/PIC24) +FS Select SXC (SX) +ES Standard error file +T Create call tree (.TRE) +A Create stats file (.STA) +EW Show warning messages +EA Show all error messages and all warnings -D +DS +DM +DC +DF +EO -T -A -EW -E +EX Do not create debug file Standard .COD format debug file .MAP format debug file Expanded .COD format debug file Enables the output of an COFF debug file. Old error file format Do not generate a tree file Do not create stats file (.STA) Suppress warnings (use with +EA) Only show first error Error/warning message format uses GCC's "brief format" (compatible with GCC editor environments) The xxx in the following are optional. If included it sets the file extension: +LNxxx Normal list file +O8xxx 8-bit Intel HEX output file +LSxxx MPASM format list file +OWxxx 16-bit Intel HEX output file +LOxxx Old MPASM list file +OBxxx Binary output file +LYxxx Symbolic list file -O Do not create object file -L Do not create list file +P +Pxx +PN +PE Keep compile status window up after compile Keep status window up for xx seconds after compile Keep status window up only if there are no errors Keep status window up only if there are errors 24 Overview +Z +DF I+="..." Keep scratch files on disk after compile COFF Debug file Same as I="..." Except the path list is appended to the current list I="..." Set include directory search path, for example: I="c:\picc\examples;c:\picc\myincludes" If no I= appears on the command line the .PJT file will be used to supply the include file paths. out="di r" -P +M -M +J -J +ICD #xxx="y yy" Use this directory for output files +Gxxx= "yyy" +? -? Same as #xxx="yyy" +STDO UT +SETU P sourceli ne= +V +Q Outputs errors to STDOUT (for use with third party editors) Close compile window after compile is complete Generate a symbol file (.SYM) Do not create symbol file Create a project file (.PJT) Do not create PJT file Compile for use with an ICD Set a global #define for id xxx with a value of yyy, example: #debug="true" Brings up a help file Same as +? Install CCSC into MPLAB (no compile is done) Allows a source line to be injected at the start of the source file. Example: CCSC +FM myfile.c sourceline=“#include ” Show compiler version (no compile is done) Show all valid devices in database (no compile is done) A / character may be used in place of a + character. The default options are as follows: +FM +ES +J +DC +Y9 -T -A +M +LNlst +O8hex -P -Z If @filename appears on the CCSC command line, command line options will be read from the specified file. Parameters may appear on multiple lines in the file. If the file CCSC.INI exists in the same directory as CCSC.EXE, then command line parameters are read from that file before they are processed on the command line. 25 Overview Examples: CCSC +FM C:\PICSTUFF\TEST.C CCSC +FM +P +T TEST.C The PCW IDE provides the user an easy to use editor and environment for developing microcontroller applications. The IDE comprises of many components, which are summarized below. For more information and details, use the Help>PCW in the compiler.. Many of these windows can be re-arranged and docked into different positions. Menu All of the IDE's functions are on the main menu. The main menu is divided into separate sections, click on a section title ('Edit', 'Search', etc) to change the section. Double clicking on the section, or clicking on the chevron on the right, will cause the menu to minimize and take less space. Editor Tabs All of the open files are listed here. The active file, which is the file currently being edited, is given a different highlight than the other files. Clicking on the X on the right closes the active file. Right clicking on a tab gives a menu of useful actions for that file. Slide Out Windows 'Files' shows all the active files in the current project. 'Projects' shows all the recent projects worked on. 'Identifiers' shows all the variables, definitions, prototypes and identifiers in your current project. Editor The editor is the main work area of the IDE and the place where the user enters and edits source code. Right clicking in this area gives a menu of useful actions for the code being edited. Debugging Windows Debugger control is done in the debugging windows. These windows allow you set breakpoints, single step, watch variables and more. 26 Overview Status Bar The status bar gives the user helpful information like the cursor position, project open and file being edited. Output Messages Output messages are displayed here. This includes messages from the compiler during a build, messages from the programmer tool during programming or the results from find and searching. 27 Program Syntax PROGRAM SYNTAX Every C program must contain a main function which is the starting point of the program execution. The program can be split into multiple functions according to the their purpose and the functions could be called from main or the sub-functions. In a large project functions can also be placed in different C files or header files that can be included in the main C file to group the related functions by their category. CCS C also requires to include the appropriate device file using #include directive to include the device specific functionality. There are also some preprocessor directives like #fuses to specify the fuses for the chip and #use delay to specify the clock speed. The functions contain the data declarations,definitions,statements and expressions. The compiler also provides a large number of standard C libraries as well as other device drivers that can be included and used in the programs. CCS also provides a large number of built-in functions to access the various peripherals included in the PIC microcontroller. Comment Comments – Standard Comments A comment may appear anywhere within a file except within a quoted string. Characters between /* and */ are ignored. Characters after a // up to the end of the line are ignored. Comments for Documentation Generator The compiler recognizes comments in the source code based on certain markups. The compiler recognizes these special types of comments that can be later exported for use in the documentation generator. The documentation generator utility uses a user selectable template to export these comments and create a formatted output document in Rich Text File Format. This utility is only available in the IDE version of the compiler. The source code markups are as follows. Global Comments These are named comments that appear at the top of your source code. The comment names are case sensitive and they must match the case used in the documentation template. For example: //*PURPOSE This program implements a Bootloader. //*AUTHOR John Doe A '//' followed by an * will tell the compiler that the keyword which follows it will be the named comment. The actual comment that follows it will be exported as a paragraph to the documentation generator. Multiple line comments can be specified by adding a : after the *, so the compiler will not concatenate the comments that follow. For example: /**:CHANGES 05/16/06 Added PWM loop 28 Program Syntax 05/27.06 Fixed Flashing problem */ Variable Comments A variable comment is a comment that appears immediately after a variable declaration. For example: int seconds; // Number of seconds since last entry long day, // Current day of the month, /* Current Month */ long year; // Year Function Comments A function comment is a comment that appears just before a function declaration. For example: // The following function initializes outputs void function_foo() { init_outputs(); } Function Named Comments The named comments can be used for functions in a similar manner to the Global Comments. These comments appear before the function, and the names are exported as-is to the documentation generator. For example: //*PURPOSE This function displays data in BCD format void display_BCD( byte n) { display_routine(); } Trigraph Sequences The compiler accepts three character sequences instead of some special characters not available on all keyboards as follows: Sequence Same as ??= # ??( [ ??/ \ ??) ] ??' ^ ??< { 29 Program Syntax ??! ??> ??- | } ~ Multiple Project Files When there are multiple files in a project they can all be included using the #include in the main file or the sub-files to use the automatic linker included in the compiler. All the header files, standard libraries and driver files can be included using this method to automatically link them. For example: if you have main.c, x.c, x.h, y.c,y.h and z.c and z.h files in your project, you can say in: main.c: #include #include #include #include x.c: #include y.c: #include z.c: #include In this example there are 8 files and one compilation unit. Main.c is the only file compiled. Note that the #module directive can be used in any include file to limit the visibility of the symbol in that file. To separately compile your files see the section "multiple compilation units". Multiple Compilation Units Multiple Compilation Units are only supported in the IDE compilers, PCW, PCWH, PCHWD and PCDIDE. When using multiple compilation units, care must be given that pre-processor commands that control the compilation are compatible across all units. It is recommended that directives such as #FUSES, #USE and the device header file all put 30 Program Syntax in an include file included by all units. When a unit is compiled it will output a relocatable object file (*.o) and symbol file (*.osym). There are several ways to accomplish this with the CCS C Compiler. All of these methods and example projects are included in the MCU.zip in the examples directory of the compiler. Full Example Program Here is a sample program with explanation using CCS C to read adc samples over RS232: #include // Loads chip specific definitions #fuses NOPROTECT // Turn off code protection #use delay(clock=20000000) // Specifies clock speed #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Creates RS232 libraries void main() { unsigned int8 i, value, min, max; printf("Sampling:"); // Printf from the RS232 library setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); // Make AN0 a analog pin // Start up the ADC // Set ADC channel to AN0 do { min=255; max=0; for(i=0; i%2x\r\n",get_rtcc()); printf("%2u %X %4X\r\n",x,y,z); printf(LCD_PUTC, "n=%u",n); Example Files: ex_admm.c, ex_lcdkb.c See Also: atoi(), puts(), putc(), getc() (for a stream example), RS232 I/O Overview putc( ) putchar( ) fputc( ) Syntax: putc (cdata) putchar (cdata) fputc(cdata, stream) Parameters: cdata is a 8 bit character. Stream is a stream identifier (a constant byte) Returns: Undefined Function: This function sends a character over the RS232 XMIT pin. A #USE RS232 must appear before this call to determine the baud rate and pin used. The #USE RS232 remains in effect until another is encountered in the file. 278 Built-in Functions If This function sends a character over the RS232 XMIT pin. A #USE RS232 must appear before this call to determine the baud rate and pin used. The #USE RS232 remains in effect until another is encountered in the file. If fputc() is used then the specified stream is used where putc() defaults to STDOUT (the last USE RS232). is used then the specified stream is used where putc() defaults to STDOUT (the last USE RS232). Availability: All Devices Requires: #USE RS232 Examples: putc('*'); for(i=0; i 1 then I2C peripheral is initialized and enabled to specified baud rate Returns: ----Function: To initialize I2C peripheral at run time to specified baud rate. Availability: All Devices Requires: #USE I2C 312 Built-in Functions Examples: #USE I2C(MASTER,I2C1, FAST,NOINIT) i2c_init(TRUE); I2C peripheral //initialize and enable //to baud rate specified in //#USE I2C i2c_init(500000); I2C peripheral //initialize and enable //to a baud rate of 500 KBPS See Also: i2c_poll( ), i2c_speed( ), i2c_slaveaddr( ), i2c_isr_state(_) ,i2c_write( ), i2c_read( ), _use_i2c( ), i2c( ) i2c_isr_state( ) Syntax: state = i2c_isr_state(); state = i2c_isr_state(stream); Parameters: ----Returns: state - is an 8 bit int 0 - Address match received with R/W bit clear, perform i2c_read( ) to read the I2C address. 1-0x7F - Master has written data; i2c_read() will immediately return the data 0x80 - Address match received with R/W bit set; perform i2c_read( ) to read the I2C address, and use i2c_write( ) to pre-load the transmit buffer for the next transaction (next I2C read performed by master will read this byte). 0x81-0xFF - Transmission completed and acknowledged; respond with i2c_write() to pre-load the transmit buffer for the next transition (the next I2C read performed by master will read this byte). Function: Returns the state of I2C communications in I2C slave mode after an SSP interrupt. The return value increments with each byte received or sent. 313 Built-in Functions If 0x00 or 0x80 is returned, an i2C_read( ) needs to be performed to read the I2C address that was sent (it will match the address configured by #USE I2C so this value can be ignored) Availability: Devices with built-in I2C Requires: #USE I2C Examples: #INT_SSP void i2c_isr() { state = i2c_isr_state(); if(state== 0 ) i2c_read(); i@c_read(); if(state == 0x80) i2c_read(2); if(state >= 0x80) i2c_write(send_buffer[state - 0x80]); else if(state > 0) rcv_buffer[state - 1] = i2c_read(); } Example Files: ex_slave.c See Also: i2c_poll, i2c_speed, i2c_start, i2c_stop, i2c_slaveaddr, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_poll( ) Syntax: i2c_poll() i2c_poll(stream) Parameters: stream (optional)- specify the stream defined in #USE I2C Returns: 1 (TRUE) or 0 (FALSE) 314 Built-in Functions Function: The i2c_poll() function should only be used when the built-in SSP is used. This function returns TRUE if the hardware has a received byte in the buffer. When a TRUE is returned, a call to i2c_read() will immediately return the byte that was received. Availability: Devices with built-in I2C Requires: #USE I2C Examples: if(i2c-poll()) buffer [index]=i2c-read();//read data } See Also: i2c_speed, i2c_start, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_read( ) Syntax: data = i2c_read(); data = i2c_read(ack); data = i2c_read(stream, ack); Parameters: ack -Optional, defaults to 1 0 indicates do not ack 1 indicates to ack 2 slave only, indicates to not release clock at end of read. Use when i2c_isr_state() returns 0x80 stream - specify the stream defined in #USE I2C Returns: data - 8 bit int Function: Reads a byte over the I2C interface. In master mode this function will generate the clock and in slave mode it will wait for the clock. There is no timeout for the slave, use 315 Built-in Functions i2c_poll() to prevent a lockup. Use restart_wdt() in the #USE I2C to strobe the watchdog timer in the slave mode while waiting. Availability: All devices Requires: #USE I2C Examples: i2c_start(); i2c_write(0xa1); data1 = i2c_read(TRUE); data2 = i2c_read(FALSE); i2c_stop() Example Files: ex_extee.c with 2416.c See Also: i2c_poll, i2c_speed, i2c_start, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_write, #USE I2C, I2C Overview i2c_slaveaddr( ) Syntax: i2c_slaveaddr(addr); i2c_slaveaddr(stream, addr) Parameters: addr = 8 bit device address stream(optional) - specifies the stream used in #USE I2C Returns: ----Function: This functions sets the address for the I2C interface in slave mode. Availability: Devices with built-in I2C 316 Built-in Functions Requires: #USE I2C Examples: i2c_SlaveAddr(0x08); i2c_SlaveAddr(i2cStream1, 0x08) Example Files: ex_slave.c See Also: i2c_poll, i2c_speed, i2c_start, i2c_stop, i2c_isr_state, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_speed( ) Syntax: i2c_speed (baud) i2c_speed (stream, baud) Parameters: baud is the number of bits per second. stream - specify the stream defined in #USE I2C Returns: ----Function: This function changes the I2c bit rate at run time. This only works if the hardware I2C module is being used. Availability: All Devices Requires: #USE I2C Examples: i2C_Speed (400000); putc(13) Example Files: ex_tgetc.c 317 Built-in Functions See Also: i2c_poll, i2c_start, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_start( ) Syntax: i2c_start() i2c_start(stream) i2c_start(stream, restart) Parameters: stream - specify the stream defined in #USE I2C restart:- 2 - new restart is forced instead of start 1 - normal start is performed 0 - (or not specified) – restart is done only if the compiler last encountered a i2c_start() and no i2c_stop() Returns: Undefined Function: Issues a start condition when in the I2C master mode. After the start condition the clock is held low until i2c_write() is called. If another i2c_start() is called in the same function before an i2c_stop() is called, then a special restart condition is issued. Note that specific I2C protocol depends on the slave device. The i2c_start() function will now accept an optional parameter. If 1 the compiler assumes the bus is in the stopped state. If 2 the compiler treats this i2c_start() as a restart. If no parameter is passed a 2 is used only if the compiler compiled a i2c_start() last with no i2c_stop() since. Availability: All Devices Requires: #USE I2C Examples: i2c_start(); i2c_write(0xa0); i2c_write(address); i2c_start(); i2c_write(0xa1); // // // // Device address Data to device Restart to change data direction 318 Built-in Functions data=i2c_read(0); i2c_stop() // Now read from slave Example Files: ex_extee.c with 2416.c See Also: i2c_poll, i2c_speed, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_stop( ) Syntax: i2c_stop() i2c_stop(stream) Parameters: stream - (optional) specify the stream defined in #USE I2C Returns: Undefined Function: Issues a stop condition when in the I2C master mode. Availability: All Devices Requires: #USE I2C Examples: i2c_start(); i2c_write(0xa0); i2c_write(5); i2c_write(12); i2c_stop(); // Start condition // Device address // Device command // Device data // Stop condition Example Files: ex_extee.c with 2416.c 319 Built-in Functions See Also: i2c_poll, i2c_speed, i2c_start, i2c_slaveaddr, i2c_isr_state, i2c_write, i2c_read, #USE I2C, I2C Overview i2c_transfer( ) Syntax: i2c_transfer([stream], address, wData, wCount, [rData], [rCount]); Parameters: stream - Optional, the stream defined in #USE I2C to use. address - The device address to transfer data to and from. wData - Pointer to data to transfer to device. wCount - Number of bytes to transfer to device. rData - Optional, pointer to save transferred data from device to. Rcount - Optional, number of byte to transfer from device. Must be used if rData is used. Returns: 0 for ACK and 1 for NACK. When only writing data, it returns whether the Slave device ACK'd or NACK'd the write command or last byte transmitted; whichever occurred last. If writing and reading data, if the Slave NACK'd one of the bytes that were transmitted, it returns a NACK, otherwise it returns whether the Slave ACK'd or NACK'd the read command. Function: Transfer data to and from an I2C device. This function does the I2C start, restart, write, read and stop operations. If the Slave device NACK's the write command, read command or one of the write bytes, the function will exit at that point even if it did not finish writing and/or reading all the data. Availability: All devices when #USE I2C is setup for Master Mode. Requires: ----Examples: unsigned int8 rAddress=0; 320 Built-in Functions unsigned int8 rData[16]; int1 ack; ack = i2c_transfer(0xA0,&rAddress, 1, rData, 16); if(ack==0) printf("\r\nData transferred successfully"); else printf("\r\nData transferred unsuccessfully"); Example File: ex_i2c_master_hw_k42.c See Also: i2c_poll(), i2c_speed(), i2c_stop(), i2c_slaveaddr(), i2c_isr_state(), i2c_write(), i2c_read(), i2c_transfer_out(), i2c_transfer_in(), #USE_I2C, I2C Overview i2c_transfer_in( ) Syntax: i2c_transfer_in([stream], address, rData, rCount); Parameters: stream - Optional, the stream defined in #USE I2C to use. address - The device address to transfer data from. rData - Optional, pointer to save transferred data from device to. Rcount - Number of byte to transfer from device. Returns: 0 for ACK and 1 for NACK from the read command. Function: Transfer data to and from an I2C device. This function does the I2C start, restart, write, read and stop operations. If the Slave NACK'd the read command, the function will exit without reading any data. Availability: All devices when #USE I2C is setup for Master Mode. 321 Built-in Functions Requires: ----Examples: unsigned int8 rData[16]; int1 ack; ack=i2c_transfer_in(0xA0,rData,16); if(ack==0) printf("Data read successfully"); else printf("data not read"); Example File: ex_i2c_master_hw_k42.c See Also: i2c_poll(), i2c_speed(), i2c_stop(), i2c_slaveaddr(), i2c_isr_state(), i2c_write(), i2c_read(), i2c_transfer_out(), i2c_transfer(), #USE_I2C, I2C Overview i2c_transfer_out( ) Syntax: i2c_transfer_out([stream], address, wData, wCount); Parameters: stream - Optional, the stream defined in #USE I2C to use. address - The device address to transfer data to. wData - Pointer to data to transfer to device. wcount - Number of bytes to transfer to device. Returns: 0 for ACK and 1 for NACK of either the write command or last byte transmitted, whichever occurred last. Function: Transfer data to and from an I2C device. This function does the I2C start, restart, write, read and stop operations. If the Slave device NACK's the write command or one of the write bytes the function will exit at that point, even if it did not finish writing all the data. 322 Built-in Functions Availability: All devices when #USE I2C is setup for Master Mode. Requires: ----Examples: unsigned int8wData[16]; int1 ack; ack = i2c_transfer_out(0xA0,wData, 16); if(ack==0) printf("\r\nData transferred successfully"); else printf("\r\nData transferred unsuccessfully"); Example File: ex_i2c_master_hw_k42.c See Also: i2c_poll(), i2c_speed(), i2c_stop(), i2c_slaveaddr(), i2c_isr_state(), i2c_write(), i2c_read(), i2c_transfer_in(), i2c_transfer(), #USE_I2C, I2C Overview i2c_write( ) Syntax: i2c_write (data) i2c_write (stream, data) Parameters: data is an 8 bit int stream - specify the stream defined in #USE I2C Returns: This function returns the ACK Bit. 0 means ACK, 1 means NO ACK, 2 means there was a collision if in Multi_Master Mode. This does not return an ACK if using i2c in slave mode. 323 Built-in Functions Function: Sends a single byte over the I2C interface. In master mode this function will generate a clock with the data and in slave mode it will wait for the clock from the master. No automatic time-out is provided in this function. This function returns the ACK bit. The LSB of the first write after a start determines the direction of data transfer (0 is master to slave). Note that specific I2C protocol depends on the slave device. Availability: All Devices Requires: #USE I2C Examples: long cmd; ... i2c_start(); i2c_write(0xa0); i2c_write(cmd); i2c_write(cmd>>8); i2c_stop(); // // // // // Start condition Device address Low byte of command High byte of command Stop condition Example Files: ex_extee.c with 2416.c See Also: i2c_poll, i2c_speed, i2c_start, i2c_stop, i2c_slaveaddr, i2c_isr_state, i2c_read, #USE I2C, I2C Overview input( ) Syntax: value = input (pin) Parameters: Pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43. Pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 0x2C2) bit 3 would have a value of 0x2C2*8+3 or 5651. This is defined as follows: #define PIN_A3 5651. [PCD] 324 Built-in Functions The PIN could also be a variable. The variable must have a value equal to one of the constants (like PIN_A1) to work properly. The tristate register is updated unless the FAST_IO mode is set on port A. note that doing I/O with a variable instead of a constant will take much longer time. Returns: 0 (or FALSE) if the pin is low, 1 (or TRUE) if the pin is high Function: This function returns the state of the indicated pin. The method of I/O is dependent on the last USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input. Availability: All Devices Requires: Pin constants are defined in the devices .h file Examples: while ( !input(PIN_B1) ); // waits for B1 to go high if( input(PIN_A0) ) printf("A0 is now high\r\n"); int16 i=PIN_B1; while(!i); //waits for B1 to go high Example Files: ex_pulse.c See Also: input_x(), output_low(), output_high(), #USE FIXED_IO, #USE FAST_IO, #USE STANDARD_IO, General Purpose I/O input_change_x( ) Syntax: value = input_change_a( ); value = input_change_b( ); value = input_change_c( ); value = input_change_d( ); 325 Built-in Functions value = input_change_e( ); value = input_change_f( ); value = input_change_g( ); value = input_change_h( ); value = input_change_j( ); value = input_change_k( ); value = input_change_l( ); Parameters: ----Returns: An 8-bit or 16-bit int representing the changes on the port Function: This function reads the level of the pins on the port and compares them to the results the last time the input_change_x( ) function was called. A 1 is returned if the value has changed, 0 if the value is unchanged. Availability: All Devices Requires: ----Examples: pin_check = input_change_b( ); See Also: input( ), input_x( ), output_x( ), #USE FIXED_IO, #USE FAST_IO, #USE STANDARD_IO, General Purpose I/O input_state( ) Syntax: value = input_state(pin) Parameters: pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43. 326 Built-in Functions pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 0x2C2) bit 3 would have a value of 0x2C2*8+3 or 5651. This is defined as follows: #define PIN_A3 5651. [PCD] Returns: Bit specifying whether pin is high or low. A 1 indicates the pin is high and a 0 indicates it is low. Function: This function reads the level of a pin without changing the direction of the pin as INPUT() does. Availability: All Devices Requires: ----Examples: level = input_state(pin_A3); printf("level: %d",level) See Also: input(), set_tris_x(), output_low(), output_high(), General Purpose I/O input_x( ) Syntax: value = input_a() value = input_b() value = input_c() value = input_d() value = input_e() value = input_f() value = input_g() value = input_h() value = input_j() value = input_k() value = input_l() Parameters: ----- 327 Built-in Functions Returns: An 8 bit int representing the port input data. [PCD] An 16 bit int representing the port input data. Function: Inputs an entire byte from a port. The direction register is changed in accordance with the last specified #USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input. Inputs an entire word from a port. The direction register is changed in accordance with the last specified #USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input. [PCD] Availability: All Devices Requires: ----Examples: data = input_b(); See Also: input(), output_x(), #USE FIXED_IO, #USE FAST_IO, #USE STANDARD_IO interrupt_active( ) Syntax: interrupt_active (interrupt) Parameters: Interrupt – constant specifying the interrupt Returns: Boolean value Function: The function checks the interrupt flag of the specified interrupt and returns true in case the flag is set. Availability: Devices with Interrupts 328 Built-in Functions Requires: Should have a #INT_xxxx, Constants are defined in the devices .h file Examples: interrupt_active(INT_TIMER0); interrupt_active(INT_TIMER1); See Also: Interrupts Overview, clear_interrupt, enable_interrupts(), disable_interrupts(), #INT, disable_interrupts() , #INT interrupt_enabled() This function checks the interrupt enabled flag for the specified interrupt and returns TRUE if set. Syntax: interrupt_enabled(interrupt); Parameters: interrupt- constant specifying the interrupt Returns: Boolean value Function: The function checks the interrupt enable flag of the specified interrupt and returns TRUE when set. Availability: Devices with Interrupts Requires: Interrupt Constants are defined in the devices .h file Examples: if(interrupt_enabled(INT_RDA)) disable_interrupt(INT_RDA); See Also: Interrupts Overview, clear_interrupt, interrupt_active(), disable_interrupts(), #INT, #INT 329 Built-in Functions isalnum(char) isalpha(char) iscntrl(x) isdigit(char) isgraph(x) islower(char) isspace(char) isupper(char) isxdigit(char) isprint(x) ispunct(x) Syntax: value = isalnum(datac) value = isalpha(datac) value = isdigit(datac) value = islower(datac) value = isspace(datac) value = isupper(datac) value = isxdigit(datac) value = iscntrl(datac) value = isgraph(datac) value = isprint(datac) value = punct(datac) Parameters: datac - is a 8 bit character Returns: 0 (or FALSE) if datac dose not match the criteria, 1 (or TRUE) if datac does match the criteria. Function: Tests a character to see if it meets specific criteria as follows: isalnum(x) X is 0..9, 'A'..'Z', or 'a'..'z' isalpha(x) X is 'A'..'Z' or 'a'..'z isdigit(x) X is '0'..'9' islower(x) X is 'a'..'z' isupper(x) X is 'A'..'Z isspace(x) X is a space isxdigit(x) X is '0'..'9', 'A'..'F', or 'a'..'f iscntrl(x) X is less than a space isgraph(x) X is greater than a space isprint(x) X is greater than or equal to a space ispunct(x) X is greater than a space and not a letter or number Availability: All Devices 330 Built-in Functions Requires: #INCLUDE Examples: char id[20]; ... if(isalpha(id[0])) { valid_id=TRUE; for(i=1;i 10) c = getc(); } 403 Built-in Functions See Also: _USE_RS232( ), rcv_buffer_full( ), tx_buffer_full( ), tx_buffer_bytes( ), getc( ), putc ) ,printf( ), setup_uart( ), putc_send( ) rcv_buffer_full( ) Syntax: value = rcv_buffer_full([stream]); Parameters: stream – optional parameter specifying the stream defined in #USE RS232 Returns: TRUE if receive buffer is full, FALSE otherwise Function: Function to test if the receive buffer is full Availability: All Devices Requires: #USE RS232 Examples: #USE_RS232(UART1,BAUD=9600,RECEIVE_BUFFER=100) void main(void) { char c; if(rcv_buffer_full()) c = getc(); } See Also: _USE_RS232( ), rcv_buffer_full( ), tx_buffer_bytes( ), tx_buffer_bytes( ), getc( ), putc ) ,printf( ), setup_uart( ), putc_send( ) read_adc( ) [PCD] read_adc2( ) Syntax: value = read_adc ([mode]) [PCD] value = read_adc2 ([mode]) [PCD] value=read_adc(mode,[channel]) 404 Built-in Functions Parameters: mode - is an optional parameter. If used the values may be: adc_start_and_read (continually takes readings, this is the default) adc_start_only (starts the conversion and returns) adc_read_only (reads last conversion result) channel - is an optional parameter for specifying the channel to start the conversion on and/or read the result from. If not specified will use channel specified in last call to set_adc_channel(), read_adc(), or adc_done(). [PCD] Returns: Either a 8 or 16 bit int depending on #DEVICE ADC= directive. Function: This function will read the digital value from the analog to digital converter. Calls to setup_adc(), setup_adc_ports() and set_adc_channel() should be made sometime before this function is called. The range of the return value depends on number of bits in the chips A/D converter and the setting in the #DEVICE ADC= directive as follows: #DEVICE 8 bit 10 bit 11 bit 12 bit 16 bit ADC=8 00-FF 00-FF 00-FF 00-FF 00-FF ADC=10 x 0-3FF x 0-3FF x ADC=11 x x 0-7FF x x [PCD] ADC=12 [PCD] 0-FFC [PCD] 0-FFF ADC=16 0FF00 0-FFC0 0-FFEO 0-FFF0 0-FFFF Availability: This function is only available on devices with A/D hardware. [PCD] Only available on devices with built in analog to digital converters. Requires: Pin constants are defined in the devices .h file Examples: setup_adc( ADC_CLOCK_INTERNAL ); setup_adc_ports( ALL_ANALOG ); set_adc_channel(1); while ( input(PIN_B0) ) { delay_ms( 5000 ); value = read_adc(); printf("A/D value = %2x\n\r", value); } 405 Built-in Functions read_adc(ADC_START_ONLY); sleep(); value=read_adc(ADC_READ_ONLY); [PCD] int16 value; setup_adc_ports(sAN0|sAN1, VSS_VDD); setup_adc(ADC_CLOCK_DIV_4|ADC_TAD_MUL_8); while (TRUE) { set_adc_channel(0); value = read_adc(); printf(“Pin AN0 A/C value = %LX\n\r”, value); delay_ms(5000); set_adc_channel(1); read_adc(ADC_START_ONLY); ... value = read_adc(ADC_READ_ONLY); printf("Pin AN1 A/D value = %LX\n\r", value); } Example Files: ex_admm.c, ex_14kad.c See Also: setup_adc(), set_adc_channel(), setup_adc_ports(), #DEVICE, ADC Overview read_bank( ) Syntax: value = read_bank (bank, offset) Parameters: bank - is the physical RAM bank 1-3 (depending on the device) offset - is the offset into user RAM for that bank (starts at 0) Returns: 8 bit int 406 Built-in Functions Function: Read a data byte from the user RAM area of the specified memory bank. This function may be used on some devices where full RAM access by auto variables is not efficient. For example, setting the pointer size to 5 bits on the PIC16C57 chip will generate the most efficient ROM code. However, auto variables can not be above 1Fh. Instead of going to 8 bit pointers, you can save ROM by using this function to read from the hard-to-reach banks. In this case, the bank may be 1-3 and the offset may be 0-15. Availability: All devices but only useful on PCB parts with memory over 1Fh and PCM parts with memory over FFh Requires: ----Examples: // See write_bank() example to see // how we got the data // Moves data from buffer to LCD i=0; do { c=read_bank(1,i++); if(c!=0x13) lcd_putc(c); } while (c!=0x13); Example Files: ex_psp.c See Also: write_bank() read_calibration( ) Syntax: value = read_calibration (n) Parameters: n is an offset into calibration memory beginning at 0 Returns: 8 bit byte 407 Built-in Functions Function: The read_calibration function reads location "n" of the 14000-calibration memory Availability: This function is only available on the PIC14000 Requires: ----Examples: fin = read_calibration(16); Example Files: ex_14kad.c with 14kcal.c read_calibration_memory( ) Syntax: value = read_calibration_memory (cal_word) Parameters: cal_word - calibration word to read from calibration memory (1-16). Returns: unsigned int16 value read from calibration memory. Function: Allows for reading one of the calibration words from the calibration memory. Availability: This function is only available on MCP191xx devices. Requires: ----Examples: CALWD1=read_calibration_memory(1); See Also: Program EEPROM Overview 408 Built-in Functions read_config_info( ) Syntax: read_config_info([offset], ramPtr, count) Parameters: ramPTR - is the destination pointer for the read results. count - is the number of bytes to read. Offset - is an optional parameter specifying the offset into the DCI memory to start reading from, offset default to zero if not used. Returns: ----Function: Read count bytes from Device Configuration Area (DCI) memory and saves the values to ramPtr. The DCI region of memory contains read-only data about the device's configuration. Availability: Devices with a DCI memory region. Requires: ----Examples: unsigned int16 EraseSize; read_device_info(&EraseSize, 2); memory //reads Erase Row Size from DCI See Also: read_configuration_memory(), read_device_info(), Configuration Memory Overview read_configuration_memory( ) Syntax: read_configuration_memory([offset], ramPtr, n) Parameters: ramPtr - is the destination pointer for the read results 409 Built-in Functions count - is an 8 bit integer offset - is an optional parameter specifying the offset into configuration memory to start reading from, offset defaults to zero if not used. Returns: Undefined Function: Reads n bytes of configuration memory and saves the values to ramPtr. For Enhanced16 devices function reads User ID, Device ID and configuration memory regions. Availability: All Devices Requires: ----Examples: int data[6]; read_configuration_memory(data,6) See Also: write_configuration_memory(), read_program_memory(), Configuration Memory Overview, Configuration Memory Overview read_device_info( ) Syntax: read_device_info([offset], ramPtr, count) Parameters: ramPTR - is the destination pointer for the read results. count - is the number of bytes to read. Offset - is an optional parameter specifying the offset into the DIA memory to start reading from, offset default to zero if not used. Returns: ----- 410 Built-in Functions Function: Read count bytes from Device Information Area (DIA) memory and saves the values to ramPtr. The DIA region of memory contains read-only data used to identify the device. Availability: Devices with a DIA memory region. Requires: ----Examples: unsigned int16 identifier[9]; read_device_info(identifier, 18); DIA memory. //reads Unique Identifier from See Also: read_configuration_memory(), read_config_info(), Configuration Memory Overview read_dmt( ) Syntax: Value = read_dmt(which); Parameters: which - an 8-bit constant indicating which DMT registers to read. The following defines are made in the device's header for selecting the register to read: DMT_READ_COUNT // the current count DMT_READ_MAX_VALUE // the value the count needs to reach for a DMT event to occur DMT_READ_WINDOW_VALUE // the value the count needs to reach before it can be cleared Returns: An int32 value indicating the value that was read from the specified DMT registers. Function: Used to read the DMTCNT, DMTPSCNT and DMTPSINTV registers of the Deadman Timer (DMT) peripheral. Availability: ----- 411 Built-in Functions Requires: ----Examples: Value = read_dmt(DMT_READ_COUNT); See Also: clear_dmt(), disable_dmt(), enable_dmt(), dmt_status(), setup_dmt() read_eeprom( ) Syntax: value = read_eeprom (address) [PCD] value = read_eeprom (address , [N]) read_eeprom(address,variable) read_eeprom(address, pointer, N) Parameters: address - is an 8 bit or 16 bit int depending on the part [PCD] N - specifies the number of EEPROM bytes to read [PCD] variable - a specified location to store EEPROM read results [PCD] pointer - is a pointer to location to store EEPROM read results Returns: An 8 bit int [PCD] A 16 bit int Function: Reads a byte from the specified data EEPROM address. The address begins at 0 and the range depends on the part. [PCD] By default the function reads a word from EEPROM at the specified address. The number of bytes to read can optionally be defined by argument N. If a variable is used as an argument, then EEPROM is read and the results are placed in the variable until the variable data size is full. Finally, if a pointer is used as an argument, then n bytes of EEPROM at the given address are read to the pointer. Availability: This command is only for parts with built-in EEPROMs 412 Built-in Functions Requires: ----Examples: #define LAST_VOLUME 10 volume = read_EEPROM (LAST_VOLUME); See Also: write_eeprom(), erase_eeprom(), Data Eeprom Overview read_extended_ram( ) Syntax: read_extended_ram(page,address,data,count); Parameters: page – the page in extended RAM to read from address – the address on the selected page to start reading from data – pointer to the variable to return the data to count – the number of bytes to read (0-32768) Returns: Undefined Function: To read data from the extended RAM of the device. Availability: On devices with more then 30K of RAM Requires: ----Examples: unsigned int8 data[8]; read_extended_ram(1,0x0000,data,8); See Also: Extended RAM Overview 413 Built-in Functions read_program_memory( ) Syntax: READ_PROGRAM_MEMORY (address, dataptr, count ); Parameters: address is 32 bits. The least significant bit should always be 0 in PCM. dataptr is a pointer to one or more bytes. count is a 8 bit integer on PIC16 count is a 16 bit integer for PIC18 and dsPIC/PIC24 Returns: Undefined Function: Reads count bytes from program memory at address to RAM at dataptr. Availability: On devices with the ability to Read program memory. Requires: ----Examples: char buffer[64]; read_program_memory(0x40000, buffer, 64); See Also: write program memory( ), External memory overview , Program Eeprom Overview read_high_speed_adc( ) Syntax: read_high_speed_adc(pair,mode,result); read_high_speed_adc(pair,result); read_high_speed_adc(pair); read_high_speed_adc(mode,result); read_high_speed_adc(result); read_high_speed_adc(); // Individual start and read or read only // Individual start and read // Individual start only // Global start and read or read only // Global start and read // Global start only 414 Built-in Functions Parameters: pair – Optional parameter that determines which ADC pair number to start and/or read. Valid values are 0 to total number of ADC pairs. 0 starts and/or reads ADC pair AN0 and AN1, 1 starts and/or reads ADC pair AN2 and AN3, etc. If omitted then a global start and/or read will be performed. mode – Optional parameter, if used the values may be: adc_start_and_read (starts conversion and reads result) adc_start_only (starts conversion and returns) adc_read_only (reads conversion result) result – Pointer to return ADC conversion too. Parameter is optional, if not used the read_fast_adc() function can only perform a start. Returns: Undefined Function: This function is used to start an analog to digital conversion and/or read the digital value when the conversion is complete. Calls to setup_high_speed_adc() and setup_high_speed_adc_pairs() should be made sometime before this function is called. When using this function to perform an individual start and read or individual start only, the function assumes that the pair's trigger source was set to individual_software_trigger. When using this function to perform a global start and read, global start only, or global read only. The function will perform the following steps: 1. 2. 3. 4. 5. Determine which ADC pairs are set for global_software_trigger Clear the corresponding ready flags (if doing a start). Set the global software trigger (if doing a start). Read the corresponding ADC pairs in order from lowest to highest (if doing a read). Clear the corresponding ready flags (if doing a read). When using this function to perform a individual read only. The function can read the ADC result from any trigger source. Availability: Only on dsPIC33FJxxGSxxx devices Requires: Constants are define in the device .h file 415 Built-in Functions Examples: //Individual start and read int16 result[2]; setup_high_speed_adc(ADC_CLOCK_DIV_4); setup_high_speed_adc_pair(0, INDIVIDUAL_SOFTWARE_TRIGGER); read_high_speed_adc(0, result); //starts conversion for AN0 //and AN1 and stores result //in result[0] and result[1] //Global start and read int16 result[4]; setup_high_speed_adc(ADC_CLOCK_DIV_4); setup_high_speed_adc_pair(0, GLOBAL_SOFTWARE_TRIGGER); setup_high_speed_adc_pair(4, GLOBAL_SOFTWARE_TRIGGER); read_high_speed_adc(result); //starts conversion for AN0, AN1, //AN8 and AN9 and stores result in //result[0], result //[1], result[2] //and result[3] See Also: setup_high_speed_adc(), setup_high_speed_adc_pair(), high_speed_adc_done() read_program_memory( ) Syntax: value = read_program_eeprom (address) Parameters: address - is 16 bits on PCM parts and 32 bits on PCH parts Returns: 16 bits Function: Reads data from the program memory 416 Built-in Functions Availability: Only devices that allow reads from program memory Requires: ----Examples: checksum = 0; for(i=0;i 3 // cell_1->4, 2->1, 3->2 and 4- See Also: rotate_left(), shift_left(), shift_right() rtc_alarm_read( ) Syntax: rtc_alarm_read(&datetime); Parameters: datetime- A structure that will contain the values to be written to the alarm in the RTCC module. Structure used in read and write functions are defined in the device header file as rtc_time_t Returns: Void 426 Built-in Functions Function: Reads the date and time from the alarm in the RTCC module to structure datetime. Availability: Devices that an RTCC module Requires: ----Examples: rtc_alarm_read(&datetime); See Also: rtc_read(), rtc_alarm_read(), rtc_alarm_write(), setup_rtc_alarm(), rtc_write(), setup_rtc() rtc_alarm_write( ) Syntax: rtc_alarm_write(&datetime); Parameters: datetime- A structure that will contain the values to be written to the alarm in the RTCC module. Structure used in read and write functions are defined in the device header file as rtc_time_t Returns: Void Function: Write the date and time from the alarm in the RTCC module to structure datetime. Availability: Devices that an RTCC module Requires: ----Examples: 427 Built-in Functions rtc_alarm_write(&datetime); See Also: rtc_read(), rtc_alarm_read(), rtc_alarm_write(), setup_rtc_alarm(), rtc_write(), setup_rtc() rtc_read( ) Syntax: rtc_read(&datetime); Parameters: datetime- A structure that will contain the values returned by the RTCC module. Structure used in read and write functions are defined in the device header file as rtc_time_t Returns: Void Function: Reads the current value of Time and Date from the RTCC module and stores the structure date time. Availability: Devices that have a Real-Time Clock and Calendar (RTCC) module. Requires: ----Examples: rtc_read(&datetime); Example Files: ex_rtcc.c See Also: rtc_read(), rtc_alarm_read(), rtc_alarm_write(), setup_rtc_alarm(), rtc_write(), setup_rtc() 428 Built-in Functions [PCD] rtc_status( ) Syntax: Status = rtc_status(); Parameters: ----Returns: An int8 value indicating the status of the RTCC module. See the device's header file for constants that can be and'ed with return value to determine that state of the individual status bits. Function: Used to determine the status of the RTCC module. Availability: Devices that have a Real-Time Clock and Calendar (RTCC) with Timestamp module. Requires: ----Examples: rtc_time_t TimeStamp; rtc_tsa_read(&TimeStamp); rtc_tsb_read(&TimeStamp); //read Timestamp A registers //read Timestamp B registers See Also: setup_rtc(), setup_rtc_alarm(), rtc_read(), rtc_write(), rtc_alarm_read(), rtc_alarm_write( ), rtc_tsx_read() [PCD] rtc_tsx_read() Syntax: rtc_tsa_read(×tamp); rtc_tsb_read(×tamp); Parameters: timestamp - a structure of rtc_time_t to return the timestamp value. Returns: ----429 Built-in Functions Function: Used to read the Timestamp A and Timestamp B registers and converts them to be compatible with the rtc_time_t structure. Availability: Devices that have a Real-Time Clock and Calendar (RTCC) with Timestamp module. Requires: -----Examples: rtc_time_t TimeStamp; rtc_tsa_read(&TimeStamp); rtc_tsb_read(&TimeStamp); //read Timestamp A registers //read Timestamp B registers See Also: setup_rtc(), setup_rtc_alarm(), rtc_read(), rtc_write(), rtc_alarm_read(), rtc_alarm_write( ), rtc_status() rtc_write( ) Syntax: rtc_write(&datetime); Parameters: datetime- A structure that will contain the values to be written to the RTCC module. Structure used in read and write functions are defined in the device header file as rtc_time_t Returns: Void Function: Writes the date and time to the RTCC module as specified in the structure date time. Availability: Devices that an RTCC module Requires: ----430 Built-in Functions Examples: rtc_write(&datetime); Example Files: ex_rtcc.c See Also: rtc_read() , rtc_alarm_read() , rtc_alarm_write() , setup_rtc_alarm() , rtc_write(), setup_rtc() rtos_await( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_await (expre) Parameters: expre is a logical expression Returns: ----Function: This function can only be used in an RTOS task. This function waits for expre to be true before continuing execution of the rest of the code of the RTOS task. This function allows other tasks to execute while the task waits for expre to be true. Availability: All Devices Requires: #USE RTOS Examples: rtos_await(kbhit()); See Also: 431 Built-in Functions rtos_disable( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_disable (task) Parameters: task - is the identifier of a function that is being used as an RTOS task Returns: ----Function: This function disables a task which causes the task to not execute until enabled by rtos_enable(). All tasks are enabled by default. Availability: All Devices Requires: #USE RTOS Examples: rtos_disable(toggle_green); See Also: rtos enable() rtos_enable( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_enable (task) Parameters: task - is the identifier of a function that is being used as an RTOS task Returns: ----- 432 Built-in Functions Function: This function enables a task to execute at it's specified rate. Availability: All Devices Requires: #USE RTOS Examples: rtos_enable(toggle_green); See Also: rtos disable() rtos_msg_poll( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: i = rtos_msg_poll() Parameters: ----Returns: An integer that specifies how many messages are in the queue Function: This function can only be used inside an RTOS task. This function returns the number of messages that are in the queue for the task that the rtos_msg_poll() function is used in. Availability: All Devices Requires: #USE RTOS Examples: if(rtos_msg_poll()) 433 Built-in Functions See Also: rtos msg send(), rtos msg read() rtos_msg_read( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: b = rtos_msg_read() Parameters: ----Returns: A byte that is a message for the task Function: This function can only be used inside an RTOS task. This function reads in the next (message) of the queue for the task that the rtos_msg_read() function is used in. Availability: All Devices Requires: #USE RTOS Examples: if(rtos_msg_poll()) { b = rtos_msg_read(); See Also: rtos msg poll(), rtos msg send() rtos_msg_send( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_msg_send(task, byte) 434 Built-in Functions Parameters: task - is the identifier of a function that is being used as an RTOS task byte - is the byte to send to task as a message Returns: ----Function: This function can be used anytime after rtos_run() has been called. This function sends a byte long message (byte) to the task identified by task. Availability: All Devices Requires: #USE RTOS Examples: if(kbhit()) { rtos_msg_send(echo, getc()); } See Also: rtos_msg_poll(), rtos_msg_read() rtos_overrun( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_overrun([task]) Parameters: task - is an optional parameter that is the identifier of a function that is being used as an RTOS task Returns: A 0 (FALSE) or 1 (TRUE) 435 Built-in Functions Function: This function returns TRUE if the specified task took more time to execute than it was allocated. If no task was specified, then it returns TRUE if any task ran over it's alloted execution time. Availability: All Devices Requires: #USE RTOS Examples: rtos_overrun(); rtos_run( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_run( ) Parameters: ----Returns: ----Function: This function begins the execution of all enabled RTOS tasks. This function controls the execution of the RTOS tasks at the allocated rate for each task. This function will return only when rtos_terminate() is called. Availability: All Devices Requires: #USE RTOS Examples: rtos_run(); 436 Built-in Functions See Also: rtos terminate() rtos_signal( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_signal (sem) Parameters: sem is a global variable that represents the current availability of a shared system resource (a semaphore) Returns: ----Function: This function can only be used by an RTOS task. This function increments sem to let waiting tasks know that a shared resource is available for use. Availability: All Devices Requires: #USE RTOS Examples: rtos_signal(uart_use); See Also: rtos wait() rtos_stats( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_stats(task,&stat) 437 Built-in Functions Parameters: task - is the identifier of a function that is being used as an RTOS task. stat - is a structure containing the following: struct rtos_stas_struct { unsigned int32 task_total_ticks; //number of ticks the task has used unsigned int16 task_min_ticks; //the minimum number of ticks used unsigned int16 task_max_ticks; //the maximum number of ticks used unsigned int16 hns_per_tick; //us = (ticks*hns_per_tick)/10 Returns: Undefined Function: This function returns the statistic data for a specified task. Availability: All Devices Requires: #USE RTOS(statistics) Examples: rtos_stats(echo, &stats); See Also: rtos_terminate( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_terminate() Parameters: ----- 438 Built-in Functions Returns: ----Function: This function ends the execution of all RTOS tasks. The execution of the program will continue with the first line of code after the rtos_run() call in the program. (This function causes rtos_run() to return.) Availability: All Devices Requires: #USE RTOS Examples: rtos_terminate() See Also: rtos run() rtos_wait( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_wait (sem) Parameters: sem is a global variable that represents the current availability of a shared system resource (a semaphore) Returns: ----Function: This function can only be used by an RTOS task. This function waits for sem to be greater than 0 (shared resource is available), then decrements sem to claim usage of the shared resource and continues the execution of the rest of the code the RTOS task. This function allows other tasks to execute while the task waits for the shared resource to be available. 439 Built-in Functions Availability: All Devices Requires: #USE RTOS Examples: rtos_wait(uart_use) See Also: rtos signal() rtos_yield( ) The RTOS is only included in the PCW, PCWH and PCWHD software packages. Syntax: rtos_yield() Parameters: ---Returns: ----Function: This function can only be used in an RTOS task. This function stops the execution of the current task and returns control of the processor to rtos_run(). When the next task executes, it will start its execution on the line of code after the rtos_yield(). Availability: All Devices Requires: #USE RTOS Examples: void yield(void) { printf(“Yielding...\r\n”); rtos_yield(); 440 Built-in Functions printf(“Executing code after yield\r\n”); } set_adc_channel( ) set_adc2_channel( ) Syntax: set_adc_channel (chan [,neg])) [PCD] set_adc_channel(chan, [differential]) [PCD] set_adc2_channel(chan) //dsPIC33EPxxGSxxx only Parameters: chan is the channel number to select. Channel numbers start at 0 and are labeled in the data sheet AN0, AN1. For devices with a differential ADC it sets the positive channel to use. neg is optional and is used for devices with a differential ADC only. It sets the negative channel to use, channel numbers can be 0 to 6 or VSS. If no parameter is used the negative channel will be set to VSS by default. Returns: Undefined [PCD] differential is an optional parameter to specify if channel is differential or singleended. TRUE is differential and FALSE is single-ended. Only available for dsPIC3EPxxGSxxx family. Function: Specifies the channel to use for the next read_adc() call. Be aware that you must wait a short time after changing the channel before you can get a valid read. The time varies depending on the impedance of the input source. In general 10us is good for most applications. You need not change the channel before every read if the channel does not change. Availability: This function is only available on devices with A/D hardware. [PCD] Only available on devices with built in analog to digital converters Requires: ----Examples: set_adc_channel(2); delay_us(10); value = read_adc(); 441 Built-in Functions Example Files: ex_admm.c See Also: read_adc(), setup_adc(), setup_adc_ports(), ADC Overview set_adc_trigger( ) Syntax: set_adc_trigger (trigger) Parameters: trigger - ADC trigger source. Constants defined in device's header, see the device's .h file for all options. Some typical options include: ADC_TRIGGER_DISABLED ADC_TRIGGER_ADACT_PIN ADC_TRIGGER_TIMER1 ADC_TRIGGER_CCP1 Returns: Undefined Function: Sets the Auto-Conversion trigger source for the Analog-to-Digital Converter with Computation (ADC2) Module. Availability: All devices with an ADC2 Module Requires: Constants defined in the device's .h file Examples: set__adc_trigger(ADC_TRIGGER_TIMER1); See Also: ADC Overview, setup_adc(), setup_adc_ports(), set_adc_channel(), read_adc(), #DEVICE, adc_read(), adc_write(), adc_status() 442 Built-in Functions set_analog_pins( ) Syntax: set_analog_pins(pin, pin, pin, ...) Parameters: pin - pin to set as an analog pin. Pins are defined in the device's .h file. The actual value is a bit address. For example, bit 3 of port A at address 5, would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43 Returns: Undefined Function: To set which pins are analog and digital. Usage of function depends on method device has for setting pins to analog or digital. For devices with ANSELx, x being the port letter, registers the function is used as described above. For all other devices the function works the same as setup_adc_ports() function. Availability: On all devices with an Analog to Digital Converter Requires: ----Examples: set_analog_pins(PIN_A0,PIN_A1,PIN_E1,PIN_B0,PIN_B5); See Also: setup_adc_reference(), set_adc_channel(), read_adc(), setup_adc(), setup_adc_ports(), ADC Overview scanf( ) fscanf( ) Syntax: scanf(cstring); scanf(cstring, values...) fscanf(stream, cstring, values... Parameters: cstring is a constant string. values is a list of variables separated by commas. 443 Built-in Functions stream is a stream identifier Returns: 0 if a failure occurred, otherwise it returns the number of conversion specifiers that were read in, plus the number of constant strings read in. Function: Reads in a string of characters from the standard RS-232 pins and formats the string according to the format specifiers. The format specifier character (%) used within the string indicates that a conversion specification is to be done and the value is to be saved into the corresponding argument variable. A %% will input a single %. Formatting rules for the format specifier as follows: If fscanf() is used, then the specified stream is used, where scanf() defaults to STDIN (the last USE RS232). Format: The format takes the generic form %nt. n is an option and may be 1-99 specifying the field width, the number of characters to be inputted. t is the type and maybe one of the following: c Matches a sequence of characters of the number specified by the field width (1 if no field width is specified). The corresponding argument shall be a pointer to the initial character of an array long enough to accept the sequence. s Matches a sequence of non-white space characters. The corresponding argument shall be a pointer to the initial character of an array long enough to accept the sequence and a terminating null character, which will be added automatically. u Matches an unsigned decimal integer. The corresponding argument shall be a pointer to an unsigned integer. Lu Matches a long unsigned decimal integer. The corresponding argument shall be a pointer to a long unsigned integer. d Matches a signed decimal integer. The corresponding argument shall be a pointer to a signed integer. Ld Matches a long signed decimal integer. The corresponding argument shall be a pointer to a long signed integer. o Matches a signed or unsigned octal integer. The corresponding argument shall be a pointer to a signed or unsigned integer. 444 Built-in Functions Lo Matches a long signed or unsigned octal integer. The corresponding argument shall be a pointer to a long signed or unsigned integer. x or X Matches a hexadecimal integer. The corresponding argument shall be a pointer to a signed or unsigned integer. Lx or LX Matches a long hexadecimal integer. The corresponding argument shall be a pointer to a long signed or unsigned integer. i Matches a signed or unsigned integer. The corresponding argument shall be a pointer to a signed or unsigned integer. Li Matches a long signed or unsigned integer. The corresponding argument shall be a pointer to a long signed or unsigned integer. f,g or e Matches a floating point number in decimal or exponential format. The corresponding argument shall be a pointer to a float. [ Matches a non-empty sequence of characters from a set of expected characters. The sequence of characters included in the set are made up of all character following the left bracket ([) up to the matching right bracket (]). Unless the first character after the left bracket is a ^, in which case the set of characters contain all characters that do not appear between the brackets. If a - character is in the set and is not the first or second, where the first is a ^, nor the last character, then the set includes all characters from the character before the - to the character after the -. For example, %[a-z] would include all characters from a to z in the set and %[^a-z] would exclude all characters from a to z from the set. The corresponding argument shall be a pointer to the initial character of an array long enough to accept the sequence and a terminating null character, which will be added automatically. n Assigns the number of characters read thus far by the call to scanf() to the corresponding argument. The corresponding argument shall be a pointer to an unsigned integer. An optional assignment-suppressing character (*) can be used after the format specifier to indicate that the conversion specification is to be done, but not saved into a corresponding variable. In this case, no corresponding argument variable should be passed to the scanf() function. 445 Built-in Functions A string composed of ordinary non-white space characters is executed by reading the next character of the string. If one of the inputted characters differs from the string, the function fails and exits. If a white-space character precedes the ordinary non-white space characters, then whitespace characters are first read in until a non-white space character is read. White-space characters are skipped, except for the conversion specifiers [, c or n, unless a white-space character precedes the [ or c specifiers. Availability: All Devices Requires: #USE RS232 Examples: char name[2-]; unsigned int8 number; signed int32 time; if(scanf("%u%s%ld",&number,name,&time)) printf"\r\nName: %s, Number: %u, Time: %ld",name,number,time See Also: RS232 I/O Overview, getc(), putc(), printf() [PCD] sent_getd( ) Syntax: data = sent_getd(module); Parameters: module - the SENT peripheral to setup, 1 or 2 for most devices. Returns: The data read by the SENT peripheral when it is setup as a receiver. The data type SENT_DATA_TYPE is defined in the device's header file for organizing the nibble data. Function: Gets data from the Single-Edge Nibble Transmission (SENT) peripheral's data registers. Availability: Devices with a SENT peripheral. 446 Built-in Functions Requires: ----Examples: SENT_DATA_TYPE Data; Data = sent_getd(1); Example Files: ex_sent_transmitter.c, ex_sent_receiver.c See Also: sent_putd( ), setup_sent( ),sent_status( ) [PCD] sent_putd( ) Syntax: sent_putd(module, data); Parameters: module - the SENT peripheral to setup, 1 or 2 for most devices. data - the data to transmit when SENT peripheral is setup as a transmitter. The data type SENT_DATA_TYPE is defined in the device's header file for organizing the nibble data. Returns: ----Function: Puts data for transmission into the Single-Edge Nibble Transmission (SENT) peripheral's data registers. Availability: Devices with a SENT peripheral. Requires: ----Examples: SENT_DATA_TYPE Data; sent_putd(1, Data); 447 Built-in Functions Example Files: ex_sent_transmitter.c, ex_sent_receiver.c See Also: sent_getd( ),setup_sent( ), sent_status( ) [PCD] sent_status( ) Syntax: status = sent_status(module); Parameters: module - the SENT peripheral to setup, 1 or 2 for most devices. Returns: The status of the SENT peripheral. See device's header file for constants that can be and'ed with return value to determine which status flags are set. Function: Gets status from the Single-Edge Nibble Transmission (SENT) peripheral's status register. Availability: Devices with a SENT peripheral. Requires: ----Examples: unsigned int8 status; status = sent_status(1); Example Files: ex_sent_transmitter.c, ex_sent_receiver.c See Also: sent_putd( ), sent_getd( ), setup_sent( ) 448 Built-in Functions set_ccp1_compare_time( ) set_ccp2_compare_time( ) set_ccp3_compare_time( ) set_ccp5_compare_time( ) set_ccp5_compare_time( ) Syntax: set_ccpx_compare_time(time); set_ccpx_compare_time(timeA, timeB) Parameters: time - may be a 16 or 32-bit constant or varaible. If 16-bit, it sets the CCPxRAL register to the value time and CCPxRBL to zero; used for single edge output compare mode set for 16-bit timer mode. If 32-bit, it sets the CCPxRAL and CCPxRBL register to the value time, CCPxRAL least significant word and CCPRBL most significant word; used for single edge output compare mode set for 32-bit timer mode. timeA - is a 16-bit constant or variable to set the CCPxRAL register to the value of timeA, used for dual edge output c ompare and PWM modes. timeB - is a 16-bit constant or variable to set the CCPxRBL register to the value of timeB, used for dual edge output compare and PWM modes. Returns: Undefined Function: This function sets the compare value for the CCP module. If the CCP module is performing a single edge compare in 16-bit mode, then the CCPxRBL register is not used. If 32-bit mode, the CCPxRBL is the most significant word of the compare time. If the CCP module is performing dual edge compare to generate an output pulse, then timeA, CCPxRAL register, signifies the start of the pulse, and timeB, CCPxRBL register signifies the pulse termination time. Availability: Available only on PIC24FxxKMxxx family of devices with a MCCP and/or SCCP modules Requires: ----Examples: setup_ccp1(CCP_COMPARE_PULSE); set_timer_period_ccp1(800); set_ccp1_compare_time(200,300); at time 449 //generate a pulse starting Built-in Functions // 200 and ending at time 300 See Also: set_pwmX_duty(), setup_ccpX(), set_timer_period_ccpX(), set_timer_ccpX(), get_timer_ccpX(), get_capture_ccpX(), get_captures32_ccpX() set_cog_blanking( ) set_cog2_blanking( ) set_cog3_blanking( ) set_cog4_blanking( ) Syntax: set_cog_blanking(falling_time, rising_time); Parameters: falling time - sets the falling edge blanking time. rising time - sets the rising edge blanking time Returns: ----Function: To set the falling and rising edge blanking times on the Complementary Output Generator (COG) module. The time is based off the source clock of the COG module, the times are either a 4-bit or 6-bit value, depending on the device, refer to the device's datasheet for the correct width. Availability: All devices with a COG module Requires: ----Examples: set_cog_blanking(10,10); See Also: setup_cog(), set_cog_phase(), set_cog_dead_band(), cog_status(), cog_restart() 450 Built-in Functions set_cog_dead_band( ) set_cog2_dead_band( ) set_cog3_dead_band( ) set_cog4_dead_band( ) Syntax: set_cog_dead_band(falling_time, rising_time); Parameters: falling time - sets the falling edge dead-band time. rising time - sets the rising edge dead-band time. Returns: ----Function: To set the falling and rising edge dead-band times on the Complementary Output Generator (COG) module. The time is based off the source clock of the COG module, the times are either a 4-bit or 6-bit value, depending on the device, refer to the device's datasheet for the correct width. Availability: All devices with a COG module Requires: ----Examples: set_cog_dead_band(16,32); See Also: setup_cog(), set_cog_phase(), set_cog_blanking(), cog_status(), cog_restart() set_cog_phase( ) set_cog2_phase( ) set_cog3_phase( ) set_cog4_phase( ) Syntax: set_cog_phase(rising_time); set_cog_phase(falling_time, rising_time); Parameters: falling time - sets the falling edge phase time. 451 Built-in Functions rising time - sets the rising edge phase time. Returns: ----Function: To set the falling and rising edge phase times on the Complementary Output Generator (COG) module. The time is based off the source clock of the COG module, the times are either a 4-bit or 6-bit value, depending on the device. Some devices only have a rising edge delay, refer to the device's datasheet. Availability: All devices with a COG module Requires: ----Examples: set_cog_phase(10,10); See Also: setup_cog(), set_cog_dead_band(), set_cog_blanking(), cog_status(), cog_restart() set_compare_time( ) Syntax: set_compare_time(x, time]) [PCD] set_compare_time(x, ocr, [ocrs]]) Parameters: x - is 1-8 and defines which output compare module to set time for. time - is the compare time for the primary compare register. [PCD] x - is 1-16 and defines which output compare module to set time for. ocr - is the compare time for the primary compare register. ocrs - is the optional compare time for the secondary register. Used for dual compare mode. Returns: ----452 Built-in Functions Function: This function sets the compare value for the CCP module. [PCD] This function sets the compare value for the output compare module. If the output compare module is to perform only a single compare than the ocrs register is not used. If the output compare module is using double compare to generate an output pulse, the ocr signifies the start of the pulse and ocrs defines the pulse termination time. Availability: All devices with a CCP module [PCD] All devices with Output Compare modules Requires: ----Example Files: ex_ccp1s.c [PCD] Example File: // Pin OC1 will be set when //timer 2 is equal to 0xF000 setup_timer2(TMR_INTERNAL | TIMER_DIV_BY_8); setup_compare_time(1, 0xF000); setup_compare(1, COMPARE_SET_ON_MATCH | COMPARE_TIMER2); See Also: get_capture( ), setup_ccpx( ) [PCD] Output Compare set_dedicated_adc_channel( ) Syntax: set_dedicated_adc_channel(core,channel, [differential]); Parameters: core - the dedicated ADC core to setup channel - the channel assigned to the specified ADC core. Channels are defined in the device's .h file as follows: ADC_CHANNEL_AN0 ADC_CHANNEL_AN7 453 Built-in Functions ADC_CHANNEL_PGA1 ADC_CHANNEL_AN0ALT ADC_CHANNEL_AN1 ADC_CHANNEL_AN18 ADC_CHANNEL_PGA2 ADC_CHANNEL_AN1ALT ADC_CHANNEL_AN2 ADC_CHANNEL_AN11 ADC_CHANNEL_VREF_BAND_GAP ADC_CHANNEL_AN3 ADC_CHANNEL_AN15 Not all of the above defines can be used with all the dedicated ADC cores. Refer to the device's header for which can be used with each dedicated ADC core. differential - optional parameter to specify if channel is differential or single-ended. TRUE is differential and FALSE is single-ended. Returns: Undefined Function: Sets the channel that will be assigned to the specified dedicated ADC core. Function does not set the channel that will be read with the next call to read_adc(), use set_adc_channel() or read_adc() functions to set the channel that will be read. Availability: Only dsPIC33EPxxGSxxx family of devices Requires: ----Examples: setup_dedicated_adc_channel(0,ADC_CHANNEL_AN0); See Also: setup_adc(), setup_adc_ports(), set_adc_channel(), read_adc(), adc_done(), setup_dedicated_adc(), ADC Overview 454 Built-in Functions set_hspwm_event( ) set_hspwm_secondary_event( ) Syntax: set_hs hspwm_event(settings, compare_time); set_hswpm_secondary_event(settings, compare_time); //if available Parameter: settings - special event timer setting or'd with a value from 1 to 16 to set the prescaler. The following are the settings available for the special event time: · HSPWM_SPECIAL_EVENT_INT_ENABLED · HSPWM_SPECIAL_EVENT_INT_DISABLED compare_time - the compare time for the special event to occur Returns: -----Function: Sets the specified High Speed PWM unit. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: Constants are defined in the device's .h file Examples: ----See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock() setup_hspwm(), setup_hspwm_secondary() set_hspwm_duty( ) Syntax: set_hspwm_duty(duty); set_hspwm_duty(unit,primary, [secondary]; 455 Built-in Functions Parameters: duty - A 16-bit constant or variable to set the master duty cycle unit - The High Speed PWM unit to set. primary - A 16-bit constant or variable to set the primary duty cycle. secondary - An optional 16-bit constant or variable to set the secondary duty cycle. Secondary duty cycle is only used in Independent PWM mode. Not available on all devices, refer to the device datasheet for availability. Returns: Undefined Function: Sets the specified High Speed PWM unit. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: ----Examples: set_hspwm_duty(0x7FFF); //sets the high speed PWM //master duty cycle set_hspwm_duty(1, 0x3FFF); //sets unit 1's primary duty cycle See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock() setup_hspwm(), setup_hspwm_secondary() set_hspwm_duty_adjustment( ) Syntax: set_hspwm_duty_adjustment(unit, value); 456 Built-in Functions Parameters: unit - The High-Speed PWM unit to set. value - An int8 value to set the PWM unit's duty cycle adjustment value to. Returns: ----Function: To setup the High-Speed PWM (HSPWM) duty cycle adjustment register. This is the value that is added to the duty cycle when the PCI source is active. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: set_hspwm_duty_ajustment(1, 10); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() set_hspwm_override( ) Syntax: set_hspwm_override(unit, setting); Parameters: unit - the High Speed PWM unit to override. settings - the override settings to use. The valid options vary depending on the device. See the device's .h file for all options. Some typical options include: HSPWM_FORCE_H_1 HSPWM_FORCE_H_0 457 Built-in Functions HSPWM_FORCE_L_1 HSPWM_FORCE_L_0 Returns: Undefined Function: Setup and High Speed PWM override settings. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: ----Examples: setup_hspwm_override(1,HSPWM_FORCE_H_1|HSPWM_FORCE_L_0); See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock(), setup_hspwm(), setup_hspwm_secondary() set_hspwm_period( ) Syntax: set_hspwm_period(period); set_hspwm_period(unit, value); Parameters: period - An int16 value to set the PWM master period to. unit - The High-Speed PWM unit to set. value - An int16 value to set the PWM unit's period to. Returns: ----- 458 Built-in Functions Function: Sets up the High-Speed PWM (HSPWM) period registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: set_hspwm_period(0x8000); set_hspwm_period(4,0x9000); //set master period //set PWM unit 4 period See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() set_hspwm_phase( ) Syntax: set_hspwm_phase(unit, primary, [secondary]); Parameters: unit - The High Speed PWM unit to set. primary - A 16-bit constant or variable to set the primary duty cycle. secondary - An optional 16-bit constant or variable to set the secondary duty cycle. Secondary duty cycle is only used in Independent PWM mode. Not available on all devices, refer to device datasheet for availability. Returns: Undefined Function: Sets up the specified High Speed PWM unit. 459 Built-in Functions Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: Constants are defined in the device's .h file Examples: set_hspwm(1,0x1000,0x8000); See Also: setup_hspwm_unit(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock() setup_hspwm(), setup_hspwm_secondary() set_hspwm_scaling( ) Syntax: set_hspwm_scaling(period, inc_value); Parameters: period - An int16 value to set the frequency scaling minimum period to. inc_value - An int16 value to set the value added to the frequency scaling accumulator for each PWM clock. Returns: ----Function: To setup the High-Speed PWM (HSPWM) frequency scaling registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: set_hspwm_scaling(0x8000, 16); 460 Built-in Functions See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(),hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() set_hspwm_scaling( ) Syntax: set_hspwm_trigger_a(unit, value); set_hspwm_trigger_b(unit, value); set_hspwm_trigger_c(unit, value); Parameters: unit - The High-Speed PWM unit to set. value - An int16 value to set the PWM unit's trigger x register to. Returns: ----Function: To setup the High-Speed PWM (HSPWM) trigger A, B and C registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: set_hspwm_trigger_a(1, 0x1000); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), 461 Built-in Functions setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() set_input_level_x( ) Syntax: set_input_level_a(value) set_input_level_b(value) set_input_level_v(value) set_input_level_d(value) set_input_level_e(value) set_input_level_f(value) set_input_level_g(value) set_input_level_h(value) set_input_level_j(value) set_input_level_k(value) set_input_level_l(value) Parameters: value- is an 8-bit int with each bit representing a bit of the I/O port. Returns: Undefined Function: These functions allow the I/O port Input Level Control (INLVLx) registers to be set. Each bit in the value represents one pin. A 1 sets the corresponding pin's input level to Schmitt Trigger (ST) level, and a 0 sets the corresponding pin's input level to TTL level. Availability: All devices with ODC registers, however not all devices have all I/O ports and not all devices port's have a corresponding ODC register. Requires: Constants are defined in the device's .h file Examples: set_input_level_a(0x0); all other //sets PIN_A0 input level to ST and 462 Built-in Functions //PORTA pins to TTL level See Also: output_high(), output_low(), output_bit(), output_x(), General Purpose I/O set_motor_pwm_duty( ) Syntax: set_motor_pwm_duty(pwm,group,time); Parameters: pwm- Defines the pwm module used. group- Output pair number 1,2 or 3. time- The value set in the duty cycle register. Returns: Void Function: Configures the motor control PWM unit duty. Availability: Devices that have the motor control PWM unit. Requires: ----Examples: set_input_level_a(0x0); all other //sets PIN_A0 input level to ST and //PORTA pins to TTL level See Also: get_motor_pwm_count(), set_motor_pwm_event(), set_motor_unit(), setup_motor_pwm() set_motor_pwm_event( ) Syntax: set_motor_pwm_event(pwm,time); [PCD] set_motor_pwm_event(pwm,time,[postscale]); 463 Built-in Functions Parameters: pwm- Defines the pwm module used. time- The value in the special event comparator register used for scheduling other events. postscale- Optional parameter to set the special trigger output postscale (1-16). Defaults to 1 if not specified. [PCD] Returns: Void Function: Configures the PWM event on the motor control unit. Availability: Devices that have the motor control PWM unit. Requires: ----Examples: set_motor_pww_event(pwm,time); [PCD] set_motor_pwm_event(1,625,2); See Also: get_motor_pwm_count(), setup_motor_pwm(), set_motor_unit(), set_motor_pwm_duty() set_motor_unit( ) Syntax: set_motor_unit(pwm,unit,options, active_deadtime, inactive_deadtime); Parameters: pwm- Defines the pwm module used Unit- This will select Unit A or Unit B options- The mode of the power PWM module. See the devices .h file for all options active_deadtime- Set the active deadtime for the unit 464 Built-in Functions inactive_deadtime- Set the inactive deadtime for the unit Returns: Void Function: Configures the motor control PWM unit. Availability: Devices that have the motor control PWM unit. Requires: ----Examples: set_motor_unit(pwm,unit,MPWM_INDEPENDENT | MPWM_FORCE_L_1, active_deadtime, inactive_deadtime); See Also: get_motor_pwm_count(), set_motor_pwm_event(), set_motor_pwm_duty(), setup_motor_pwm() set_nco_accumulator( ) Syntax: set_nco_accumulator(value); Parameters: value - The 20-bit value to set the NCO accumulator to. Returns: ----Function: Used to set the NCO accumulator to a specific value. Availability: Devices with a Numerically Controlled Oscillator (NCO) module. Requires: ----465 Built-in Functions Examples: set_nco_accumulator(500000); See Also: setup_nco( ), get_nco_accumulator( ), set_nco_inc_value( ), get_nco_inc_value( ) set_nco_inc_value( ) Syntax: set_nco_inc_value(value); Parameters: value- value to set the NCO increment registers Returns: Undefined Function: Sets the value that the NCO's accumulator will be incremented by on each clock pulse. The increment registers are double buffered so the new value won't be applied until the accumulator rolls-over. Availability: Devices with a NCO module Requires: ----Examples: set_nco_inc_value(inc_value); value //sets the new increment See Also: setup_nco( ), get_nco_accumulator( ), get_nco_inc_value( ) set_open_drain_x(value) Syntax: set_open_drain_a(value) set_open_drain_b(value) set_open_drain_c(value) set_open_drain_d(value) 466 Built-in Functions set_open_drain_e(value) set_open_drain_f(value) set_open_drain_g(value) set_open_drain_h(value) set_open_drain_j(value) set_open_drain_k(value) Parameters: value – is an 8-bit int with each bit representing a bit of the I/O port. [PCD] value – is a 16-bit int with each bit representing a bit of the I/O port. Returns: -----Function: These functions allow the I/O port Open-Drain Control (ODCONx) registers to be set. Each bit in the value represents one pin. A 1 sets the corresponding pin to act as an open-drain output, and a 0 sets the corresponding pin to act as a digital output. [PCD] Enables/Disables open-drain output capability on port pins. Not all ports or port pins have open-drain capability, refer to devices data sheet for port and pin availability. Availability: Devices with a NCO module Requires: ----Examples: set_open_drain_a(0x01); set_open_drain_b(0x001); //makes PIN_A0 an open-drain output. //enables open-drain output on PIN-B0 //disable on all other port B pins See Also: output_high(), output_low(), output_bit(), output_x(), General Purpose I/O set_power_pwm_override( ) Syntax: set_power_pwm_override(pwm, override, value) Parameters: pwm - is a constant between 0 and 7 Override - is true or false Value - is 0 or 1 467 Built-in Functions Returns: Undefined Function: pwm - selects which module will be affected. Override - determines whether the output is to be determined by the OVDCONS register or the PDC registers. When override is false, the PDC registers determine the output. When override is true, the output is determined by the value stored in OVDCONS. value - determines if pin is driven to it's active staet or if pin will be inactive. I will be driven to its active state, 0 pin will be inactive. Availability: All devices equipped with PWM. Requires: ----Examples: set_power_pwm_override(1, true, 1); //PWM1 will be overridden to active state set_power_pwm_override(1, false, 0); //PMW1 will not be overidden See Also: setup_power_pwm(), setup_power_pwm_pins(), set_power_pwmX_duty() set_power_pwmx_duty( ) Syntax: set_power_pwmX_duty(duty) Parameters: X is 0, 2, 4, or 6 Duty is an integer between 0 and 16383 Returns: Undefined Function: Stores the value of duty into the appropriate PDCXL/H register. This duty value is the amount of time that the PWM output is in the active state. 468 Built-in Functions Availability: All devices equipped with PWM. Requires: ----Examples: set_power_pwmx_duty(4000); See Also: setup_power_pwm(), setup_power_pwm_pins(), set_power_pwm_override() set_pulldown( ) Syntax: set_Pulldown(state [, pin]) Parameters: Pins are defined in the devices .h file. If no pin is provided in the function call, then all of the pins are set to the passed in state. State is either true or false. Returns: Undefined Function: Sets the pin's pull down state to the passed in state value. If no pin is included in the function call, then all valid pins are set to the passed in state. Availability: All devices equipped with pull-down hardware Requires: Pin constants are defined in the devices .h file Examples: set_pulldown(true, PIN_B0); set_pullup(false); false //Sets pin B0's pull down state to true //Sets all pin's pull down state to 469 Built-in Functions set_pullup( ) Syntax: set_pullup(state, [ pin]) Parameters: Pins are defined in the devices .h file. If no pin is provided in the function call, then all of the pins are set to the passed in state. State is either true or false. Pins are defined in the devices .h file. The actual number is a bit address. For example, port a (byte 5 ) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #DEFINE PIN_A3 43 . The pin could also be a variable that has a value equal to one of the predefined pin constants. Note if no pin is provided in the function call, then all of the pins are set to the passed in state. Returns: Undefined Function: Sets the pin's pull up state to the passed in state value. If no pin is included in the function call, then all valid pins are set to the passed in state. Availability: All Devices Requires: Pin constants are defined in the devices .h file Examples: set_pullup(true, PIN_B0); set_pullup(false); //Sets pin B0's pull up state to true //Sets all pin's pull up state to false set_pwm1_duty( ) set_pwm2_duty( ) set_pwm3_duty( ) set_pwm4_duty( ) set_pwm5_duty( ) Syntax: set_pwm1_duty (value) set_pwm2_duty (value) set_pwm3_duty (value) 470 Built-in Functions set_pwm4_duty (value) set_pwm5_duty (value) [PCD] set_pwmX_duty (value) Parameters: value - may be an 8 or 16 bit constant or variable Returns: Undefined Function: Writes the 10-bit value to the PWM to set the duty. An 8-bit value may be used if the most significant bits are not required. The 10 bit value is then used to determine the duty cycle of the PWM signal as follows: duty cycle = value / [ 4 * (PR2 +1 ) ] If an 8-bit value is used, the duty cycle of the PWM signal is determined as follows: duty cycle=value/(PR2+1) Where PR2 is the maximum value timer 2 will count to before toggling the output pin. PIC24FxxKLxxx devices, writes the 10-bit value to the PWM to set the duty. An 8-bit value may be used if the most significant bits are not required. The 10-bit value is then used to determine the duty cycle of the PWM signal as follows: duty cycle = value / [ 4 * (PRx +1 ) ] Where PRx is the maximum value timer 2 or 4 will count to before rolling over. [PCD] PIC24FxxKMxxx devices, wires the 16-bit value to the PWM to set the duty. The 16-bit value is then used to determine the duty cycle of the PWM signal as follows: duty cycle=value/(CCPxPRL+1) Where CCPxPRL is the maximum value timer 2 will count to before toggling the output pin. Availability: This function is only available on devices with CCP/PWM hardware. [PCD] This function is only available on devices with MCCP and/or SCCP modules. Requires: ----Examples: // For a 20 mhz clock, 1.2 khz frequency, // t2DIV set to 16, PR2 set to 200 // the following sets the duty to 50% (or 416 us). 471 Built-in Functions long duty; duty = 408; // [408/(4*(200+1))]=0.5=50% set_pwm1_duty(duty); [PIC24FxxKLxxx Devices] // 32 MHz clock unsigned int16 duty; setup_timer2(T2_DIV_BY_4, 199, 1); setup_ccp1(CCP_PWM); //period=50us duty=400; //duty=400/[4*(199+1)]=0.5=50% set_pwm1_duty(duty); [PIC24FxxKMxxx Devices] // 32 MHz clock unsigned int16 duty; setup_ccp1(CCP_PWM); set_timer_period_ccp1(799); duty=400; set_pwm1_duty(duty); //period=50us //duty=400/(799+1)=0.5=50% Example Files: ex_pwm.c See Also: setup_ccpX(), set_ccpX_compare_time(), set_timer_period_ccpX(), set_timer_ccpX(), get_timer_ccpX(), get_capture_ccpX(, get_captures32_ccpX() set_pwm1_offset( ) set_pwm2_offset( ) set_pwm3_offset( ) set_pwm4_offset( ) set_pwm5_offset( ) set_pwm6_offset( ) Syntax: set_pwm1_offset (value) set_pwm2_offset (value) set_pwm3_offset (value) set_pwm4_offset (value) set_pwm5_offset (value) set_pwm6_offset (value) Parameters: value - 16-bit constant or variable 472 Built-in Functions Returns: Undefined Function: Writes the 16-bit to the PWM to set the offset. The offset is used to adjust the waveform of a slae PWM module relative to the waveform of a master PWM module. Availability: Devices with a 16-bit PWM module Requires: ----Examples: set_pwm1_offset(0x0100); set_pwm1_offset(offset); See Also: setup_pwm(), set_pwm_duty(), set_pwm_period(), clear_pwm_interrupt(), set_pwm_phase(), enable_pwm_interrupt(), disable_pwm_interrupt(), pwm_interrupt_active() set_pwm1_period( ) set_pwm2_period( ) set_pwm3_period( ) set_pwm4_period( ) set_pwm5_period( ) set_pwm6_period( ) Syntax: set_pwm1_period (value) set_pwm2_period (value) set_pwm3_period (value) set_pwm4_period (value) set_pwm5_period (value) set_pwm6_period (value) Parameters: value - 16-bit constant or variable Returns: Undefined 473 Built-in Functions Function: Writes the 16-bit to the PWM to set the period. When the PWM module is set-up for standard mode it sets the period of the PWM signal. When set-up for set on match mode, it sets the maximum value at which the phase match can occur. When in toggle on match and center aligned modes it sets the maximum value the PWMxTMR will count to, the actual period of PWM signal will be twice what the period was set to. Availability: Devices with a 16-bit PWM module Requires: ----Examples: set_pwm1_period(0x8000); set_pwm1_period(period); See Also: setup_pwm(), set_pwm_duty(), set_pwm_phase(), clear_pwm_interrupt(), set_pwm_offset(), enable_pwm_interrupt(), disable_pwm_interrupt(), pwm_interrupt_active() set_pwmx_phase( ) Syntax: set_pwm1_phase (value) set_pwm2_phase (value) set_pwm3_phase (value) set_pwm4_phase (value) set_pwm5_phase (value) set_pwm6_phase (value) Parameters: value - 16-bit constant or variable Returns: Undefined Function: Writes the 16-bit to the PWM to set the phase. When the PWM module is set-up for standard mode the phaes specifies the start of the duty cycle, when in set on match 474 Built-in Functions mode it specifies when the output goes high, and when in toggle on match mode it specifies when the output toggles. Phase is not used when in center aligned mode. Availability: Devices with a 16-bit PWM module Requires: ----Examples: set_pwm1_phase(0); set_pwm1_phase(phase); See Also: setup_pwm(), set_pwm_duty(), set_pwm_period(), clear_pwm_interrupt(), set_pwm_offset(), enable_pwm_interrupt(), disable_pwm_interrupt(), pwm_interrupt_active() set_timerx( ) set_rtcc( ) set_timer0( ) set_timer1( ) set_timer2( ) set_timer3( ) set_timer4( ) set_timer5( ) Syntax: set_timerX(value) set_timer0(value) set_timer1(value) set_timer2(value) set_timer3(value) set_timer4(value) set_timer5(value) or set_rtcc (value) Parameters: Timers 1 & 5 get a 16 bit int. Timer 2 and 4 gets an 8 bit int. Timer 0 (AKA RTCC) gets an 8 bit int except on the PIC18XXX where it needs a 16 bit int. Timer 3 is 8 bit on PIC16 and 16 bit on PIC18 Returns: Undefined 475 Built-in Functions Function: Sets the count value of a real time clock/counter. RTCC and Timer0 are the same. All timers count up. When a timer reaches the maximum value it will flip over to 0 and continue counting (254, 255, 0, 1, 2...) Availability: Timer 0 - All devices Timers 1 & 2 - Most but not all PCM devices Timer 3 - Only PIC18XXX and some pick devices Timer 4 - Some PCH devices Timer 5 - Only PIC18XX31 Requires: ----Examples: set_timer0(81); // 20 mhz clock, no prescaler, //set timer 0 to overflow in 35us // 256-(.000035/(4/20000000)) Example Files: ex_patg.c See Also: set_timer1(), get_timerX() Timer0 Overview, Timer1Overview, Timer2 Overview, Timer5 Overview set_ticks( ) Syntax: set_ticks([stream],value); Parameters: stream – optional parameter specifying the stream defined in #USE TIMER value – a 8, 16 or 32 bit integer, specifying the new value of the tick timer. (int8, int16 or int32) [PCD] value – a 8, 16, 32 or 64 bit integer, specifying the new value of the tick timer. (int8, int16, int32 or int64) Returns: Void 476 Built-in Functions Function: Sets the new value of the tick timer. Size passed depends on the size of the tick timer. Availability: All Devices Requires: #USE TIMER(options) Examples: #USE TIMER(TIMER=1,TICK=1ms,BITS=16,NOISR) void main(void) { unsigned int16 value = 0x1000; set_ticks(value); } (.000035/(4/20000000)) // 256- See Also: #USE TIMER, get_ticks() setup_sd_adc_calibration( ) Syntax: setup_sd_adc_calibration(model); Parameters: mode- selects whether to enable or disable calibration mode for the SD ADC module. The following defines are made in the device's .h file: SDADC_START_CALIBRATION_MODE SDADC_END_CALIBRATION_MODE Returns: ----Function: To enable or disable calibration mode on the Sigma-Delta Analog to Digital Converter (SD ADC) module. This can be used to determine the offset error of the module, which then can be subtracted from future readings. Availability: Devices with a SD ADC module 477 Built-in Functions Requires: #USE TIMER(options) Examples: signed int 32 result, calibration; set_sd_adc_calibration(SDADC_START_CALIBRATION_MODE); calibration=read_sd_adc() set_sd_adc_calibration(SDADC_END_CALIBRATION_MODE); result=read_sd_adc()-calibration; See Also: setup_sd_adc(), read_sd_adc(), set_sd_adc_channel() set_sd_adc_channel( ) Syntax: setup_sd_adc(channel); Parameters: channel- sets the SD ADC channel to read. Channel can be 0 to read the difference between CH0+ and CH0-, 1 to read the difference between CH1+ and CH1-, or one of the following: SDADC_CH1SE_SVSS SDADC_REFERENCE Returns: Void Function: To select the channel that the Sigma-Delta Analog to Digital Converter (SD ADC) performs the conversion on. Availability: Devices with a SD ADC module Requires: ----Examples: set_sd_adc_channel(0); 478 Built-in Functions See Also: setup_sd_adc(), read_sd_adc(), set_sd_adc_calibration() set_slow_slew_x() Syntax: set_slow_slew_a(value); set_slow_slew_b(value); set_slow_slew_c(value); set_slow_slew_d(value); set_slow_slew_e(value); set_slow_slew_f(value); set_slow_slew_g(value); set_slow_slew_h(value); Parameters: value - may be a 1-bit constant or an 8-bit value (see the device's header file to determine which) used to enable and disable slew rating limiting on a port or port pin. Devices that take a 1-bit constant passing a 1 to function enables slew rate limiting on entire port. Passing a 0 to function disables slew rate limiting on entire port. Devices that take an 8-bit value, each bit corresponds to a pin on the port. Setting a bit enables slew rate limiting on that port's corresponding pin and clearing a bit disables slew rate limiting on that port's corresponding pin. Returns: ----Function: Used to enable and disable slew rate limiting on the device's ports or port pins. Availability: Devices that have Slew Rate Control registers for enabling and disabling slew rate limiting. Requires: -----Examples: set_slow_slew_a(TRUE); set_slow_slew_a(0x03); 479 Built-in Functions See Also: set_tris_x(), set_input_level_x(), set_open_drain_x(), get_tris_x(), output_x(), input_x(), input_change_x(), port_x_pullups(), input(), input_state(), output_low(), output_high(), output_toggle(), output_bit(), output_float(), output_drive() set_timerA( ) Syntax: set_timerA(value); Parameters: An 8 bit integer. Specifying the new value of the timer. (int8) Returns: ----Function: Sets the current value of the timer. All timers count up. When a timer reaches the maximum value it will flip over to 0 and continue counting (254, 255, 0, 1, 2, …) Availability: Devices with Timer A hardware Requires: ----Examples: // 20 mhz clock, no prescaler, set timer A set_timerA(81); // to overflow in 35us // 256-(.000035/(4/20000000) See Also: get_timerA( ), setup_timer_A( ), TimerA Overview set_timerB( ) Syntax: set_timerB(value); Parameters: An 8 bit integer. Specifying the new value of the timer. (int8) 480 Built-in Functions Returns: ----Function: Sets the current value of the timer. All timers count up. When a timer reaches the maximum value it will flip over to 0 and continue counting (254, 255, 0, 1, 2, …) Availability: Devices with Timer B hardware Requires: ----Examples: // 20 mhz clock, no prescaler, set timer B set_timerB(81); // to overflow in 35us // 256-(.000035/(4/20000000) See Also: get_timerB( ), setup_timer_B( ), TimerB Overview set_timerxy( ) Syntax: set_timerXY(value) Parameters: A 32 bit integer, specifying the new value of the timer. (int32) Returns: ----Function: Retrieves the 32 bit value of the timers X and Y, specified by XY(which may be 23, 45, 67 and 89) Availability: This function is available on all devices that have a valid 32 bit enabled timers. Timers 2 & 3, 4 & 5, 6 & 7 and 8 & 9 may be used. The target device must have one of these timer sets. The target timers must be enabled as 32 bit. 481 Built-in Functions Requires: ----Examples: if(get_timer45() == THRESHOLD) set_timer(THRESHOLD + 0x1000); values //skip those timer See Also: Timer Overview, setup_timerX(), get_timerXY(), set_timerX(), set_timerXY() set_timer_ccp1( ) set_timer_ccp2( ) set_timer_ccp3( ) set_timer_ccp4( ) set_timer_ccp5( ) set_timer_ccp6( ) Syntax: set_timer_ccpx(time); set_timer_ccpx(timeL, timeH); Parameters: time - may be a 32-bit constant or variable. Sets the timer value for the CCPx module when in 32-bit mode. timeL - may be a 16-bit constant or variable to set the value of the lower timer when CCP module is set for 16-bit mode. timeH - may be a 16-bit constant or variable to set the value of the upper timer when CCP module is set for 16-bit mode. Returns: ----Function: This function sets the timer values for the CCP module. TimeH is optional parameter when using 16-bit mode, defaults to zero if not specified. Availability: Available only on PIC24FxxKMxxx family of devices with a MCCP and/or SCCP modules. Requires: ----Examples: 482 Built-in Functions setup_ccp1(CCP_TIMER); set_timer_ccp1(100,200); timer //set for dual timer mode //set lower timer value to 100 and upper //value to 200 See Also: set_pwmX_duty(), setup_ccpX(), set_ccpX_compare_time(), get_capture_ccpX(), set_timer_period_ccpX(), get_timer_ccpx(), get_captures32_ccpX() set_timer_period_ccp1( ) set_timer_period_ccp2( ) set_timer_period_ccp3( ) set_timer_period_ccp4( ) set_timer_period_ccp5( ) set_timer_period_ccp6( ) Syntax: set_timer_period_ccpx(time); set_timer_period_ccpx(timeL, timeH); Parameters: time - may be a 32-bit constant or variable. Sets the timer value for the CCPx module when in 32-bit mode. timeL - may be a 16-bit constant or variable to set the value of the lower timer when CCP module is set for 16-bit mode. timeH - may be a 16-bit constant or variable to set the value of the upper timer when CCP module is set for 16-bit mode. Returns: ----Function: This function sets the timer periods for the CCP module. When setting up CCP module in 32-bit function is only needed when using Timer mode. Period register are not used when module is setup for 32-bit compare mode, period is always 0xFFFFFFFF. TimeH is optional parameter when using 16-bit mode, default to zero if not specified. Availability: Available only on PIC24FxxKMxxx family of devices with a MCCP and/or SCCP modules. Requires: ----- 483 Built-in Functions Examples: setup_ccp1(CCP_TIMER); set_timer_period_ccp1(800,2000); //set for dual timer mode //set lower timer period to 800 and //upper timer period to 2000 See Also: set_pwmX_duty(), setup_ccpX(), set_ccpX_compare_time(), set_timer_ccpX(), get_timer_ccpX(), get_capture_ccpX(), get_captures32_ccpX() set_tris( ) Syntax: set_tris_a (value) set_tris_b (value) set_tris_c (value) set_tris_d (value) set_tris_e (value) set_tris_f (value) set_tris_g (value) set_tris_h (value) set_tris_j (value) set_tris_k (value) set_tris_l (value) Parameters: value is an 8 bit int with each bit representing a bit of the I/O port. [PCD] value is an 16 bit int with each bit representing a bit of the I/O port. Returns: Undefined Function: These functions allow the I/O port direction (TRI-State) registers to be set. This must be used with FAST_IO and when I/O ports are accessed as memory such as when a # BYTE directive is used to access an I/O port. [PCD] This must be used with FAST_IO and when I/O ports are accessed as memory such as when a #word directive is used to access an I/O port. Using the default standard I/O the built in functions set the I/O direction automatically. Each bit in the value represents one pin. A 1 indicates the pin is input and a 0 indicates it is output. Availability: All devices (however not all devices have all I/O ports) 484 Built-in Functions Requires: Pin constants are defined in the devices .h file Examples: SET_TRIS_B( 0x0F ); [PCD] // B7,B6,B5,B4 are outputs // B3,B2,B1,B0 are inputs // B15,B14,B13,B12,B11,B10,B9,B8, Example Files: lcd.c See Also: #USE FAST_IO, #USE FIXED_IO, #USE STANDARD_IO, General Purpose I/O set_uart_speed( ) Syntax: set_uart_speed (baud, [stream, clock]) Parameters: baud - is a constant representing the number of bits per second. stream - is an optional stream identifier. clock - is an optional parameter to indicate what the current clock is if it is different from the #use delay value Returns: ----Function: Changes the baud rate of the built-in hardware RS232 serial port at run-time. Availability: This function is only available on devices with a built in UART Requires: #USE RS232 Examples: // Set baud rate based on setting // of pins B0 and B1 switch( input_b() & 3 ) { 485 Built-in Functions case case case case 0 1 2 3 : : : : set_uart_speed(2400); set_uart_speed(4800); set_uart_speed(9600); set_uart_speed(19200); break; break; break; break; } Example Files: loader.c See Also: #USE RS232, putc(), getc(), setup uart(), RS232 I/O Overview setjmp( ) Syntax: result = setjmp (env) Parameters: env - The data object that will receive the current environment Returns: If the return is from a direct invocation, this function returns 0. If the return is from a call to the longjmp function, the setjmp function returns a nonzero value and it's the same value passed to the longjmp function. Function: Stores information on the current calling context in a data object of type jmp_buf and which marks where you want control to pass on a corresponding longjmp call. Availability: All Devices Requires: #INCLUDE Examples: result = setjmp(jmpbuf); See Also: longjmp() 486 Built-in Functions setup_act( ) Syntax: setup_act(settings); Parameters: settings - to setup the ACT module. See the device's header file for options. Returns: ----Function: Used to setup the Active Clock Tuning (ACT) module. Availability: Devices with an ACT module. See the device's header file for availability. Requires: ----Examples: setup_act(ACT_ENABLED | ACT_TUNED_TO_USE); See Also: act_status( ) setup_adc(mode) [PCD] setup_adc2(mode) Syntax: setup_adc (mode, [ADCRS], [ADRPT]); [PCD] setup_adc2(mode); Parameters: mode- Analog to digital mode. The valid options vary depending on the device. See the devices .h file for all options. Some typical options include: ADC_OFF ADC_CLOCK_INTERNAL ADC_CLOCK_DIV_32 [PCD] ADC_CLOCK_INTERNAL – The ADC will use an internal clock [PCD] ADC_CLOCK_DIV_32 – The ADC will use the external clock scaled down by 32 [PCD] ADC_TAD_MUL_16 – The ADC sample time will be 16 times the ADC conversion time 487 Built-in Functions ADCRS - For devices with an analog-to-digital converter with computation (ADC2) module only. Optional parameter used set how much the accumulated value is divided by (2^ADCRS) in Accumulate, Average and Parst Average modes, and the cut-off frequency in low-pass filter mode. ADRPT - For devices with an ADC2 module only. Optional parameter used to set the number of samples to be done before performing a threshold comparison in Average, Bust Average and low-pass filter modes. Returns: ----Function: Configures the analog to digital converter. [PCD] Configures the ADC clock speed and the ADC sample time. The ADC converters have a maximum speed of operation, so ADC clock needs to be scaled accordingly. In addition, the sample time can be set by using a bitwise OR to concatenate the constant to the argument. Availability: Only the devices with built in analog to digital converter. Requires: Constants are defined in the devices .h file. Examples: setup_adc_ports( ALL_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); set_adc_channel( 0 ); value = read_adc(); setup_adc( ADC_OFF ) Example Files: ex_admm.c See Also: setup_adc_ports(), set_adc_channel(), read_adc(), #DEVICE, ADC Overview 488 Built-in Functions setup_adc_ports( ) [PCD] setup_adc_ports2( ) Syntax: setup_adc_ports (value) setup_adc_ports (ports, [reference]) setup_adc_ports (ports, [ports2], [reference]) setup_adc_ports (ports, [p2_ports], [reference]) [PCD] setup_adc_ports (ports, reference]) Parameters: value - a constant defined in the device's .h file ports - a constant specifying the ADC pins to use. ports2 - an optional constant on devices with more than 32 analog pins. To specify the ADC pins to use for analog pins 32-x. p2_ports - an optional constant specifying the ADC pins to use on a device that have more than 32 analog pins. Not an option on all devices, see the device's header file to determine if available. For devices with this option, if setting ADC reference, the reference is passed as the third parameter. reference - is an optional constant specifying the ADC reference to use. By default, the reference voltage are Vss and Vdd Returns: ----Function: Sets up the ADC pins to be analog, digital, or a combination and the voltage reference to use when computing the ADC value. The allowed analog pin combinations vary depending on the chip and are defined by using the bitwise OR to concatenate selected pins together. Check the device include file for a complete list of available pins and reference voltage settings. The constants ALL_ANALOG and NO_ANALOGS are valid for all chips. Some other example pin definitions are: sAN1 | sAN2 - AN1 and AN2 are analog, remaining pins are digital sAN0 | sAN3 - AN0 and AN3 are analog, remaining pins are digital Availability: This function is only available on devices with A/D hardware. This function is only available on devices with built-in A/D converters 489 Built-in Functions Requires: Constants are defined in the devices .h file. Examples: setup_adc_ports(ALL_ANALOG); be) // All pins analog (that can setup_adc_ports(RA0_RA1_ANALOG_RA3_REF); // Pins A0 and A1 are analog. Pin RA3 is // used for the reference voltage and all // other pins are digital. setup_adc_ports(ALL_ANALOG); // Set all ADC pins to analog mode. setup_adc_ports(sAN0|sAN1|sAN3); analog and all // Pins AN0, AN1 and AN3 are // others pins are digital. setup_adc_ports(sAN0|sAN1, VREF_VDD); // Pins AN0 and AN1 are analog. The VrefL pin // and Vdd are used for voltage references. Example Files: ex_admm.c See Also: setup_adc_reference(), set_adc_channel(), read_adc(), setup_adc(), set_analog_pins(), ADC Overview setup_adc_reference( ) setup_adc_reference2( ) Syntax: setup_adc_reference(reference) Parameters: reference - the voltage reference to set the ADC. The valid options depend on the device, see the device's .h file for all options. Typical options include: - VSS_VDD - VSS_VREF - VREF_VREF - VREF_VDD Returns: Undefined. 490 Built-in Functions Function: Set the positive and negative voltage reference for the Analog to Digital Converter (ADC) uses. Availability: Only on devices with an ADC and has ANSELx, x being the port letter; registers for setting which pins are analog or digital. Requires: Nothing Examples: setup_adc_reference(VSS_VREF); Examples Files: None See Also: set_analog_pins(), set_adc_channel(), read_adc(), setup_adc(), setup_adc_ports(), ADC Overview setup_adc_reference( ) setup_adc_reference2( ) Syntax: setup_adc_reference(reference) Parameters: reference - the voltage reference to set the ADC. The valid options depend on the device, see the device's .h file for all options. Typical options include: - VSS_VDD - VSS_VREF - VREF_VREF - VREF_VDD Returns: Undefined. Function: Set the positive and negative voltage reference for the Analog to Digital Converter (ADC) uses. 491 Built-in Functions Availability: Only on devices with an ADC and has ANSELx, x being the port letter; registers for setting which pins are analog or digital. Requires: Nothing Examples: setup_adc_reference(VSS_VREF); Examples Files: None See Also: set_analog_pins(), set_adc_channel(), read_adc(), setup_adc(), setup_adc_ports(), ADC Overview setup_at( ) Syntax: setup_at(settings) Parameters: settings - the setup of the AT module. See the device's header file for all options. Some typical options include: at_enabled at_disabled at_multi_pulse_mode at_single_pulse_mode Returns: ----Function: To setup the Angular Timer (AT) module. Availability: All devices with an AT module Requires: Constants defined in the device's .h file 492 Built-in Functions Examples: setup_at(AT_ENABLED|AT_MULTI_PULSE_MODE|AT_INPUT_ATIN); See Also: at_set_resolution(), at_get_resolution(), at_set_missing_pulse_delay(), at_get_missing_pulse_delay(), at_get_period(), at_get_phase_counter(), at_set_set_point(), at_get_set_point(), at_get_set_point_error(), at_enable_interrupts(), at_disable_interrupts(), at_clear_interrupts(), at_interrupt_active(), at_setup_cc(), at_set_compare_time(), at_get_capture(), at_get_status() setup_capture( ) Syntax: setup_capture(x, mode) Parameters: x - is 1-16 and defines which input capture module is being configured mode - is defined by the constants in the devices .h file Returns: ----Function: This function specifies how the input capture module is going to function based on the value of mode. The device specific options are listed in the device .h file Availability: Only available on devices with Input Capture modules Requires: ----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); } 493 Built-in Functions See Also: get_capture( ), setup_compare( ), Input Capture Overview setup_ccp1( ) setup_ccp2( ) setup_ccp3( ) setup_ccp4( ) setup_ccp5( ) setup_ccp6( ) setup_ccp8( ) setup_ccp9( ) setup_ccp10( ) Syntax: setup_ccp1 (mode) or setup_ccp1 (mode, pwm) setup_ccp2 (mode) or setup_ccp2 (mode, pwm) setup_ccp3 (mode) or setup_ccp3 (mode, pwm) setup_ccp5 (mode) or setup_ccp5 (mode, pwm) setup_ccp6 (mode) or setup_ccp6 (mode, pwm) [PCD] setup_ccpx(mode,[pwm]);//PIC24FxxKLxxx devices [PCD] setup_ccpx(mode1,[mode2],[mode3],[dead_time]);//PIC24FxxKMxxx devices Parameters: mode - is a constant. Valid constants are defined in the devices .h file and refer to devices .h file for all options; some options are as follows: Disable the CCP CCP_CAPUTURE_FE CCP_CAPUTURE_RE CCP_CAPUTURE_DIV_4 CCP_CAPUTURE_DIV_16 Set CCP to Capture Mode: CCP_CAPUTURE_SET_ON_MATCH CCP_CAPUTURE_CLR_ON_MATCH CCP_CAPUTURE_INT CCP_CAPUTURE_RESET_TIMER Set to CCP to PWM Mode: CCP_PWM Capture on falling edge Capture on rising edge Capture after 4 pulses Capture after 16 pulses Output high on compare Output low on compare Interrupt on compare Reset timer on compare Enable Pulse Width Modulator Constants used for ECCP Modules: CCP_PWM_H_H CCP_PWM_H_L CCP_PWM_L_H CCP_PWM_L_L CCP_PWM_FULL_BRIDGE CCP_PWM_FULL_BRIDGE_REV CCP_PWM_HALF_BRIDGE 494 Built-in Functions CCP_SHUTDOWN_ON_COMP1 CCP_SHUTDOWN_ON_COMP2 CCP_SHUTDOWN_ON_COMP CCP_SHUTDOWN_ON_INTO CCP_SHUTDOWN_ON_COMP1_INTO CCP_SHUTDOWN_ON_COMP2_INTO CCP_SHUTDOWN_ON_COMP_INTO change Shutdown on Comparator 1 change Shutdown on Comparator 2 change Either Comparator 1 or 2 change VIL on INT pin VIL on INT pin or Comparator 1 change VIL on INT pin or Comparator 2 change VIL on INT pin or Comparator 1 or 2 CCP_SHUTDOWN_AC_L CCP_SHUTDOWN_AC_H CCP_SHUTDOWN_AC_F Drive pins A and C high Drive pins A and C low Drive pins A and D tri-state CCP_SHUTDOWN_BD_L CCP_SHUTDOWN_BD_H CCP_SHUTDOWN_BD_F Drive pins B and D high Drive pins B and D low Drive pins B and D tri-state CCP_SHUTDOWN_RESTART CCP_DELAY Device restart after a shutdown event Use the deadband delay pwm parameter - is an optional parameter for chips that includes ECCP module. This parameter allows setting the shutdown time. The value may be 0-255. mode and mode1 - constants used for setting up the CCP module. Valid constants are defined in the device's .h file; refer to the device's .h file for all options. Some typical options are as follows: [PCD] CCP_OFF CCP_COMPARE_INT_AND_TOGGLE CCP_COMPARE_FE CCP_COMPARE_RE CCP_COMPARE_DIV_4 CCP_COMPARE_DIV_16 CCP_COMPARE_SET_ON_MATCH CCP_COMPARE_CLR_ON_MATCH CCP_COMPARE_INT CCP_COMPARE_RESET_TIMER CCP_PWM mode2 is an optional parameter for setting up more settings of the CCP module. Valid constants are defined in the device's .h file, refer to the device's .h file for all options. [PCD] 495 Built-in Functions mode3 is an optional parameter for setting up more settings of the CCP module. Valid constants are defined in the device's .h file, refer to the device's .h file for all options. [PCD] pwm is an optional parameter for devices that have an ECCP module. this parameter allows setting the shutdown time. The value may be 0-255. [PCD] dead_time is an optional parameter for setting the dead time when the CCP module is operating in PWM mode with complementary outputs. The value may be 0-63, 0 is the default setting if not specified. [PCD] Returns: ----Function: Initialize the CCP. The CCP counters may be accessed using the long variables CCP_1 and CCP_2. The CCP operates in 3 modes. In capture mode it will copy the timer 1 count value to CCP_x when the input pin event occurs. In compare mode it will trigger an action when timer 1 and CCP_x are equal. In PWM mode it will generate a square wave. The PCW wizard will help to set the correct mode and timer settings for a particular application. Initializes the CCP module. For PIC24FxxKLxxx devices the CCP module can operate in three modes (Capture, Compare or PWM). Capture Mode - the value of Timer 3 is copied to the CCPRxH and CCPRxl registers when an input event occurs. [PCD] Compare Mode - will trigger an action when Timer 3 and the CCPRxL and CCPRxH registers are equal. PWM Mode - will generate a square wave, the duty cycle of the signal can be adjusted using the CCPRxL register and the DCxB bits of the CCPxCON register. The function set_pwmx_duty() is provided for setting the duty cycle when in PWM mode. PIC24FxxKMxxx devices, the CCP module can operate in four mode (Timer, Caputure, Compare or PWM). IN Timer mode, it functions as a timer. The module has to basic modes, it can functions as two independent 16-bit timers/counters or as a single 32-bit timer/counter. The mode it operates in is controlled by the option CCP_TIMER_32_BIT, with the previous options added, the module operates as a single 32-bit timer, and if not added, it operates as two 16-bit timers. The function set_timer_period_ccpx() is provided to set the period(s) of the timer, and the functions set_timer_ccpx() and get_timer_ccpx() are provided to set and get the current value of the timer(s). 496 Built-in Functions In Capture mode, the value of the timer is captured when an input event occurs, it can operate in either 16-bit or 32-bit mode. The functions get_capture_ccpx() and get_capture32_ccpx() are provided to get the last capture value. In Compare and PWM modes, the value of the timers is c ompared to one or two compare registers, depending on its mode of operation, to generate a single output transition or a train of output pulses. For signal output edge modes, CCP_COMPARE_SET_ON_MATCH, CCP_COMPARE_CLR_ON_MATCH, and CCP_COMPARE_TOGGLE, the module can operate in 16 or 32-bit mode, all other modes can only operate in 16-bit mode. However, when in 32-bit mode the timer source will only rollover when it reaches 0xFFFFFFFF or when reset from an external synchronization source. Therefore, is a period of less than 0xFFFFFFFF is needed, as it requires an external synchronization source to reset the timer. The functions set_ccpx_compare_time() and set_pwmx_duty() are provided for setting the compare registers. Availability: This function is only available on devices with CCP hardware. [PCD] Only on devices with the MCCP and/or SCCP modules. Requires: Constants are defined in the devices .h file. Examples: setup_ccp1(CCP_CAPTURE_RE); [PCD] setup_ccp1(CCP_CAPTURE_FE); setup_ccp1(CCP_COMPARE_TOGGLE); setup_ccp1(CCP_PWM); Example Files: ex_pwm.c, ex_ccpmp.c, ex_ccp1s.c See Also: set_pwmX_duty(), set_ccpX_compare_time(), set_timer_period_ccpX(), set_timer_ccpX(), get_timer_ccpX(), get_capture_ccpX(), get_captures32_ccpX() setup_clc1() setup_clc2() setup_clc3() setup_clc4() Syntax: setup_clc1(mode); setup_clc2(mode); setup_clc3(mode); setup_clc4(mode);_capture(x, mode) 497 Built-in Functions Parameters: mode – The mode to setup the Configurable Logic Cell (CLC) module into. See the device's .h file for all options. Some typical options include: CLC_ENABLED CLC_OUTPUT CLC_MODE_AND_OR CLC_MODE_OR_XOR Returns: ----Function: Sets up the CLC module to performed the specified logic. Please refer to the device datasheet to determine what each input to the CLC module does for the select logic function Availability: Devices with a CLC module Requires: ----Examples: setup_clc1(CLC_ENABLED | CLC_MODE_AND_OR); See Also: clcx_setup_gate(), clcx_setup_input() setup_comparator( ) Syntax: setup_comparator (mode) [PCD] setup_comparator (comparator, mode); [PCD] setup_comparator (comparator, mode, [blanking_period]); Parameters: mode is a constant. Valid constants are in the devices .h file refer to devices .h file for valid options. Some typical options are as follows: A0_A3_A1_A2 A0_A2_A1_A2 NC_NC_A1_A2 NC_NC_NC_NC 498 Built-in Functions A0_VR_A1_VR A3_VR_A2_VR A0_A2_A1_A2_OUT_ON_A3_A4 A3_A2_A1_A2 [PCD] comparator - constant specifying which comparator to setup. mode - constants specifying the settings to setup the specified comparator. See the device's .h file for all options. Some typical options include: CXINB_CXINA CXINC_CSINA CXIND_CXINA CXINB_VREF CXINC_VREF CXIND_VREF COMP_INVERT COMP_OUTPUT PCD] blanking_period - optional parameter available on devices with an Analog Comparator with Slope Compensation DAC peripheral. See the device's header file for availability. It sets the 10-bit blanking period for the comparator following changes to the DAC output during Change-of-State. [PCD] Returns: ----Function: Sets the analog comparator module. The above constants have four parts representing the inputs: C1-, C1+, C2-, C2+ Configures the voltage comparator. The voltage comparators allow to compare two voltages and find the greater of them. The configuration constants for this function specify the sources for the comparator in the order Cx- and Cx+. The results of the comparator modules are stored in CxOUT. COMP_INVERT will invert the result of the comparator and COMP_OUTPUT will output the result to the comparator output pin. [PCD] Availability: This function is only available on devices with an analog comparator. [PCD] Devices with a comparator module. Requires: Constants are defined in the devices .h file Examples: //Sets up two independent comparators (C1 and C2), 499 Built-in Functions // C1 uses A0 and A3 as inputs (- and +), and C2 // uses A1 and A2 as inputs setup_comparator(A0_A3_A1_A2); [PCD] setup_comparator(1,CXINB_CXINA); // setup C1 setup_comparator(2,CXINB_CXINA); // setup C2 Example Files: ex_comp.c See Also: Analog Comparator Overview, setup_comparator_filter(), setup_comparator_mask(), setup_comparator_dac(), setup_comparator_slope() setup_comparator_dac( ) [PCD] Syntax: [PCD] setup_comparator_dac(settings); [PCD] setup_comparator_dac(settings, [tmode_time], [ss_time]); Parameters: [PCD] settings - constants specifying the settings to setup the comparator and DAC. See the device's header file for defines that can be used with this parameter. tmode_time - optional 10-bit value used the set the Transition Mode Duration, value passed for this parameter should be less the ss-time parameter. [PCD] ss_time - optional 10-bit parameter used to set the time from Start of Transmission Mode until Steady-State filter is enabled. PCD] Returns: ----Function: [PCD] Used to setup the common settings for the Analog Comparator with Slope Compensation DAC peripheral. Some common settings include enabling/disabling the common DAC module, DAC clock source, comparator filter clock divider, etc. Availability: [PCD] Devices with the High-Speed Analog Comparator with the Slope Compensation DAC peripheral. See the device's header file to determine if the function is available. 500 Built-in Functions Requires: ----Examples: [PCD] setup_comparator_dac(COMP_COMMON_DAC_ENABLE | COMP_DAC_CLK_SRC_FPLLO, 85, 138); See Also: Analog Comparator Overview, setup_comparator(), setup_comparator_slope(), dac_write() setup_comparator_filter( ) Syntax: [PCD] setup_comparator (comparator, mode); Parameters: [PCD] comparator - constant specifying which comparator filter to setup. mode - constants specifying the settings to setup the specified comparator's filter. See the device's .h file for all options. Some typical options include: COMP_FILTER_ENABLE COMP_FILTER_CLK_T3 COMP_FILTER_CLK_T2 COMP_FILTER_CLK_FOSC COMP_FILTER_CLK_INTERNAL COMP_FILTER_CLK_DIV_BY_4 COMP_FILTER_CLK_DIV_BY_2 COMP_FILTER_CLK_DIV_BY_1 [PCD] Returns: ----Function: [PCD] Configures the voltage comparator's digital filter. Availability: [PCD] Devices with a comparator module that has a digital filter. See the device's header file to determine if the device has a digital filter as part of the comparator module. 501 Built-in Functions Requires: Constants are defined in the devices .h file Examples: [PCD] setup_comparator_filter(1,COMP_FILTER_ENABLE| COMP_FILTER_CLK_FOSC|COMP_FILTER_CLK_DIV_BY_4); See Also: Analog Comparator Overview, setup_comparator(), setup_comparator_mask() setup_comparator_mask( ) Syntax: [PCD] setup_comparator_mask (comparator, mode, [input1], [input2], [input3]); Parameters: [PCD] comparator - constant specifying which comparator filter to setup. mode - constants specifying the settings to setup the specified comparator's mask registers. See the device's .h file for all options. Some typical options include: COMP_MASK_COMP_HIGH COMP_MASK_COMP_LOW COMP_MASK_MAI_CONNECTED_TO_OR COMP_MASK_INVERTED_MAI_CONNECTED_TO_OR COMP_MASK_MAI_CONNECTED_TO_AND COMP_MASK_INVERTED_MAI_CONNECTED_TO_AND [PCD] input1, input2, input3 - optional parameters specifying the inputs to mask. See the device's .h file for all options. Some typical options include: COMP_MASK_INPUT_PWM3H COMP_MASK_INPUT_PWM3L COMP_MASK_INPUT_PWM2H COMP_MASK_INPUT_PWM2L COMP_MASK_INPUT_PWM1H COMP_MASK_INPUT_PWM1L [PCD] Returns: ----Function: [PCD] Configures the voltage comparator's output blanking function. 502 Built-in Functions Availability: [PCD] Devices with a comparator module that has a output blanking function. See the device's header file to determine if the device has an output blanking function as part of the comparator module. Requires: Constants are defined in the devices .h file Examples: setup_comparator_mask(1,COMP_MASK_COMP_LOW| COMP_MASK_MAI_CONNECTED_TO_AND, COMP_MASK_INPUT_PWM1H; [PCD] See Also: Analog Comparator Overview, setup_comparator(), setup_comparator_filter() [PCD] setup_comparator_slope( ) Syntax: [PCD] setup_comparator_slope(comparator, settings, rate); Parameters: PCD] comparator - constant specifying which comparator to setup. settings - constants specifying the settings to setup the comparator and DAC. See the device's header file for defines that can be used with this parameter. [PCD] [PCD] rate - 16-bit value used to set slope ramp rate, the value is in 12.4 format. Returns: ----Function: [PCD] Used to setup the Analog Comparator with Slope Compensation DAC peripheral slope settings. Availability: [PCD] Devices with the High-Speed Analog Comparator with the Slope Compensation DAC peripheral. See the device's header file to determine if the function is available. Requires: ----- 503 Built-in Functions Examples: setup_comparator_slope(1,COMP_ENABLE_SLOPE_FUNCTION | COMP_SLOPE_START_SIG_PWM1_TRIG_1 | COMP_SLOPE_STOP_B_SIG_COMP1 | COMP_SLOPE_STOP_A_SIG_PWM1_TRIG_1, 500000); [PCD] See Also: Analog Comparator Overview, setup_comparator(), setup_comparator_dac(), dac_write() setup_comparator_x( ) Syntax: setup_comparator_1(mode); setup_comparator_2(mode); setup_comparator_3(mode); setup_comparator_4(mode); setup_comparator_5(mode); setup_comparator_6(mode); setup_comparator_7(mode); setup_comparator_8(mode); Parameters: mode - to setup the comparator in. Valid options are device dependent. See the device's header file for all valid options. Returns: ----Function: Used to setup one of the Analog Comparator modules. Availability: On most devices that have more than three Analog Comparator modules. Requires: ----Examples: setup_comparator_1(CP1_A1_A0 | CP1_INVERT); 504 Built-in Functions See Also: setup_comparator( ), Analog Comparator setup_compare( ) Syntax: setup_compare(x, mode) Parameters: mode - is defined by the constants in the devices .h file x - is 1-16 and specifies which OC pin to use. Returns: ----Function: This function specifies how the output compare module is going to function based on the value of mode. The device specific options are listed in the device .h file. Availability: Available only on devices with Output Compare Modules Requires: ----Examples: // Pin OC1 will be set when timer 2 // is equal to 0xF000 setup_timer2(TMR_INTERNAL | TIMER_DIV_BY_16); set_compare_time(1, 0xF000); setup_compare(1, COMPARE_SET_ON_MATCH | COMPARE_TIMER2); See Also: set_compare_time(), set_pwm_duty(), setup_capture(), Output Compare / PWM Overview setup_counters( ) Syntax: setup_counters (rtcc_state, ps_state) 505 Built-in Functions Parameters: rtcc_state - may be one of the constants defined in the devices .h file. RTCC_INTERNAL RTCC_EXT_L_TO_H RTCC_EXT_H_TO_L ps_state - may be one of the constants defined in the devices .h file. RTCC_DIV_2 RTCC_DIV_4 RTCC_DIV_8 RTCC_DIV_16 RTCC_DIV_32 RTCC_DIV_64 RTCC_DIV_128 RTCC_DIV_256 WDT_18MS WDT_36MS WDT_72MS WDT_144MS WDT_288MS WDT_576MS WDT_1152MS WDT_2304MS Returns: ----Function: Sets up the RTCC or WDT. The rtcc_state determines what drives the RTCC. The PS state sets a prescaler for either the RTCC or WDT. The prescaler will lengthen the cycle of the indicated counter. If the RTCC prescaler is set the WDT will be set to WDT_18MS. If the WDT prescaler is set the RTCC is set to RTCC_DIV_1. This function is provided for compatibility with older versions. setup_timer_0 and setup_WDT are the recommended replacements when possible. For PCB devices if an external RTCC clock is used and a WDT prescaler is used then this function must be used. Availability: All Devices Requires: Constants are defined in the devices .h file 506 Built-in Functions Examples: setup_counters (RTCC_INTERNAL, WDT_2304MS); See Also: setup wdt(), setup_timer 0(), see header file for device selected setup_crc(mode) Syntax: setup_crc(polynomial terms) Parameters: polynomial - This will setup the actual polynomial in the CRC engine. The power of each term is passed separated by a comma. 0 is allowed, but ignored. The following define is added to the device's header file (32-bit CRC Moduel Only), to enable little-endian shift direction: CRC_LITTLE_ENDIAN Returns: ----Function: Configures the CRC engine register with the polynomial. Availability: Devices with built in CRC module Requires: ----Examples: setup_crc (12, 5); setup_crc(16, 15, 3, 1); X1+ 1 // CRC Polynomial is X12 + X5 + 1 // CRC Polynomial is X16 + X15 + X3 + Example Files: ex.c See Also: crc_init(); crc_calc(); crc_calc8() 507 Built-in Functions setup_cog( )setup_cog2( ) setup_cog3( ) setup_cog4( ) Syntax: setup_cog(mode, [shutdown]); setup_cog(mode, [shutdown], [sterring]); Parameters: mode- the setup of the COG module. See the device's .h file for all options. Some typical options include: COG_ENABLED COG_DISABLED COG_CLOCK_HFINTOSC COG_CLOCK_FOSC shutdown- the setup for the auto-shutdown feature of COG module. See the device's .h file for all the options. Some typical options include: COG_AUTO_RESTART COG_SHUTDOWN_ON_C1OUT COG_SHUTDOWN_ON_C2OUT steering- optional parameter for steering the PWM signal to COG output pins and/or selecting the COG pins static level. Used when COG is set for steered PWM or synchronous steered PWM modes. Not available on all devices, see the device's .h file if available and for all options. Some typical options include: COG_PULSE_STEERING_A COG_PULSE_STEERING_B COG_PULSE_STEERING_C COG_PULSE_STEERING_D Returns: ----Function: Sets up the Complementary Output Generator (COG) module, the auto-shutdown feature of the module and if available steers the signal to the different output pins. Availability: Devices with built in COG module Requires: ----- 508 Built-in Functions Examples: setup_cog(COG_ENABLED | COG_PWM | COG_FALLING_SOURCE_PWM3 | COG_RISING_SOURCE_PWM3, COG_NO_AUTO_SHUTDOWN, COG_PULSE_STEERING_A | COG_PULSE_STEERING_B); See Also: set_cog_dead_band(), set_cog_phase(), set_cog_blanking(), cog_status(), cog_restart() setup_cwg( ) setup_cwg2( ) setup_cwg3( ) Syntax: setup_cwg(mode,shutdown,dead_time_rising,dead_time_falling) Parameters: mode - the setup of the CWG module. See the device's .h file for all options. Some typical options include: CWG_ENABLED CWG_DISABLED CWG_OUTPUT_B CWG_OUTPUT_A shutdown - the setup for the auto-shutdown feature of CWG module. See the device's .h file for all the options. Some typical options include: CWG_AUTO_RESTART CWG_SHUTDOWN_ON)COMP1 CWG_SHUTDOWN_ON_FLT CWG_SHUTDOWN_ON_CLC2 dead_time_rising - value specifying the dead time between A and B on the rising edge. (0-63) dead_time_rising - value specifying the dead time between A and B on the falling edge. (0-63) Returns: ----Function: Sets up the CWG module, the auto-shutdown feature of module and the rising and falling dead times of the module. Availability: Devices with built in CWG module 509 Built-in Functions Requires: ----Examples: setup_cwg(CWG_ENABLED|CWG_OUTPUT_A|CWG_OUTPUT_B|CWG_INPUT_PWM1,CWG_SHUTDOWN_ON_F LT,60,30); See Also: cwg_status( ), cwg_restart( ) [PCD] setup_current_source() Syntax: setup_current_source(mode); Parameters: mode - setup the Constant Current Source module. Valid options are device dependent. See the device's header file for all options. Returns: ----Function: Used to setup the Constant Current Source module. Availability: Devices that have a Constant Current Source module. Requires: -----Examples: setup_current_source(CURRENT_SOURCE_ENABLED | CURRENT_SOURCE_D5); setup_dac( ) Syntax: setup_dac(mode); setup_dac2(mode); setup_dac3(mode); 510 Built-in Functions setup_dac4(mode); setup_dac5(mode); setup_dac6(mode); setup_dac7(mode); setup_dac8(mode); [PCD] setup_dac(mode, divisor); [PCD] setup_dac(module, mode); Parameters: mode - The mode to setup the DAC module in. The valid options vary depending on the device. See the device's header file for all options. [PCD] divisor - Divides the provided clock. [PCD] module - DAC module setup. Returns: ----Function: Setup the DAC module. Availability: Devices with a digital-to-analog converter (DAC). Requires: ----Examples: setup_dac(DAC_VSS_VDD | DAC_OUTPUT); [PCD] setup_dac(DAC_RIGHT_ON, 5); setup_dac(1, DAC_ON) See Also: dac_write, DAC. See header file for selected device. setup_dci( ) Syntax: setup_dci(configuration, data size, rx config, tx config, sample rate); 511 Built-in Functions Parameters: configuration - Specifies the configuration the Data Converter Interface should be initialized into, including the mode of transmission and bus properties. The following constants may be combined ( OR’d) for this parameter: CODEC_MULTICHANNEL CODEC_I2S· CODEC_AC16 CODEC_AC20· JUSTIFY_DATA· DCI_MASTER DCI_SLAVE· TRISTATE_BUS· MULTI_DEVICE_BUS SAMPLE_FALLING_EDGE· SAMPLE_RISING_EDGE DCI_CLOCK_INPUT· DCI_CLOCK_OUTPUT data size – Specifies the size of frames and words in the transmission: DCI_xBIT_WORD: x may be 4 through 16 DCI_xWORD_FRAME: x may be 1 through 16 DCI_xWORD_INTERRUPT: x may be 1 through 4 rx config- Specifies which words of a given frame the DCI module will receive (commonly used for a multi-channel, shared bus situation) RECEIVE_SLOTx: x May be 0 through 15 RECEIVE_ALL· RECEIVE_NONE tx config- Specifies which words of a given frame the DCI module will transmit on. TRANSMIT_SLOTx: x May be 0 through 15 TRANSMIT _ALL TRANSMIT _NONE sample rate - The desired number of frames per second that the DCI module should produce. Use a numeric value for this parameter. Keep in mind that not all rates are achievable with a given clock. Consult the device datasheet for more information on selecting an adequate clock. Returns: ----Function: Configures the DCI module. Availability: Only available on devices with DCI peripheral. Requires: Constants are defined in the devices .h file 512 Built-in Functions Examples: dci_initialize((I2S_MODE|DCI_MASTER|DCI_CLOCK_OUTPUT|SAMPLE_RISING_EDGE|UNDERFLO W_LAST| MULTI_DEVICE_BUS,DCI_1WORD_FRAME|DCI_16BIT_WORD|DCI_2WORD_INTERR UPT, RECEIVE_SLOT0|RECEIVE_SLOT1, TRANSMIT_SLOT0|TRANSMIT_SLOT1, 44100 ); See Also: DCI Overview, dci start( ), dci write( ), dci read( ), dci transmit ready( ), dci data received() setup_dedicated_adc( ) Syntax: setup_dedicated_adc(core, mode); Parameters: core - the dedicated ADC core to setup mode - the mode to setup the dedicated ADC core in. See the device's .h file all options. Some typical options include: ADC_DEDICATED_CLOCK_DIV_2 ADC_DEDICATED_CLOCK_DIV_6 ADC_DEDICATED_TAD_MUL_2 ADC_DEDICATED_TAD_MUL_3 Returns: ----Function: Configures one of the dedicated ADC core's clock speed and sample time. Function should be called after the setup_adc() function. Availability: Only available on dsPIC33EPxxGSxxx family of devices. Requires: Constants are defined in the devices .h file Examples: setup_dedicated_adc(0,ADC_DEDICATED_CLOCK_DIV_2|ADC_DEDICATED_TA D_MUL_1025) 513 Built-in Functions See Also: setup_adc(), setup_adc_ports(), set_adc_channel(), read_adc(), adc_done(), set_dedicated_adc_channel(), ADC Overview setup_dma( ) Syntax: setup_dma(channel, start_trigger, abort_trigger); [PCD] setup_dma(channel, peripheral,mode); [PCD] setup_dma(channel, trigger, mode); Parameters: channel -The DMA channel to setup. start_trigger - The trigger source to cause the DMA channel to start the transfer when HW trigger is enabled. See header file for all possible sources. abort_trigger - The trigger source to cause the DMA channel to abort the transfer when HW abort trigger is enabled. See header file for all possible sources. peripheral - The peripheral that the DMA channel transfers data to and from. Constants for setting the trigger source are defined in the device's .h file, see header file for all possible peripherals. [PCD] trigger - The trigger source to cause the DMA channel to start the transfer. Constants for setting the trigger source are defined in the device's header file, see header file for all possible sources. [PCD] mode - The mode to use for the DMA transfers. Constants for setting the mode are defined in the device's header file, see header file for all possible options. [PCD] Returns: ----Function: Configures the DMA peripheral to copy data from one location to another. Availability: Devices that have a DMA peripheral. [PCD] The version of the function depends on the type of DMA peripheral it has. Use getenv("DMA") to determine the type the device has. It will return 0 for no DMA peripheral, 1 for Type 1 and 2 for Type 2. For devices with 514 Built-in Functions Type 1 uses first version of the function and for devices with Type 2 uses second version of the function. Requires: ----Examples: [PCD] setup_dma(0,DMA_IN_UART1,DMA_BYTE); setup_dma(0,DMA_TRIGGER_RDA,DMA_BYTE| DMA_RELOAD_ADDRESS); // Type 1 // Type 2 setup_dma(1, DMA_TRIGGER_RDA, DMA_TRIGGER_NONE); Example Files: ex_dma_uart_rx.c See Also: dma_start(), dma_status() setup_dmt( ) Syntax: setup_dmt(mode, max_time, window_time); Parameters: mode - This sets if whether the DMT is always enabled or can be enabled and disabled in software. The following defines are made in the device's header file for setting the following: DMT_SOFTWARE // DMT can be enabled and disabled in software. DMT_ENABLED // DMT is ways enabled. max_time - A 32-bit constant value for setting the count that causes a DMT event to occur. window_time - A 32-bit constant value for setting the count value at which it is possible to clear the DMT count value. Returns: ----- 515 Built-in Functions Function: Sets up the Deadman Timer (DMT) peripheral. This function does not generate any assembly code, it only causes the DMT configuration fuses to be set to the specified values. Availability: Only on devices that have the DMT peripheral. Requires: ----Examples: //Setup DMT peripheral to be enabled and disabled in software //with a max count of 50000 and can be cleared after count //reaches 10000. setup_dmt(DMT_SOFTWARE, 50000, 10000); See Also: clear_dmt(), read_dmt(), disable_dmt(), enable_dmt(), dmt_status() setup_dsm() Syntax: setup_dsm(enable); setup_dsm2(enable); setup_dsm3(enable); setup_dsm4(enable); setup_dsm(mode, source, carrier); setup_dsm2(mode, source, carrier); setup_dsm3(mode, source, carrier); setup_dsm4(mode, source, carrier); Parameters: enable – a 1-bit constant used to enable and disable the DSM module. If 1 is passed as the parameter, the DSMx module is enabled, and if 0 is passed as the parameter, the DSM module is disabled. mode - the mode to setup the DSM module. Valid options vary by device. See the device's header file for all options. source - used to set the signal source for the DSM module. Valid options vary by device. See the device's header file for all options. 516 Built-in Functions carrier - used to set the high and low level carriers for the DSM module. Valid options vary by device. See the device's header file for all options. Returns: ----Function: Used to setup the DSM module. Availability: Devices that have a Data Signal Modulator (DSM) module Requires: -----Examples: setup_dsm(DSM_ENABLED, DSM_SOURCE_U1TX, DSM_CARRIER_LOW_CCP1 | DSM_CARRIER_HIGH_CCP2); See Also: Data Signal Modulator Overview setup_external_memory( ) Syntax: setup_external_memory(mode); Parameters: mode - is one or more constants from the device header file OR'ed together. Returns: ----Function: Sets the mode of the external memory bus. Availability: Devices that allow external memory bus. Requires: Constants are defined in the devices .h file 517 Built-in Functions Examples: setup_external_memory(EXTMEM_WORD_WRITE|EXTMEM_WAIT_0 ); setup_external_memory(EXTMEM_DISABLE); See Also: WRITE PROGRAM EEPROM() , WRITE PROGRAM MEMORY(), External Memory Overview setup_high_speed_adc( ) Syntax: setup_external_memory(mode); Parameters: mode - Analog to digital mode. The valid options vary depending on the device. See the devices .h file for all options. Some typical options include: ADC_OFF ADC_CLOCK_DIV_1 ADC_HALT_IDLE (The ADC will not run when device is idle) Returns: ----Function: Configures the High-Speed ADC clock speed and other High-Speed ADC options including, when the ADC interrupts occurs, the output result format, the conversion order, whether the ADC pair is sampled sequentially or simultaneously, and whether the dedicated sample and hold is continuously sampled or samples when a trigger event occurs. Availability: dsPIC33FJxxGSxxx devices Requires: Constants are defined in the devices .h file Examples: setup_high_speed_adc_pair(0, INDIVIDUAL_SOFTWARE_TRIGGER); setup_high_speed_adc(ADC_CLOCK_DIV_4); read_high_speed_adc(0, START_AND_READ, result); setup_high_speed_adc(ADC_OFF); 518 Built-in Functions See Also: setup_high_speed_adc_pair(), read_high_speed_adc(), high_speed_adc_done() setup_high_speed_adc_pair( ) Syntax: setup_high_speed_adc_pair(pair, mode); Parameters: pair – The High-Speed ADC pair number to setup, valid values are 0 to total number of ADC pairs. 0 sets up ADC pair AN0 and AN1, 1 sets up ADC pair AN2 and AN3, etc. mode – ADC pair mode. The valid options vary depending on the device. See the devices .h file for all options. Some typical options include: INDIVIDUAL_SOFTWARE_TRIGGER GLOBAL_SOFTWARE_TRIGGER PWM_PRIMARY_SE_TRIGGER PWM_GEN1_PRIMARY_TRIGGER PWM_GEN2_PRIMARY_TRIGGER Returns: ----Function: Sets up the analog pins and trigger source for the specified ADC pair. Also sets up whether ADC conversion for the specified pair triggers the common ADC interrupt. If zero is passed for the second parameter the corresponding analog pins will be set to digital pins. Availability: dsPIC33FJxxGSxxx devices Requires: Constants are defined in the devices .h file Examples: setup_high_speed_adc_pair(0,INDIVIDUAL_SOFTWARE_TRIGGER); setup_high_speed_adc_pair(1,GLOBAL_SOFTWARE_TRIGGER); setup_high_speed_adc_pair(2,0) //sets AN4 and AN5 as digital pins 519 Built-in Functions See Also: setup_high_speed_adc(), read_high_speed_adc(), high_speed_adc_done() setup_hspwm( ) setup_hspwm_secondary( ) Syntax: setup_hspwm(mode, value); setup_hspwm_secondary(mode, value); //if available Parameters: mode - Mode to setup the High Speed PWM module in. The valid options vary depending on the device. See the device's .h file for all options. Some typical options include: HSPWM_ENABLED HSPWM_HALT_WHEN_IDLE HSPWM_CLOCK_DIV_1 value - 16-bit constant or variable to specify the time bases period. Returns: ----Function: Enable the High Speed PWM module and set up the Primary and Secondary Time base of the module. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: Constants are defined in the device's .h file Examples: setup_hspwm(HSPWM_ENABLED | HSPWM_CLOCK_DIV_BY4, 0x8000); See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock(), setup_hspwm_secondary() 520 Built-in Functions setup_hspwm_blanking( ) Syntax: setup_hspwm_blanking(unit, settings, delay); Parameters: unit - The High Speed PWM unit to set. settings - Settings to setup the High Speed PWM Leading-Edge Blanking. The valid options vary depending on the device. See the device's header file for all options. Some typical options include: HSPWM_RE_PWMH_TRIGGERS_LE_BLANKING HSPWM_FE_PWMH_TRIGGERS_LE_BLANKING HSPWM_RE_PWML_TRIGGERS_LE_BLANKING HSPWM_FE_PWML_TRIGGERS_LE_BLANKING HSPWM_LE_BLANKING_APPLIED_TO_FAULT_INPUT HSPWM_LE_BLANKING_APPLIED_TO_CURRENT_LIMIT_INPUT delay - 16-bit constant or variable to specify the leading-edge blanking time. Returns: ----Function: Sets up the analog pins and trigger source for the specified ADC pair. Also sets up whether ADC conversion for the specified pair triggers the common ADC interrupt. If zero is passed for the second parameter the corresponding analog pins will be set to digital pins. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: ----Examples: setup_hspwm_blanking(HSPWM_RE_PWMH_TRIGGERS_LE_BLANKING, 10); 521 Built-in Functions See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock() setup_hspwm(), setup_hspwm_secondary(), setup_high_speed_adc(), read_high_speed_adc(), high_speed_adc_done() setup_hspwm_chop_clock( ) Syntax: setup_hspwm_chop_clock(settings); Parameters: unit - The High Speed PWM unit to set. settings - a value from 1 to 1024 to set the chop clock divider. Also one of the following can be or'd with the value: HSPWM_CHOP_CLK_GENERATOR_ENABLED HSPWM_CHOP_CLK_GENERATOR_DISABLED Returns: ----Function: Setup and High Speed PWM Chop Clock Generator and divisor. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: ----Examples: setup_hspwm_chop_clock(HSPWM_CHOP_CLK_GENERATOR_ENABLED|32); See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_unit_chop_clock(), setup_hspwm(), setup_hspwm_secondary() 522 Built-in Functions setup_hspwm_current_limit( ) Syntax: setup_hspwm_current_limit(unit, settings); Parameters: unit - The High-Speed PWM unit to setup. settings - An int32 value to setup the PWM Generator Current Limit PCI registers. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Current Limit PCI registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_current_limit(1, HSPWM_PCI_SRC_MASTER_PCI10 | HSPWM_ACCEPTANCE_QUALIFIER_PWM_TRIGGERED | HSPWM_TERMINATION_QUALIFIER_DUTY_CYCLE | HSPWM_PCI_ACCEPTANCE_LATCHED_ANY_EDGE); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() 523 Built-in Functions setup_hspwm_event( ) Syntax: setup_hspwm_event(unit, settings_1, settings_h); Parameters: unit - The High-Speed PWM unit to setup. settings_1 - An int16 constant value to setup the PWM Generator Event low register settings. See the device's header file for valid defines that can be used with function. settings_h - An int16 constant value to setup the PWM Generator Event high register settings. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Event registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_EVENT(3, HSPWM_EVENT_TRIGGER_EOC | HSPWM_EVENT_UPDATE_WRITE_TO_DUTY_CYCLE | HSPWM_EVENT_ADC_TRIGGER_1_PGxTRIGB_SRC_ENABLED | 30, HSPWM_EVENT_INTERRUPT_DISABLED | HSPWM_EVENT_FEED_FORWARD_INTERRUPT_ENABLED | 10); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_fault(), setup_hspwm_current_limit(),setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() 524 Built-in Functions setup_hspwm_fault( ) Syntax: setup_hspwm_fault(unit, settings); Parameters: unit - The High-Speed PWM unit to setup. settings - An int32 value to setup the PWM Generator Fault PCI registers. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Fault PCI registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_fault(1, HSPWM_PCI_SRC_MASTER_PCI10 | HSPWM_ACCEPTANCE_QUALIFIER_PWM_TRIGGERED | HSPWM_TERMINATION_QUALIFIER_DUTY_CYCLE | HSPWM_PCI_ACCEPTANCE_LATCHED_ANY_EDGE); See Also: setup_hspwm(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() setup_hspwm_feed_forward( ) Syntax: setup_hspwm_feed_forward(unit, settings); 525 Built-in Functions Parameters: unit - The High-Speed PWM unit to setup. settings - An int32 value to setup the PWM Generator Feed Forward PCI registers. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Feed Forward PCI registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_feed_forward(1, HSPWM_PCI_SRC_MASTER_PCI10 | HSPWM_ACCEPTANCE_QUALIFIER_PWM_TRIGGERED | HSPWM_TERMINATION_QUALIFIER_DUTY_CYCLE | HSPWM_PCI_ACCEPTANCE_LATCHED_ANY_EDGE); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() setup_hspwm_logic_x( ) Syntax: setup_hspwm_logic_a(settings); setup_hspwm_logic_b(settings); 526 Built-in Functions setup_hspwm_logic_c(settings); setup_hspwm_logic_d(settings); setup_hspwm_logic_e(settings); setup_hspwm_logic_f(settings); Parameters: settings - An int16 value to setup the PWM Logic control to. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Logic control registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_logic_a(HSPWM_LOGIC_SRC1_PWM1H | HSPWM_LOGIC_SRC2_PWM4H | HSPWM_LOGIC_SRC1_OR_SRC2 | HSPWM_LOGIC_ASSIGNED_TO_PWM2); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(),setup_hspwm_feed_forward(), setup_hspwn_sync(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update() setup_hspwm_sync( ) Syntax: setup_hspwm_sync(unit, settings); Parameters: unit - The High-Speed PWM unit to setup. 527 Built-in Functions settings - An int32 value to setup the PWM Generator Sync PCI registers. See the device's header file for valid defines that can be used with function. Returns: ----Function: To setup the High-Speed PWM (HSPWM) Sync PCI registers. Availability: On devices that have the HSPWM peripheral with Fine Edge Placement. See the device's header file to determine if functions are available. Requires: ----Examples: setup_hswm_sync(1, HSPWM_PCI_SRC_MASTER_PCI10 | HSPWM_ACCEPTANCE_QUALIFIER_PWM_RIGGERED | HSPWM_TERMINATION_QUALIFIER_DUTY_CYCLE | HSPWM_PCI_ACCEPTANCE_LATCHED_ANY_EDGE); See Also: setup_hspwm(), setup_hspwm_event_output_x(), setup_hspwm_logic_x(), setup_hspwm_unit(), setup_hspwm_blanking(), setup_hspwm_event(), setup_hspwm_fault(), setup_hspwm_current_limit(), setup_hspwm_feed_forward(), set_hspwm_scaling(), set_hspwm_overrride(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_period(), set_hspwm_duty_adjustment(), set_hspwm_trigger_x(), get_hspwm_feedback(), get_hspwm_capture(), get_hspwm_status(), hspwm_trigger_pwm(), hspwm_stop_pwm(), hspwm_do_capture(), hspwm_update(), setup_hspwm_trigger( ) Syntax: setup_hspwm_trigger(unit, [start_ delay], [divider], [trigger_value], [strigger_value]); Parameters: unit - The High Speed PWM unit to set. start_delay - Optional value from 0 to 63 specifying then umber of PWM cycles to wait before generating the first trigger event. For some devices, one of the following may be optional or'd in with the value: 528 Built-in Functions HSPWM_COMBINE_PRIMARY_AND_SECONDARY_TRIGGER HSPWM_SEPERATE_PRIMARY_AND_SECONDARY_TRIGGER divider - optional value from 1 to 16 specifying the trigger event divisor. trigger_value - optional 16-bit value specifying the primary trigger compare time. strigger_value - optional 16-bit value specifying the secondary trigger compare time. Returns: ----Function: Sets up the High Speed PWM Trigger event. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: ----Examples: setup_hspwm_trigger(1, 10, 1, 0x2000); See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock(), setup_hspwm(), setup_hspwm_secondary() setup_hspwm_unit( ) Syntax: setup_hspwm_unit(unit, mode, [dead_time], [alt_dead_time]); set_hspwm_duty(unit, primary, [secondary]); Parameters: unit - The High Speed PWM unit to set. mode - Mode to setup the High Speed PWM unit in. The valid option vary depending on the device. See the device's header file for all options. Some typical options include: HSPWM_ENABLE 529 Built-in Functions HSPWM_ENABLE_H HSPWM_ENABLE_L HSPWM_COMPLEMENTARY HSPWM_PUSH_PULL dead_time - Optional 16-bit constant or variable to specify the dead time for this PWM unit, defaults to 0 if not specified. alt_dead_time - Optional 16-bit constant or variable to specify the alternate dead time for this PWM unit, default to 0 if not specified. Returns: ----Function: Sets up the specified High Speed PWM unit. Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: Constants are defined in the device's .h file Examples: setup_hspwm_unit(1,HSPWM_ENABLE|SHPWM_COMPLEMENTARY, 100,100); See Also: set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock(), setup_hspwm(), setup_hspwm_secondary() setup_hspwm_unit_chop_clock( ) Syntax: setup_hspwm_unit_chop_clock(unit, settings); Parameters: unit - the High Speed PWM unit chop clock to setup. 530 Built-in Functions settings - a settings to setup the High Speed PWM unit chop clock. The valid options vary depending on the device. See the device's .h file for all options. Some typical options include: HSPWM_PWMH_CHOPPING_ENABLED HSPWM_PWML_CHOPPING_ENABLED HSPWM_CHOPPING_DISABLED HSPWM_CLOP_CLK_SOURCE_PWM2H HSPWM_CLOP_CLK_SOURCE_PWM1H HSPWM_CHOP_CLK_SOURCE_CHOP_CLK_GENERATOR Returns: ----Function: Setup and High Speed PWM unit's Chop Clock Availability: Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx, dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices) Requires: Constants are defined in the device's .h file Examples: setup_hspwm_unit_chop_clock(1,HSPWM_PWMH_CHOPPING_ENABLED| HSPWM_PWML_CHOPPIJNG_ENABLED| HSPWM_CLOP_CLK_SOURCE_PWM2H); See Also: setup_hspwm_unit(), set_hspwm_phase(), set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(), setup_hspwm_trigger(), set_hspwm_override(), get_hspwm_capture(), setup_hspwm_chop_clock(), setup_hspwm(), setup_hspwm_secondary() setup_lcd( ) Syntax: setup_lcd (mode, prescale, [segments0_31],[segments32_47]); Parameters: mode - may be any of the following constants to enable the LCD and may be or'ed with other constants in the devices *.h file: LCD_DISABLED, LCD_STATIC, LCD_MUX12, LCD_MUX13, LCD_MUX14 531 Built-in Functions prescale - may be 1-16 for the LCD clock. segments0-31 - may be any of the following constants or'ed together when using the PIC16C92X series of chips:: SEG0_4, SEG5_8, SEG9_11, SEG12_15, SEG16_19, SEG20_26, SEG27_28, SEG29_31 ALL_LCD_PINS When using the PIC16F/LF1xxx or PIC18F/LFxxxx series of chips, each of the segments are enabled individually. A value of 1 will enable the segment, 0 will disable it and use the pin for normal I/O operation. segments 32-47 - when using a chip with more than 32 segments, this enables segments 32-47. A value 1 will enable the segment, 0 will disable it. Bit 0 corresponds to segment 32 and bit 15 corresponds to segment 47. Returns: ----Function: Initialize the LCD Driver Module on the PIC16C92X and PIC16F/LF193X series of devices. Availability: Only on devices with built-in LCD Driver Module hardware. Requires: Constants are defined in the devices .h file Examples: setup_lcd(LCD_MUX14|LCD_STOP_ON_SLEEP,2,ALL_LCD_PINS); // PIC16C92X setup_lcd(LCD_MUX13|LCD_REF_ENABLED|LCD_B_HIGH_POWER,0,0xFF0429) ; // PIC16F/LF193X – //Enables Segments //0,3,5,10,16,17,18, 19,20,21,22,23 Example Files: ex_92lcd.c See Also: lcd_symbol(), lcd_load(), lcd_contrast( ), Internal LCD Overview 532 Built-in Functions setup_low_volt_detect( ) Syntax: setup_low_volt_detect(mode) Parameters: mode may be one of the constants defined in the devices .h file. LVD_LVDIN LVD_45 LVD_42 LVD_40 LVD_38 LVD_36 LVD_35 LVD_33 LVD_30 LVD_28 LVD_27 LVD_25 LVD_23 LVD_21 LVD_19 One of the following may be or’ed(via |) with the above if high voltage detect is also available in the device LVD_TRIGGER_BELOW LVD_TRIGGER_ABOVE Returns: ----Function: This function controls the high/low voltage detect module in the device. The mode constants specifies the voltage trip point and a direction of change from that point (available only if high voltage detect module is included in the device). If the device experiences a change past the trip point in the specified direction the interrupt flag is set and if the interrupt is enabled the execution branches to the interrupt service routine. Availability: Only available with devices that have the high/low voltage detect module. Requires: Constants are defined in the devices .h file 533 Built-in Functions Examples: setup_low_volt_detect( LVD_TRIGGER_BELOW | LVD_36 ); would trigger the //This //interrupt when the voltage //is below 3.6 volts setup_motor_pwm( ) Syntax: setup_motor_pwm(pwm,options, timebase); setup_motor_pwm(pwm,options,prescale,postscale,timebase) Parameters: pwm - Defines the pwm module used. Options - The mode of the power PWM module. See the devices .h file for all options timebase - This parameter sets up the PWM time base pre-scale and post-scale. prescale - This will select the PWM timebase prescale setting postscale - This will select the PWM timebase postscale setting Returns: ----Function: Configures the motor control PWM module. Availability: Devices that have the motor control PWM unit. Requires: ----Examples: setup_motor_pwm(1,MPWM_FREE_RUN | MPWM_SYNC_OVERRIDES, timebase); See Also: get motor pwm count(), set motor pwm event(), set motor unit(), set motor pwm duty() 534 Built-in Functions setup_msi( ) Syntax: setup_msi(settings); Parameters: settings - Setting to setup the MSI peripheral in. The available options depend on whether the program is for the Master or Slave core of the device. See the device's header file for valid defines that can be used with the function. Returns: ----Function: Sets up the Master Slave Interface (MSI). Availability: Only available on Dual Core devices. Requires: ----Examples: //Setup MSI to enable the Slave PIC, interrupt when 1st write to //FIFO is done by other core, enable write FIFO and enable read FIFO. setup_msi(MSI_SLAVE_ENABLE | MSI_FIFO_DATA_VALID_INT_ON_1ST_WRITE | MSI_WRITE_FIFO_ENABLED | MSI_READ_FIFO_ENABLED); See Also: msi_write_mailbox(), msi_read_mailbox(), msi_status(), msi_read_fifo(), msi_mailbox_status(),msi_write_fifo(), msi_fifo_status() setup_nco( ) Syntax: setup_nco(settings,inc_value) Parameters: settings - setup of the NCO module. See the device's .h file for all options. Some typical options include: NCO_ENABLE NCO_OUTPUT NCO_PULSE_FREQ_MODE NCO_FIXED_DUTY_MODE 535 Built-in Functions inc_value - value to increment the NCO 20 bit accumulator by. Returns: ----Function: Sets up the NCO module and sets the value to increment the 20-bit accumulator by. Availability: Devices with a NCO module. Requires: ----Examples: setup_nco(NCO_ENABLED|NCO_OUTPUT|NCO_FIXED_DUTY_MODE|NCO_CLOCK_F OSC,8192); See Also: get_nco_accumulator( ), set_nco_inc_value( ), get_nco_inc_value( ) setup_opamp1( ) setup_opamp2( ) setup_opamp3( ) setup_opamp4( ) Syntax: setup_opamp1(mode) setup_opamp2(mode) setup_opamp3(mode) setup_opamp4(mode) Parameters: mode - The mode of the operation amplifier. See the devices .h file for all options. Some typical options include: OPAMP_ENABLED OPAMP_DISABLED Returns: ----Function: Enables or Disables the internal operational amplifier peripheral of certain devices. 536 Built-in Functions Availability: Devices with a built-in operational amplifier (for example, PIC16F785) Requires: ----Examples: setup_opamp1(OPAMP_ENABLED); setup_opamp2(OPAMP_DISABLED); setup_opamp3(OPAMP_ENABLED | OPAMP_I_TO_OUTPUT); setup_opamp1( ) setup_opamp2( ) setup_opamp3( ) setup_opamp4( ) Syntax: setup_opamp1(mode) setup_opamp2(mode) setup_opamp3(mode) setup_opamp4(mode) Parameters: mode - The mode of the operation amplifier. See the devices .h file for all options. Some typical options include: OPAMP_ENABLED OPAMP_DISABLED Returns: ----Function: Enables or Disables the internal operational amplifier peripheral of certain devices. Availability: Devices with a built-in operational amplifier (for example, PIC16F785) Requires: ----Examples: setup_opamp1(OPAMP_ENABLED); setup_opamp2(OPAMP_DISABLED); setup_opamp3(OPAMP_ENABLED | OPAMP_I_TO_OUTPUT); 537 Built-in Functions setup_oscillator( ) Syntax: setup_oscillator(mode, finetune) Parameters: mode - is dependent on the chip. For example, some chips allow speed setting such as OSC_8MHZ or OSC_32KHZ. Other chips permit changing the source like OSC_TIMER1. finetune - (only allowed on certain parts) is a signed int with a range of -31 to +31. Returns: Some devices return a state such as OSC_STATE_STABLE to indicate the oscillator is stable. Function: This function controls and returns the state of the internal RC oscillator on some parts. See the devices .h file for valid options for a particular device. Note that if INTRC or INTRC_IO is specified in #fuses and a #USE DELAY is used for a valid speed option, then the compiler will do this setup automatically at the start of main(). WARNING: If the speed is changed at run time the compiler may not generate the correct delays for some built in functions. The last #USE DELAY encountered in the file is always assumed to be the correct speed. You can have multiple #USE DELAY lines to control the compilers knowledge about the speed. Availability: Devices with a OSCCON register. Requires: Constants are defined in the .h file. Examples: setup_oscillator( OSC_2MHZ ); See Also: #FUSES, Internal oscillator Overview [PCD] Syntax: setup_oscillator(mode, target [,source] [,divide] ) 538 Built-in Functions Parameters: mode - is one of: OSC_INTERNAL OSC_CRYSTAL OSC_CLOCK OSC_RC OSC_SECONDARY target - is the target frequency to run the device it. source - is optional. It specifies the external crystal/oscillator frequency. If omitted the value from the last #USE DELAY is used. If mode is OSC_INTERNAL, source is an optional tune value for the internal oscillator for devices that support it. If omitted a tune value of zero will be used. divide in - is optional. For devices that support it, it specifies the divide ration for the Display Module Interface Clock. A number from 0 to 64 divides the clock from 1 to 17 increasing in increments of 0.25, a number from 64 to 96 divides the clock from 17 to 33 increasing in increments of 0.5, and a number from 96 to 127 divides the clock from 33 to 64 increasing in increments of 1. If omitted zero will be used for divide by 1. Returns: ----Function: Configures the oscillator with preset internal and external source configurations. If the device fuses are set and #use delay() is specified, the compiler will configure the oscillator. Use this function for explicit configuration or programming dynamic clock switches. Please consult your target data sheets for valid configurations, especially when using the PLL multiplier, as many frequency range restrictions are specified. Availability: All Devices. Requires: Constants are defined in the .h file. Examples: setup_oscillator( OSC_CRYSTAL, 4000000, 16000000); setup_oscillator( OSC_INTERNAL, 29480000); See Also: setup_wdt( ), Internal Oscillator Overview 539 Built-in Functions setup_pga( ) Syntax: setup_pga(module,settings) Parameters: module - constant specifying the Programmable Gain Amplifier (PGA) to setup. Returns: ----Function: This function allows for setting up one of the Programmable Gain Amplifier modules. Availability: Devices with a Programmable Gain Amplifier module. Requires: ----Examples: setup_pga(PGA_ENABLED | PGA_POS_INPUT_PGAxP1 | PGA_GAIN_8X); setup_pid( ) Syntax: setup_pid([mode,[K1],[K2],[K3]); Parameters: mode - the setup of the PID module. The options for setting up the module are defined in the device's header file as: PID_MODE_PID PID_MODE_SIGNED_ADD_MULTIPLY_WITH_ACCUMULATION PID_MODE_SIGNED_ADD_MULTIPLY PID_MODE_UNSIGNED_ADD_MULTIPLY_WITH_ACCUMULATION PID_MODE_UNSIGNED_ADD_MULTIPLY PID_OUTPUT_LEFT_JUSTIFIED PID_OUTPUT_RIGHT_JUSTIFIED K1 - optional parameter specifying the K1 coefficient, defaults to zero if not specified. The K1 coefficient is used in the PID and ADD_MULTIPLY modes. When in PID mode the K1 coefficient can be calculated with the following formula: K1 = Kp + Ki * T + Kd/T 540 Built-in Functions When in one of the ADD_MULTIPLY modes K1 is the multiple value. K2 - optional parameter specifying the K2 coefficient, defaults to zero if not specified. The K2 coefficient is used in the PID mode only and is calculated with the following formula: K2 = -(Kp + 2Kd/T) K3 - optional parameter specifying the K3 coefficient, defaults to zero if not specified. The K3 coefficient is used in the PID mode, only and is calculated with the following formula: K3 = Kd/T T - is the sampling period in the above formulas. Returns: ----Function: Setup the Proportional Integral Derivative (PID) module, and to set the input coefficients (K1, K2 and K3). Availability: Devices with built in PID module Requires: Constants are defined in the device's .h file. Examples: setup_pid(PID_MODE_PID, 10, -3, 50); See Also: pid_get_result(), pid_read(), pid_write(), pid_busy() setup_pmp(option,address_mask) Syntax: setup_pmp(options,address_mask); Parameters: options - The mode of the Parallel Master Port that allows to set the Master Port mode, read-write strobe options and other functionality of the PMPort module. See the device's .h file for all options. Some typical options include: PAR_PSP_AUTO_INC 541 Built-in Functions PAR_CONTINUE_IN_IDLE PAR_INTR_ON_RW PAR_INC_ADDR cycle PAR_MASTER_MODE_1 PAR_WAITE4 // Interrupt on read write // Increment address by 1 every read/write // Master Mode 1 // 4 Tcy Wait for data hold after strobe address_mask - this allows the user to setup the address enable register with a 16-bit value. This value determines which address lines are active from the available 16 address lines PMA0:PMA15. Returns: ----Function: Configures various options in the PMP module. The options are present in the device's .h file and they are used to setup the module. The PMP module is highly configurable and this function allows users to setup configurations like the Slave module, Interrupt options, address increment/decrement options, Address enable bits, and various strobe and delay options. Availability: Devices with built in Parallel Master Port module. Requires: Constants are defined in the device's .h file. Examples: setup_psp(PAR_ENABLE| PAR_MASTER_MODE_1|PAR_ STOP_IN_IDLE,0x00FF); //Sets up Master mode with address //lines PMA0:PMA7 See Also: setup_pmp( ), pmp_address( ), pmp_read( ), psp_read( ), psp_write( ), pmp_write( ), psp_output_full( ), psp_input_full( ), psp_overflow( ), pmp_output_full( ), pmp_input_full( , pmp_overflow( ) setup_power_pwm( ) Syntax: setup_power_pwm(modes, postscale, time_base, period, compare, compare_postscale, dead_time) 542 Built-in Functions Parameters: modes - values may be up to one from each group of the following: PWM_CLOCK_DIV_4, PWM_CLOCK_DIV_16, PWM_CLOCK_DIV_64, PWM_CLOCK_DIV_128 PWM_DISABLED, PWM_FREE_RUN, PWM_SINGLE_SHOT, PWM_UP_DOWN, PWM_UP_DOWN_INT PWM_OVERRIDE_SYNC PWM_UP_TRIGGER, PWM_DOWN_TRIGGER PWM_UPDATE_DISABLE, PWM_UPDATE_ENABLE PWM_DEAD_CLOCK_DIV_2, PWM_DEAD_CLOCK_DIV_4, PWM_DEAD_CLOCK_DIV_8, PWM_DEAD_CLOCK_DIV_16 postscale - is an integer between 1 and 16. This value sets the PWM time base output postscale. time_base - is an integer between 0 and 65535. This is the initial value of the PWM base period - is an integer between 0 and 4095. The PWM time base is incremented until it reaches this number. compare - is an integer between 0 and 255. This is the value that the PWM time base is compared to, to determine if a special event should be triggered. compare_postscale - is an integer between 1 and 16. This postscaler affects compare, the special events trigger. dead_time - is an integer between 0 and 63. This value specifies the length of an off period that should be inserted between the going off of a pin and the going on of it is a complementary pin. Returns: ----Function: Initializes and configures the motor control Pulse Width Modulation (PWM) module. 543 Built-in Functions Availability: Devices with motor control or power PWM module. Requires: ----Examples: setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN|PWM_DEAD_CLOCK_DIV_4,1,100 00,1000,0,1,0); See Also: set_power_pwm_override(), setup_power_pwm_pins(), set_power_pwmX_duty() setup_power_pwm_faults( ) Syntax: setup_power_pwm_faults(mode); Parameters: mode - to setup the Power PWM faults. Valid options vary by device. See the device's header file for all options. Returns: ----Function: Used to setup the power PWM faults for the Power Control PWM module. Availability: Devices with a Power Control PWM module. Requires: ----Examples: setup_power_pwm_faults(PWM_ENABLE_FLTA | PWM_AUTO_CLEAR_FLTA); See Also: set_power_pwm_override(), setup_power_pwm_pins(), set_power_pwmX_duty(), setup_power_pwm( ) 544 Built-in Functions setup_power_pwm_pins( ) Syntax: setup_power_pwm_pins(module0,module1,module2,module3) Parameters: For each module (two pins) specify: PWM_PINS_DISABLED PWM_ODD_ON PWM_BOTH_ON'PWM_COMPLEMENTARY Returns: ----Function: Configures the pins of the Pulse Width Modulation (PWM) device. Availability: Devices with motor control or power PWM module. Requires: ----Examples: setup_power_pwm_pins(PWM_PINS_DISABLED, PWM_PINS_DISABLED, PWM_PINS_DISABLED, PWM_PINS_DISABLED); setup_power_pwm_pins(PWM_COMPLEMENTARY, PWM_COMPLEMENTARY, PWM_PINS_DISABLED, PWM_PINS_DISABLED); See Also: setup_power_pwm(), set_power_pwm_override(),set_power_pwmX_duty() setup_prgx() Syntax: setup_prg1(mode, current, rising_source, falling_source); setup_prg2(mode, current, rising_source, falling_source); setup_prg3(mode, current, rising_source, falling_source); setup_prg4(mode, current, rising_source, falling_source); 545 Built-in Functions Parameters: mode - the mode to setup the PRGx module in. The valid options vary depending on the device. See the device's header file for all options. current - the current source/sink setting to set the PRGx module to and can be a value from 0 to 31. When using a value from 0 to 15, the current is calculated as: 2+(current / 2) uA. When using a value from 16 to 31, the current is calculated as: 10+(current - 16) uA. rising_source - used to set the rising timing source. The valid options vary depending on the device. See the device's header file for all options. falling_source - used to set the falling timing source. The valid options vary depending on the device. See the device's header file for all options. Returns: ----Function: Used to set the PRGx modules. Availability: Devices that have a Programmable Ramp Generator (PRG) module. Requires: -----Examples: setup_prg1(PRG_ENABLED | PRG_INPUT_SOURCD_FVR, 16, PRG_RISING_SOURCE_CCP1, PRG_RISING_SOURCE_CCP2); See Also: prgx_status( ) setup_psmc( ) Syntax: setup_psmc(unit, mode, period, period_time, rising_edge, rise_time, falling_edge, fall_time); Parameters: unit - is the PSMC unit number 1-4 546 Built-in Functions mode - is one of: PSMC_SINGLE PSMC_PUSH_PULL PSMC_BRIDGE_PUSH_PULL PSMC_PULSE_SKIPPING PSMC_ECCP_BRIDGE_REVERSE PSMC_ECCP_BRIDGE_FORWARD PSMC_VARIABLE_FREQ PSMC_3_PHASE For complementary outputs use a bar (|) and or in PSMC_COMPLEMENTARY Normally the module is not started until the psmc_pins() call is made. To enable immediately or in PSMC_ENABLE_NOW. period - has three parts or'ed together. The clock source, the clock divisor and the events that can cause the period to start. Sources: PSMC_SOURCE_FOSC PSMC_SOURCE_64MHZ PSMC_SOURCE_CLK_PIN Divisors: PSMC_DIV_1 PSMC_DIV_2 PSMC_DIV_4 PSMC_DIV_8 Events - Use any of the events listed below. period_time - is the duration the period lasts in ticks. A tick is the above clock source divided by the divisor. rising_edge - is any of the following events to trigger when the signal goes active. rise_time - is the time in ticks that the signal goes active (after the start of the period) if the event is SMC_EVENT_TIME, otherwise unused. falling_edge - is any of the following events to trigger when the signal goes inactive. fall_time - is the time in ticks that the signal goes inactive (after the start of the period) if the event is PSMC_EVENT_TIME, otherwise unused. Events: PSMC_EVENT_TIME 547 Built-in Functions PSMC_EVENT_C1OUT PSMC_EVENT_C2OUT PSMC_EVENT_C3OUT PSMC_EVENT_C4OUT PSMC_EVENT_PIN_PIN Returns: ----Function: Initializes a PSMC unit with the primary characteristics such as the type of PWM, the period, duty and various advanced triggers. Normally this call does not start the PSMC. It is expected all the setup functions be called and the psmc_pins() be called last to start the PSMC module. These two calls are all that are required for a simple PWM. The other functions may be used for advanced settings and to dynamically change the signal. Availability: Devices with built in PSMC module. Requires: ----Examples: //Simple PWM, 10khz out on pin C0 assuming a 20mhz crystal // Duty is initially set to 25% setup_psmc(1, PSMC_SINGLE,PSMC_EVENT_TIME | PSMC_SOURCE_FOSC, 100, PSMC_EVENT_TIME, 0,PSMC_EVENT_TIME, 25); psmc_pins(1, PSMC_A); See Also: psmc_deadband(), psmc_sync(), psmc_blanking(), psmc_modulation(), psmc_shutdown(), psmc_duty(), psmc_freq_adjust(), psmc_pins() setup_psp(option,address_mask) Syntax: setup_psp (options,address_mask); setup_psp(options); 548 Built-in Functions Parameters: Option - The mode of the Parallel slave port. This allows to set the slave port mode, read-write strobe options and other functionality of the PMP/EPMP module. See the devices .h file for all options. Some typical options include: PAR_PSP_AUTO_INC PAR_CONTINUE_IN_IDLE PAR_INTR_ON_RW // Interrupt on read write PAR_INC_ADDR // Increment address by 1 every read/write cycle PAR_WAITE4 // 4 Tcy Wait for data hold after strobe address_mask - This allows the user to setup the address enable register with a 16 bit or 32 bit (EPMP) value. This value determines which address lines are active from the available 16 address lines PMA0: PMA15 or 32 address lines PMAO:PMA31 (EPMP only) Returns: ----Function: Configures various options in the PMP/EPMP module. The options are present in the device.h file and they are used to setup the module. The PMP/EPMP module is highly configurable and this function allows users to setup configurations like the Slave mode, Interrupt options, address increment/decrement options, Address enable bits and various strobe and delay options. Availability: Devices with Parallel Port module or Enhanced Parallel Master Port module. Requires: Constants are defined in the devices .h file. Examples: setup_psp(PAR_PSP_AUTO_INC| PAR_STOP_IN_IDLE,0x00FF ); increment //Sets up legacy slave mode with //read and write buffers auto See Also: psp_output_full(), psp_input_full(), psp_overflow(), setup_pmp() , pmp_address() , pmp_read() , psp_read() , psp_write() , pmp_write() ,pmp_output_full() , pmp_input_full() , pmp_overflow() [PCD] 549 Built-in Functions setup_pwm1( ) setup_pwm2( ) setup_pwm3( ) setup_pwm4( ) Syntax: setup_pwm1(settings); setup_pwm2(settings); setup_pwm3(settings); setup_pwm4(settings); Parameters: settings- setup of the PWM module. See the device's .h file for all options. Some typical options include: PWM_ENABLED PWM_OUTPUT PWM_ACTIVE_LOW Returns: ----Function: Initializes the Pulse Width Modulation (PWM) device. Availability: Devices with PWM module. Requires: ----Examples: setup_pwm1(PWM_ENABLED|PWM_OUTPUT); setup_qei( ) Syntax: setup_qei( options, filter, maxcount ); [PCD] setup_qei( [unit,]options, filter, maxcount ); Parameters: Options - The mode of the QEI module. See the devices .h file for all options. Some common options are: QEI_MODE_X2 QEI_MODE_X4 filter - This parameter is optional, the user can enable the digital filters and specify the clock divisor. 550 Built-in Functions maxcount - Specifies the value at which to reset the position counter. Options- The mode of the QEI module. See the devices .h file for all options. Some common options are: QEI_MODE_X2 QEI_TIMER_GATED QEI_TIMER_DIV_BY_1 [PCD] filter - This parameter is optional and the user can specify the digital filter clock divisor. [PCD] [PCD] maxcount - This will specify the value at which to reset the position counter. unit - Optional unit number, defaults to 1. Returns: ----[PCD] Function: Configures the Quadrature Encoder Interface. Various settings like mode and filters can be setup. Availability: Devices with QEI module. Requires: ----Examples: setup_qei(QEI_MODE_X2|QEI_RESET_WHEN_MAXCOUNT, EI_FILTER_ENABLE_QEA|QEI_FILTER_DIV_2,0x1000); [PCD] setup_qei(QEI_MODE_X2|QEI_TIMER_INTERNAL,QEI_FILTER_DIV_2,QEI_FORWARD) ; See Also: qei_set_count() , qei_get_count() , qei_status() setup_rtc( ) Syntax: setup_rtc(options, calibration); 551 Built-in Functions [PCD] setup_rtc(options, period, stability_time, sample_time); //RTCC with Timestamp Parameters: Options- The mode of the RTCC module. See the devices .h file for all options Calibration- This parameter is optional and the user can specify an 8 bit value that will get written to the calibration configuration register. Period - RTCC with Timestamp, sets the period of the clock divider counter. Value should be set to achieve a period of 0.5 seconds. [PCD] Stability_time - RTCC with Timestamp, sets the Power Control Stability Time (2255). This parameter is optional. [PCD] Sample_time - RTCC with Timestamp, sets the Power Control Sample Time Window (2-255). This parameter is optional. Returns: ----[PCD] Function: Configures the Real Time Clock and Calendar module. The module requires an external 32.768 kHz clock crystal for operation. Availability: Devices with RTCC module. Requires: ----Examples: setup_rtc(RTC_ENABLE | RTC_OUTPUT SECONDS, 0x00); // Enable RTCC module with seconds clock and no calibration setup_rtc(RTC_ENABLE|RTC_CLOCK_SOSC, 16383); // Enable RTCC with Timestamp module from an external 32.768Khz crystal [PCD] See Also: rtc_read(), rtc_alarm_read(), rtc_alarm_write(), setup_rtc_alarm(), rtc_write(, setup_rtc() 552 Built-in Functions setup_rtc_alarm( ) Syntax: setup_rtc_alarm(options, mask, repeat); Parameters: options - The mode of the RTCC module. See the devices .h file for all options mask - specifies the alarm mask bits for the alarm configuration. repeat - Specifies the number of times the alarm will repeat. It can have a max value of 255. Returns: ----Function: Configures the alarm of the RTCC module. Availability: Devices with RTCC module. Requires: ----Examples: setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_HOUR, 3); See Also: rtc_read(), rtc_alarm_read(), rtc_alarm_write(), setup_rtc_alarm(), rtc_write(), setup_rtc() setup_sd_adc( ) Syntax: setup_sd_adc(settings1, settings 2, settings3); Parameters: settings1 - settings for the SD1CON1 register of the SD ADC module. See the device's .h file for all options. Some options include: 1 SDADC_ENABLED 2 SDADC_NO_HALT 3 SDADC_GAIN_1 4 SDADC_NO_DITHER 553 Built-in Functions 5 6 SDADC_SVDD_SVSS SDADC_BW_NORMAL settings2 - settings for the SD1CON2 register of the SD ADC module. See the device's .h file for all options. Some options include: 7 SDADC_CHOPPING_ENABLED 8 SDADC_INT_EVERY_SAMPLE 9 SDADC_RES_UPDATED_EVERY_INT 10 SDADC_NO_ROUNDING settings3 - settings for the SD1CON3 register of the SD ADC module. See the device's .h file for all options. Some options include: 11 SDADC_CLOCK_DIV_1 12 SDADC_OSR_1024 13 SDADC_CLK_SYSTEM Returns: ----Function: Setup the Sigma-Delta Analog to Digital Converter (SD ADC) module. Availability: Devices with SD ADC module. Requires: ----Examples: setup_sd_adc(SDADC_ENABLED | SDADC_DITHER_LOW,SDADC_CHOPPING_ENABLED | SDADC_INT_EVERY_5TH_SAMPLE |SDADC_RES_UPDATED_EVERY_INT, SDADC_CLK_SYSTEM |SDADC_CLOCK_DIV_4); See Also: set_sd_adc_channel(), read_sd_adc(), set_sd_adc_calibration() [PCD] setup_sent( ) Syntax: setup_sent(module, settings, tick_time); setup_sent(module, settings, tick_time, [frame_time]); 554 Built-in Functions Parameters: module - the SENT peripheral to setup, 1 or 2 for most devices. settings - the mode to setup the SENT peripheral in. Constants for setting up the peripheral are defined in the device's header file. See the device's header file for all the possible options. tick_time - the tick time to set the SENT peripheral to, value is a time in us from 3 to 90. fame_time - optional parameter unless peripheral is set-up for transmitter mode and sent_uses_pause_pulse is used in settings parameter. It is used to set the frame time in us of the message. Returns: ----Function: Used to setup the Single-Edge Nibble Transmission (SENT) peripheral. Availability: Devices with a SENT peripheral. Requires: ----Examples: //Setup SENT1 peripheral for asynchronous transmitter //mode with HW CRC generation enabled, pause pulse //enabled, and to send 6 data nibbles with a tick time //90us and a frame time of 50ms. setup_sent(1, SENT_MODE_TRANSMITTER_ASYNCHRONOUS | SENT_ENABLE_HW_CRC | SENT_USES_PAUSE_PULSE | SENT_DATA_NIBBLES_6, 90, 50000); Example Files: ex_sent_transmitter.c, ex_sent_receiver.c See Also: sent_getd( ), sent_putd( ), sent_status( ) setup_smtx( ) Syntax: setup_smt1(mode,[period]); 555 Built-in Functions setup_smt2(mode,[period]); Parameters: mode - The setup of the SMT module. See the device's .h file for all options. Some typical options include: SMT_ENABLED SMT_MODE_TIMER SMT_MODE_GATED_TIMER SMT_MODE_PERIOD_DUTY_CYCLE_ACQ period - Optional parameter for specifying the overflow value of the SMT timer, defaults to maximum value if not specified. Returns: ----Function: Configures the Signal Measurement Timer (SMT) module. Availability: Devices with SMT module. Requires: ----Examples: setup_smt1(SMT_ENABLED | SMT_MODE_PERIOD_DUTY_CYCLE_ACQ| SMT_REPEAT_DATA_ACQ_MODE | SMT_CLK_FOSC); See Also: smtx_status(), stmx_start(), smtx_stop(), smtx_update(), smtx_reset_timer(), smtx_read(), smtx_write() setup_spi( ) setup_spi2( ) setup_spi3( ) setup_spi4( ) Syntax: setup_spi(mode) setup_spi2(mode) setup_spi3(mode) setup_spi4(mode) Parameters: mode may be: SPI_MASTER, SPI_SLAVE, SPI_SS_DISABLED 556 Built-in Functions SPI_L_TO_H, SPI_H_TO_L SPI_CLK_DIV_4, SPI_CLK_DIV_16, SPI_CLK_DIV_64, SPI_CLK_T2 SPI_SAMPLE_AT_END, SPI_XMIT_L_TO_H [PCD] SPI_MODE_16B, SPI_XMIT_L_TO_H Constants from each group may be or'ed together with | Returns: ----Function: Initializes the Serial Port Interface (SPI). This is used for 2 or 3 wire serial devices that follow a common clock/data protocol. [PCD] Configures the hardware SPI™ module. SPI_MASTER will configure the module as the bus master SPI_SLAVE will configure the module as a slave on the SPI™ bus SPI_SS_DISABLED will turn off the slave select pin so the slave module receives any transmission on the bus. SPI_x_to_y will specify the clock edge on which to sample and transmit data SPI_CLK_DIV_x will specify the divisor used to create the SCK clock from system clock. Availability: Devices with SPI hardware module. Requires: Constants are defined in the device's .h file Examples: setup_spi(spi_master |spi_l_to_h | spi_clk_div_16 ); setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_DIV_BY_16); Example Files: ex_spi.c See Also: spi_write(), spi_read(), spi_data_is_in(), spi_set_txcnt(), SPI Overview setup_timerx( ) Syntax: setup_timerX(mode) setup_timerX(mode,period) 557 Built-in Functions Parameters: mode - is a bit-field comprised of the following configuration constants: TMR_DISABLED: Disables the timer operation. TMR_INTERNAL: Enables the timer operation using the system clock. Without divisions, the timer will increment on every instruction cycle. On PCD, this is half the oscillator frequency. TMR_EXTERNAL: Uses a clock source that is connected to the SOSCI/SOSCO pins TMR_EXTERNAL_SYNC: Uses a clock source that is connected to the SOSCI/SOSCO pins. The timer will increment on the rising edge of the external clock which is synchronized to the internal clock phases. This mode is available only for Timer1. TMR_EXTERNAL_RTC: Uses a low power clock source connected to the SOSCI/SOSCO pins; suitable for use as a real time clock. If this mode is used, the low power oscillator will be enabled by the setup_timer function. This mode is available only for Timer1. TMR_DIV_BY_X: X is the number of input clock cycles to pass before the timer is incremented. X may be 1, 8, 64 or 256. TMR_32_BIT: This configuration concatenates the timers into 32 bit mode. This constant should be used with timers 2, 4, 6 and 8 only. Period is an optional 16 bit integer parameter that specifies the timer period. The default value is 0xFFFF. Returns: ----Function: Sets up the timer specified by X (May be 1 – 9). X must be a valid timer on the target device. Availability: This function is available on all devices that have a valid timer X. Use getenv or refer to the target datasheet to determine which timers are valid. Requires: Constants are defined in the device's .h file 558 Built-in Functions Examples: /* setup a timer that increments every 64th instruction cycle with an overflow period of 0xA010 */ setup_timer2(TMR_INTERNAL | TMR_DIV_BY_64, 0xA010); /* Setup another timer as a 32-bit hybrid with a period of 0xFFFFFFFF and a interrupt that will be fired when that timer overflows*/ setup_timer4(TMR_32_BIT); timer value enable_interrupts(int_timer5); the interrupt //use get_timer45() to get the //use the odd number timer for See Also: Timer Overview, setup_timerX(), get_timerXY(), set_timerX(), set_timerXY() setup_timerA( ) Syntax: setup_timer_A (mode); Parameters: mode values may be: TA_OFF, TA_INTERNAL, TA_EXT_H_TO_L, TA_EXT_L_TO_H TA_DIV_1, TA_DIV_2, TA_DIV_4, TA_DIV_8, TA_DIV_16, TA_DIV_32, TA_DIV_64, TA_DIV_128, TA_DIV_256 Constants from different groups may be or'ed together with |. Returns: ----Function: Sets up Timer A. Availability: This function is only available on devices with Timer A hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_A(TA_OFF); 559 Built-in Functions setup_timer_A(TA_INTERNAL | TA_DIV_256); setup_timer_A(TA_EXT_L_TO_H | TA_DIV_1); See Also: get_timerA( ), set_timerA( ), TimerA Overview setup_timerB( ) Syntax: setup_timer_B (mode); Parameters: mode values may be: TB_OFF, TB_INTERNAL, TB_EXT_H_TO_L, TB_EXT_L_TO_H TB_DIV_1, TB_DIV_2, TB_DIV_4, TB_DIV_8, TB_DIV_16, TB_DIV_32, TB_DIV_64, TB_DIV_128, TB_DIV_256 Constants from different groups may be or'ed together with |. Returns: ----Function: Sets up Timer B. Availability: This function is only available on devices with Timer B hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_B(TB_OFF); setup_timer_B(TB_INTERNAL | TB_DIV_256); setup_timer_B(TA_EXT_L_TO_H | TB_DIV_1); See Also: get_timerB( ), set_timerB( ), TimerB Overview setup_timer0( ) Syntax: setup_timer_0 (mode); 560 Built-in Functions Parameters: mode - constants defined in the device's .h file. Some typical defines are: TO_INTERNAL TO_EXT_L_TO_H TO_EXT_H_TO_l TO_DIV_2, TO_DIV_4 (See device's .h file for all possible defines.) One constant may be used from each group or'ed together with the | operator. Returns: ----Function: Sets up the timer 0 (aka RTCC). Availability: All Devices. (WARNING: On older PIC16 devices, set-up of the prescaler may undo the WDT prescaler) Requires: Constants are defined in the device's .h file Examples: setup_timer_0 (TO_INTERNAL|TO_DIV2); See Also: get_timer0(), set_timer0(), setup counters() setup_timer1( ) Syntax: setup_timer_1 (mode); Parameters: mode T1_DISABLED, T1_INTERNAL, T1_EXTERNAL, T1_EXTERNAL_SYNC T1_CLK_OUT T1_DIV_BY_1, T1_DIV_BY_2, T1_DIV_BY_4, T1_DIV_BY_8 One constant may be used from each group or'ed together with the | operator. 561 Built-in Functions Returns: ----Function: Initializes timer 1. The timer value may be read and written to using SET_TIMER1() and GET_TIMER1()Timer 1 is a 16 bit timer. With an internal clock at 20mhz and with the T1_DIV_BY_8 mode, the timer will increment every 1.6us. It will overflow every 104.8576ms. Availability: Available only on devices with timer 1 hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_1 ( T1_DISABLED ); setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_4 ); setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 ); See Also: get_timer1(), set_timer1() , Timer1 Overview setup_timer2( ) Syntax: setup_timer_2 (mode, period, postscale); Parameters: mode T2_DISABLED T2_DIV_BY_1, T2_DIV_BY_4, T2_DIV_BY_16 period - is a int 0-255 that determines when the clock value is reset postscale - is a number 1-16 that determines how many timer overflows before an interrupt: (1 means once, 2 means twice, an so on). Returns: ----- 562 Built-in Functions Function: Initializes timer 2. The mode specifies the clock divisor (from the oscillator clock). The timer value may be read and written to using GET_TIMER2() and SET_TIMER2(). 2 is a 8-bit counter/timer. Availability: Available only on devices with timer 2 hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_2 ( T2_DIV_BY_4, 0xc0, 2) increment //at 20mhz, the timer will //every 800ns will overflow every 154.4us, //and will interrupt every 308.us See Also: get_timer2(), set_timer2() , Timer2 Overview setup_timer3( ) Syntax: setup_timer_3 (mode); Parameters: mode - may be one of the following constants from each group or'ed (via |) together: T3_DISABLED, T3_INTERNAL, T3_EXTERNAL, T3_EXTERNAL_SYNC T3_DIV_BY_1, T3_DIV_BY_2, T3_DIV_BY_4, T3_DIV_BY_8 Returns: ----Function: Initializes timer 3 or 4.The mode specifies the clock divisor (from the oscillator clock). The timer value may be read and written to using GET_TIMER3() and SET_TIMER3(). Timer 3 is a 16 bit counter/timer. Availability: Available only on devices with timer 3 hardware. 563 Built-in Functions Requires: Constants are defined in the device's .h file Examples: setup_timer_3 (T3_INTERNAL | T3_DIV_BY_2); See Also: get_timer3(), set_timer3() setup_timer4( ) Syntax: setup_timer_4 (mode); Parameters: mode - may be one of: T4_DISABLED, T4_DIV_BY_1, T4_DIV_BY_4, T4_DIV_BY_16 period - is a int 0-255 that determines when the clock value is reset postscale - is a number 1-16 that determines how many timer overflows before an interrupt: (1 means once, 2 means twice, and so on). Returns: ----Function: Initializes timer 4. The mode specifies the clock divisor (from the oscillator clock). The timer value may be read and written to using GET_TIMER4() and SET_TIMER4(). Timer 4 is a 8 bit counter/timer. Availability: Available only on devices with timer 4 hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_4 ( T4_DIV_BY_4, 0xc0, 2); increment // At 20mhz, the timer will // every 800ns,will overflow every 153.6us, 564 Built-in Functions // and will interrupt every 307.2us See Also: get_timer4(), set_timer4() setup_timer5( ) Syntax: setup_timer_5 (mode); Parameters: mode - may be one or two of the constants defined in the devices .h file. T5_DISABLED, T5_INTERNAL, T5_EXTERNAL, or T5_EXTERNAL_SYNC T5_DIV_BY_1, T5_DIV_BY_2, T5_DIV_BY_4, T5_DIV_BY_8 T5_ONE_SHOT, T5_DISABLE_SE_RESET, or T5_ENABLE_DURING_SLEEP Returns: ----Function: Initializes timer 5. The mode specifies the clock divisor (from the oscillator clock). The timer value may be read and written to using GET_TIMER5() and SET_TIMER5(). Timer 5 is a 16 bit counter/timer. Availability: Available only on devices with timer 5 hardware. Requires: Constants are defined in the device's .h file Examples: setup_timer_5 (T5_INTERNAL | T5_DIV_BY_2); See Also: get_timer5(), set_timer5(), Timer5 Overview setup_uart( ) Syntax: setup_uart(baud, stream) setup_uart(baud) 565 Built-in Functions setup_uart(baud, stream, clock) Parameters: baud - is a constant representing the number of bits per second. A one or zero may also be passed to control the on/off status. Stream - is an optional stream identifier. Chips with the advanced UART may also use the following constants: UART_ADDRESS UART only accepts data with 9th bit=1 UART_DATA UART accepts all data Chips with the EUART H/W may use the following constants: UART_AUTODETECT Waits for 0x55 character and sets the UART baud rate to match. UART_AUTODETECT_NOWAIT Same as above function, except returns before 0x55 is received. KBHIT() will be true when the match is made. A call to GETC() will clear the character. UART_WAKEUP_ON_RDA Wakes PIC up out of sleep when RCV goes from high to low clock - If specified this is the clock rate this function should assume. The default comes from the #USE DELAY. Returns: ----Function: Similar to SET_UART_SPEED. If 1 is passed as a parameter, the UART is turned on, and if 0 is passed, UART is turned off. If a BAUD rate is passed to it, the UART is also turned on, if not already on. Availability: Available only on devices with built in UART. Requires: #USE RS232 Examples: setup_uart(9600); setup_uart(9600, rsOut); See Also: #USE RS232, putc(), getc(), RS232 I/O Overview 566 Built-in Functions setup_vref( ) setup_vref2( ) Syntax: setup_vref (mode | value) Parameters: mode - may be one of the following constants: FALSE (off) VREF_LOW for VDD*VALUE/24 VREF_HIGH for VDD*VALUE/32 + VDD/4 any may be or'ed with VREF_A2. value - is an int 0-15. [PCD] mode - is a bit-field comprised of the following constants: VREF_DISABLED VREF_LOW ( Vdd * value / 24) VREF_HIGH ( Vdd * value / 32 + Vdd/4 ) VREF_ANALOG Returns: ----Function: Establishes the voltage of the internal reference that may be used for analog compares and/or for output on pin A2. [PCD] Configures the voltage reference circuit used by the voltage comparator. The voltage reference circuit allows you to specify a reference voltage that the comparator module may use. You may use the Vdd and Vss voltages as your reference or you may specify VREF_ANALOG to use supplied Vdd and Vss. Voltages may also be tuned to specific values in steps, 0 through 15. That value must be or’ed to the configuration constants. Availability: This function is only available on devices with VREF hardware. [PCD] Some devices, consult the device datasheet. Requires: [PCD] Constants are defined in the devices .h file Examples: 567 Built-in Functions setup_vref (VREF_HIGH | 6); // At VDD=5, the voltage is 2.19V /* Use the 15th step on the course setting */ setup_vref(VREF_LOW | 14); [PCD] Example Files: ex_comp.c See Also: Voltage Reference Overview setup_wdt( ) Syntax: setup_wdt (mode) Parameters: Constants: WDT_18MS WDT_36MS WDT_72MS WDT_144MS WDT_288MS WDT_576MS WDT_1152MS WDT_2304MS For some parts: WDT_ON WDT_OFF . [PCD] Mode is a bit-field comprised of the following constants: WDT_ON WDT_OFF Specific Time Options vary between chips, some examples are: WDT_2ms WDT_64MS WDT_1S WDT_16S Returns: ----568 Built-in Functions Function: Setup-wdt is used to set the timer that is allowed between calls to restart-wdt () before the chip is reset. Some parts also allow the wdt to be enabled/disabled and to run time by this function. Some parts do not allow the time to be changed at run time. The watchdog timer is used to cause a hardware reset if the software appears to be stuck. The timer must be enabled, the timeout time set and software must periodically restart the timer. Note: For PCH parts and PCM parts with software controlled WDT, setup_wdt( ) would enable/disable watchdog timer only if NOWDT fuse is set. If WDT fuse is set, watchdog timer is always enabled. Note: WDT_OFF should not be used with any other options. Warning: Some chips share the same prescaller between the WDT and Timer0. In these cases a call to setup_wdt may disable the Timer0 prescaller. Configures the watchdog timer. The watchdog timer is used to monitor the software. If the software does not reset the watchdog timer before it overflows, the device is reset, preventing the device from hanging until a manual reset is initiated. The watchdog timer is derived from the slow internal timer. [PCD] Availability: All Devices (WARNING: On older PIC16 devices, set-up of the prescaler may undo the timer0 prescaler) Requires: Constants are defined in the devices .h file Examples: #fuses WDT1, WDT PIC18 example main() { setup_wdt( WDT_18MS); while (TRUE) { restart_wdt(); perform_activity(); } } [PCD] // PIC18 example, See restart_wdt for a setup_wdt(WDT_ON); 569 Built-in Functions Example Files: [PCD] ex_wdt.c See Also: #FUSES , restart_wdt() , WDT or Watch Dog Timer Overview , Internal Oscillator Overview setup_zcd( ) Syntax: setup_zdc(mode); Parameters: mode- the setup of the ZDC module. The options for setting up the module include: ZCD_ENABLED ZCD_DISABLED ZCD_INVERTED ZCD_INT_L_TO_H ZCD_INT_H_TO_L Returns: ----Function: Set-up the Zero_Cross Detection (ZCD) module. Availability: Devices with a ZCD module. Requires: ----Examples: setup_zcd(ZCD_ENABLE|ZCD_INT_H_TO_L); See Also: zcd_status() 570 Built-in Functions shift_left( ) Syntax: shift_left (address, bytes, value) Parameters: address - is a pointer to memory. bytes - is a count of the number of bytes to work with value - is a 0 to 1 to be shifted in. Returns: 0 or 1 for the bit shifted out Function: Shifts a bit into an array or structure. The address may be an array identifier or an address to a structure (such as &data). Bit 0 of the lowest byte in RAM is treated as the LSB. Availability: All Devices. Requires: ----Examples: byte buffer[3]; for(i=0; i 4); Availability: All Devices Requires: ----Examples: x=0x45; swap(x); //x now is 0x54 [PCD] int x = 0x42; int result; 598 Built-in Functions result = swap(x); // result is 0x24; See Also: rotate_right(), rotate_left() tolower( ) toupper( ) Syntax: result = tolower (cvalue) result = toupper (cvalue) Parameters: cvalue - is a character Returns: An 8 bit character Function: These functions change the case of letters in the alphabet. TOLOWER(X) will return 'a'..'z' for X in 'A'..'Z' and all other characters are unchanged. TOUPPER(X) will return 'A'..'Z' for X in 'a'..'z' and all other characters are unchanged. Availability: All Devices Requires: ----Examples: switch( case case case } toupper(getc()) ) { 'R' : read_cmd(); break; 'W' : write_cmd(); break; 'Q' : done=TRUE; break; Example Files: ex_str.c touchpad_getc( ) Syntax: input = TOUCHPAD_GETC( ); 599 Built-in Functions Parameters: ----Returns: char (returns corresponding ASCII number is “input” declared as int) Function: Actively waits for firmware to signal that a pre-declared Capacitive Sensing Module (CSM) or charge time measurement unit (CTMU) pin is active, then stores the predeclared character value of that pin in “input”. Note: Until a CSM or CTMU pin is read by firmware as active, this instruction will cause the microcontroller to stall. Availability: Devices with CSM or CTMU Module. Requires: #USE TOUCHPAD (options) Examples: //When the pad connected to PIN_B0 is activated, store the letter 'A' #USE TOUCHPAD (PIN_B0='A') void main(void){ char c; enable_interrupts(GLOBAL); c = TOUCHPAD_GETC(); is detected //will wait until one of declared pins //if PIN_B0 is pressed, c will get value 'A' } See Also: #USE TOUCHPAD, touchpad_state( ) touchpad_hit( ) Syntax: value = TOUCHPAD_HIT( ) Parameters: ----Returns: TRUE or FALSE 600 Built-in Functions Function: Returns TRUE if a Capacitive Sensing Module (CSM) or Charge Time Measurement Unit (CTMU) key has been pressed. If TRUE, then a call to touchpad_getc() will not cause the program to wait for a key press. Availability: Devices with CSM or CTMU Module. Requires: #USE TOUCHPAD (options) Examples: //When the pad connected to PIN_B0 is activated, store the letter 'A' #USE TOUCHPAD (PIN_B0='A') void main(void){ char c; enable_interrupts(GLOBAL); while (TRUE) { if ( TOUCHPAD_HIT() ) pressed c = TOUCHPAD_GETC(); } } //wait until key on PIN_B0 is //get key that was pressed //c will get value 'A' See Also: #USE TOUCHPAD, touchpad_state( ), touchpad_getc( ) touchpad_state( ) Syntax: TOUCHPAD_STATE (state); Parameters: state - is a literal 0, 1, or 2. Returns: ----Function: Sets the current state of the touchpad connected to the Capacitive Sensing Module (CSM). The state can be one of the following three values: 0 : Normal state 1 : Calibrates, then enters normal state 601 Built-in Functions 2 : Test mode, data from each key is collected in the int16 array TOUCHDATA Note: If the state is set to 1 while a key is being pressed, the touchpad will not calibrate properly. Availability: Devices with CSM or CTMU Module. Requires: #USE TOUCHPAD (options) Examples: #USE TOUCHPAD (THRESHOLD=5, PIN_D5='5', PIN_B0='C') void main(void){ char c; TOUCHPAD_STATE(1); //calibrates, then enters normal state enable_interrupts(GLOBAL); while(1){ c = TOUCHPAD_GETC(); //will wait until one of declared pins is detected } //if PIN_B0 is pressed, c will get value 'C' } //if PIN_D5 is pressed, c will get value '5' See Also: #USE TOUCHPAD, touchpad_getc( ), touchpad_hit( ) tx_buffer_available( ) Syntax: value = tx_buffer_available([stream]); Parameters: stream – optional parameter specifying the stream defined in #USE RS232. Returns: Number of bytes that can still be put into transmit buffer. Function: Function to determine the number of bytes that can still be put into transmit buffer before it overflows. Transmit buffer is implemented has a circular buffer, so be sure to check to make sure there is room for at least one more then what is actually needed. 602 Built-in Functions Availability: All Devices Requires: #USE RS232 Examples: #USE_RS232(UART1,BAUD=9600,TRANSMIT_BUFFER=50) void main(void) { unsigned int8 Count = 0; while(TRUE){ if(tx_buffer_available()>13) printf("/r/nCount=%3u",Count++); } } See Also: _USE_RS232( ), tx_buffer_full( ), rcv_buffer_bytes( ),rcv_buffer_full( ), get( ), putc( ) ,printf( ), setup_uart( ), putc_send( ) tx_buffer_bytes( ) Syntax: value = tx_buffer_bytes([stream]); Parameters: stream – optional parameter specifying the stream defined in #USE RS232. Returns: Number of bytes in transmit buffer that still need to be sent. Function: Function to determine the number of bytes in transmit buffer that still need to be sent. Availability: All Devices Requires: #USE RS232 Examples: #USE_RS232(UART1,BAUD=9600,TRANSMIT_BUFFER=50) 603 Built-in Functions void main(void) { char string[] = “Hello”; if(tx_buffer_bytes()
52203-609 价格&库存

很抱歉,暂时无法提供与“52203-609”相匹配的价格&库存,您可以联系我们找货

免费人工找货