Home

CCS C Compiler Manual

image

Contents

1. at_setup_cc 2 AT_CC_ENABLED AT CC CAPTURE MODE AT CC_ACTIVE HIGH 153 CCS C 10082015 Example Files Also See bit_clear Syntax Parameters Returns Function Availability Requires Examples Example Files Also See bit_set Syntax Parameters Returns Function 154 None 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 set compare time at get capture at get status setup_at bit_clear var bit var may be a any bit variable any Ivalue bit is a number 0 31 representing a bit number 0 is the least significant bit undefined Simply clears the specified bit 0 7 0 15 or 0 31 in the given variable The least significant bit is 0 This function is the similar to var amp 1 lt lt bit All devices Nothing int x x 5 bit _clear x 2 x is now 1 ex patqg c bit_set bit_test bit_set var bit var may be a 8 16 or 32 bit variable any lvalue bit is a number 0 31 representing a bit number 0 is the least significant bit Undefined Sets the specified bit 0 7 0 15 or 0 31 in the given variable The least significant bit is 0 This function is the similar to
2. Parameters fallingtime sets the falling edge dead band time rising time sets the rising edge dead band time Returns Nothing 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 Examples set_cog_dead band 16 32 Example Files None Also See setup cog set cog phase set cog blanking cog status cog restart set_cog_phase Syntax set_cog_phase rising_time set_cog_phase falling_time rising_time Parameters falling time sets the falling edge phase time rising time sets the rising edge phase time Returns Nothing Function To set the falling and rising edge phase times on the Complementary 266 Availability Examples Example Files Also See Built in Functions 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 All devices with a COG module set Coe phess LO 10 None setup cog set cog dead band set cog blanking cog status cog restart set_compare_time Syntax Parameters Retur
3. HUES A Cada aaada wea ase cass aia PrE S T e E AE E E ia oleada n ea E E E E E A EE EEE E E E NE AS EEE NN Ne ETE EE E E EE ETE A E EE E E E E EE EEA E A A A A T TEE FEO WEISS HON RASO canica iia A 025i A E A E E agunand ended sae A E E E sume nouesaenee Susie E ASAA LOE E O T TE AA A A E SEE EA AS ATEA T E AA EEN E E E E E E E E E EE E E E E E eaa URE a E O E AE EE A E A E TE T AR EE A cat A O e E A E E E E E aden A ERAL EOE E E E E E E E E E ANT o E EE N S E EIS E EEE E E E E E T E EET E a EE 75 CCS C 10082015 O page E 102 E 102 AE A O O 103 POB cuina E arenero do Ea O soii 105 A A o gee E E E ec edasaiae ean pened ended pe 105 o AT 106 O 106 EAST AAE EEE O A 106 AUASI E E A E A E E E E E E E E E 107 aieia A E os cv Sete Scio E T AE E AOE O 108 ELOLA PAE E E E E E E A A E E A A EAS 108 E E EE E A E EAE AE state shad A E ET 109 FA E a iia nin io ie 109 A seuuisvasanesanesraunaimenisaniedeerieniaenieeGe 111 O E AA 111 a A A E E E ETE 112 PUAN E EE E ET E EE E E E A A E A E E E 113 MASELS E A CU E E E E E EE E AEE EE AE EE E E E A E E E E E E 113 PUSS AUS E A A EE N 114 E e OL 115 TUS memory oo c cd dav epeatec lesen cvieestze eaeacedevegettacubeteessvspeanses Spednas aE Eae A aAA OEA TE AENEASE REETA 116 TA 117 AA A A E E E EN A EEE 117 aA EEA A N A E E EEE E E E A E E ETE E EAE 117 PES SME O AA E E E E EA E E E E 119 O 119 RUBIO aan EEE E E iaa E E E T 120 ATIE LE A E E E T E E A E E E A EE E
4. Syntax Parameters Returns Function Availability Requires Examples shift_right address bytes value 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 0 or 1 for the bit shifted out Shifts a bit into an array or structure The address may be an array identifier or an address to a structure such as amp data Bit 0 of the lowest byte in RAM is treated as the LSB All devices Nothing reads 16 bits from pin Al each bit is read on a low to high on pin A2 struct byte time byte command 4 byte source 4 msg for 1 0 i lt 16 i while input PIN A2 shift right amp msg 3 input PIN Al while input PIN_A2 This shifts 8 bits out PIN AO LSB first 321 CCS C 10082015 for 1 0 1 lt 8 1 output_bit PIN AO shift_ right data 1 0 Example Files ex_extee c 9356 c Also See shift_left rotate right rotate left sleep Syntax sleep mode Parameters mode for most chips this is not used Check the device header for special options on some chips Returns Undefined Function Issues a SLEEP instruction Details are device dependent However in general the part will enter low power mode and halt program execution until woken by specific external events Depending on the cause of the wake up execution may continue after the sleep instruction The compiler insert
5. ex_psp c input output_x USE FIXED lO USE FAST 10 USE STANDARD IO interrupt_active Syntax Parameters Returns Function Availability Requires Examples Example Files interrupt_active interrupt Interrupt constant specifying the interrupt Boolean value The function checks the interrupt flag of the specified interrupt and returns true in case the flag is set Device with interrupts Should have a INT_xxxx Constants are defined in the devices h file interrupt_active INT_TIMERO interrupt active INT_TIMER1 None Also See disable interrupts INT Interrupts Overview clear interrupt enable _interrupts 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 197 CCS C 10082015 Parameters Returns Function Availability Requires Examples Example Files Also See isamong Syntax Parameters Returns 198 value isxdigit datac value iscntrl datac value isgraph datac value isprint datac value punct datac datac is a 8 bit character O or FALSE if datac dose not match the criteria 1 or TRUE if datac does match the criteria Tests a character to see if it meets specific c
6. Returns Function Availability Requires Examples setup_pga module settings module constant specifying the Programmable Gain Amplifier PGA to setup Undefined This function allows for setting up one of the Programmable Gain Amplifier modules Devices with a Programmable Gain Amplifier module Nothing setup_pga PGA_ENABLED PGA_POS_INPUT_PGAxP1 PGA_GAIN_8X 305 CCS C 10082015 Example Files Also See None setup_pid Syntax Parameters Returns Function Availability Requires 306 setup_pid mode K1 K2 K3 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 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
7. The timer must be enabled the timeout time set and software must periodically restart the timer These are done differently on the PCB PCM and PCH parts as follows 250 Built in Functions PCB PCM PCH Enable Disable fuses setup_wat Timeout time setup_wat fuses restart restart_wdt restart_wdt Availability All devices Requires FUSES Examples fuses WDT PCB PCM example See setup_wdt for a PIC18 example main setup_wdt WDT_2304MS while TRUE restart _wdt perform activity Example Files ex_wdt c Also See FUSES setup wdt WDT or Watch Dog Timer Overview rotate_left Syntax rotate_left address bytes Parameters address is a pointer to memory bytes is a count of the number of bytes to work with Returns undefined Function Rotates a bit through an array or structure The address may be an array identifier or an address to a byte or structure such as amp data Bit 0 of the lowest BYTE in RAM is considered the LSB Availability All devices Requires Nothing Examples x 0x86 rotate left amp x 1 x is now 0x0d Example Files None Also See rotate right shift _left shift_right 251 CCS C 10082015 rotate_right Syntax Parameters Returns Function Availability Requires Examples Example Files Also See rotate_right address bytes address is a pointer to memory bytes is a count of the numbe
8. int_usb Relevant Include files pic_usb h pic18 usb h usbn960x h usb h The same as kbhit returns TRUE if there is 1 or more character in the receive buffer The same as getc reads and returns a character from the receive buffer If there is no data in the receive buffer it will wait indefinitely until there a character has been received The same as putc sends a character It actually puts a character into the transmit buffer and if the transmit buffer is full will wait indefinitely until there is space for the character The same as usb_cdc_putc but will not wait indefinitely until there is space for the character in the transmit buffer In that situation the character is lost Sends a character string null terminated to the USB CDC port Will return FALSE if the buffer is busy TRUE if buffer is string was put into buffer for sending Entire string must fit into endpoint if string is longer than endpoint buffer then excess characters will be ignored Returns TRUE if there is space in the transmit buffer for another character A USB event has happened and requires application intervention The USB library that CCS provides handles this interrupt automatically Hardware layer driver for the PIC16C765 family PICmicro controllers with an internal USB peripheral Hardware layer driver for the PIC18F4550 family PICmicro controllers with an internal USB peripheral Hardware layer driver for the National U
9. 167 CCS C 10082015 Example Files Also See are not activated until the following statement enable interrupts GLOBAL ex sisr c ex stwt c enable nterrupts clear interrupt INT xxxx Interrupts Overview interrupt _active disable _pwm1_interrupt disable _pwm2_interrupt disable pwm3_interrupt disable _pwm4_interrupt disable _ pwmb5_interrupt disable _pwm6_interrupt Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 168 disable_pwm1_interrupt interrupt disable_pwm2_interrupt interrupt disable_pwm3_interrupt interrupt disable_pwm4_interrupt interrupt disable_pwm5_interrupt interrupt disable_pwm6_interrupt interrupt interrupt 8 bit constant or variable Constants are defined in the device s header file as e PWM_PERIOD_INTERRUPT PWM_DUTY_INTERRUPT PWM_PHASE_INTERRUPT PWM_OFFSET_INTERRUPT undefined Disables one of the above PWM interrupts multiple interrupts can be disabled by or ing multiple options together Devices with a 16 bit PWM module Nothing disable_pwm1_interrupt PWM_PERIOD INTERRUPT disable pwml_ interrupt PWM PERIOD INTERRUPT PWM DUTY INTERRUPT setup pwm set pwm_duty set pwm_phase set pwm period set pwm_offset enable pwm_interrupt clear _pwm_interrupt pwm interrupt active Built in Functions div Idiv Syntax idiv div num
10. B7 B6 B5 B4 are outputs B3 B2 B1 B0 are inputs Example Files led c Also See USE FAST 10 USE FIXED 10 USE STANDARD 10 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 undefined 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 BO and Bl switch input_b amp 3 case 0 set_uart_speed 2400 break case 1 set_uart_speed 4800 break case 2 set uart speed 9600 break case 3 set_uart speed 19200 break Example Files loader c Also See USE RS232 putc getc setup uart RS232 I O Overview 284 setjmp Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions result setjmp env env The data object that will receive the current environment 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
11. LVD 36 This would trigger the interrupt when the voltage is below 3 6 volts setup_nco Syntax Parameters setup_nco settings inc_value 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 inc_value value to increment the NCO 20 bit accumulator by 303 CCS C 10082015 Returns Function Availability Examples Example Files Also See Undefined Sets up the NCO module and sets the value to increment the 20 bit accumulator by On devices with a NCO module setup_nco NCO_ENABLED NCO_OUTPUT NCO_FIXED DUTY MODE NCO_CLOCK_FOSC 8192 None get nco accumulator set nco inc value get nco inc value setup_opamp1 setup opamp2 setup_opamp3 Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 304 setup_opamp1 mode setup_opamp2 mode setup_opamp3 mode mode The mode of the operation amplifier See the devices h file for all options Some typical options include OPAMP_ENABLED OPAMP_DISABLED undefined Enables or Disables the internal operational amplifier peripheral of certain PICmicros Only parts with a built in operational amplifier for example PIC16F785 Only parts with a built in operational amplifier for example PIC16F785 setup _opampl OPAMP_ENABLED setup_o
12. This does not return an ACK if using i2c in slave mode Sends a single byte over the 12C 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 timeout 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 12C protocol depends on the slave device All devices USE 12C long cmd i2c_start Start condition i2c_write 0xa0 Device address i2c_write cmd Low byte of command i2c_write cmd gt gt 8 High byte of command Stop condition i2c_stop ex_extee c with 2416 c i2c poll i2c_ speed i2c_ start i2c stop i2c_slaveaddr i2c isr state i2c_ read USE 12C 12C Overview value input pin Pinto 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 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 O or FALSE if the pin is low 1 or TRUE if the pin is high This function returns the st
13. an int16 constant or variable specifying the new PWM high time Nothing To change the duty cycle of the PWM signal The duty cycle percentage depends on the period of the PWM signal This function is faster than pwm_set_duty_percent but requires you to know what the period of the PWM signal is All devices USE PWM 235 CCS C 10082015 Examples USE PWM OUTPUT PIN C2 FREQUENCY 10kHz DUTY 25 Example Files None Also See ttuse pwm pwm_ on pwm off pwm_ set frequency pwm_ set duty percent pwm_set_duty_percent Syntax pwm_set_duty_percent stream percent Parameters stream optional parameter specifying the stream defined in USE PWM percent an int16 constant or variable ranging from O to 1000 specifying the new PWM duty cycle Dis 0 and 1000 is 100 0 Returns Nothing Function To change the duty cycle of the PWM signal Duty cycle percentage is based off the current frequency period of the PWM signal Availability All devices Requires USE PWM Examples USE PWM OUTPUT PIN C2 FREQUENCY 10kHz DUTY 25 pwm_set_ duty percent 500 set PWM duty cycle to 50 Example Files None Also See ttuse pwm pwm on pwm_off owm set frequency pwm set duty pwm_set_frequency Syntax pwm_set_frequency stream frequency Parameters stream optional parameter specifying the stream defined in USE PWM frequency an int32 constant or variable specifying the new PWM frequency R
14. mystring now has lt 1234 gt 0 Example Files Also See sqrt Syntax Parameters Returns Function Availability Requires Examples Example Files Also See srand Syntax Parameters Returns Function Built in Functions None printf result sqrt va ue value is a float A float Computes the non negative square root of the float value x If the argument is negative the behavior is undefined Note on error handling If errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Domain error occurs in the following cases sqrt when the argument is negative All devices INCLUDE lt math h gt distance sqrt pow x1 x2 2 pow yl y2 2 None None srand n nis the seed for a new sequence of pseudo random numbers to be returned by subsequent calls to rand No value The srand function uses the argument as a seed for a new sequence of pseudo random numbers to be returned by subsequent calls to rand If srand is then called with same seed 333 CCS C 10082015 Availability Requires Examples Example Files Also See value the sequence of random numbers shall be repeated If rand is called before any call to srand have been made the same sequence shall be generated as when srand is fi
15. output x output float output_float Syntax Parameters Returns Function Availability Requires Examples Example Files Also See output_float pin 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 The PIN could also be a variable to identify the pin The variable must have a value equal to one of the constants like PIN_A1 to work properly Note that doing I O with a variable instead of a constant will take much longer time undefined Sets the specified pin to the input mode This will allow the pin to float high to represent a high on an open collector type of connection All devices Pin constants are defined in the devices h file if data amp 0x80 0 output_low pin AO else output float pin AO None input output low output _high output bit output x output_drive USE FIXED_IO USE FAST IO USE STANDARD 1O General Purpose I O output_high Syntax Parameters output_high pin Pin to write to 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 The PIN could also be a variable The variable must have a value equal to one of the constants like PIN_A1 to w
16. psmc_shutdown psmc_duty psmc freq adjust psmc_pins psmc_duty Syntax Parameters Returns Function Availability Requires Examples psmc_pins unit pins_used pins_active_low unit is the PSMC unit number 1 4 fall_time is the time in ticks that the signal goes inactive after the start of the period assuming the event PSMC_EVENT_TIME has been specified in the setup_psmc Undefined This function changes the fall time within the period for the active signal This can be used to change the duty of the active pulse Note that the time is NOT a percentage nor is it the time the signal is active It is the time from the start of the period that the signal will go inactive If the rise_time was set to 0 then this time is the total time the signal will be active All devices equipped with PSMC module For a 10khz PWM based on Fosc divided by 1 the following sets the duty from 0 to 100 baed on the ADC reading while TRUE psmc_duty 1 read_adc int16 10 25 getenv CLOCK 1000000 227 CCS C 10082015 Example Files None Also See setup psmc psmc_deadband psmc_sync psmc_blanking psmc_modulation psmc_shutdown psmc freq adjust psmc_pins psmc_freq_adjust Syntax psmc_freq_adjust unit freg_adjust Parameters unit is the PSMC unit number 1 4 freq_adjust is the time in tick 16 increments to add to the period The value may be 0
17. 4 20000000 Example Files none Also See get timerB setup_timer_B TimerB Overview 282 Built in Functions set_timerx Syntax set_timerX va ue Parame A 16 bit integer specifiying the new value of the timer int16 ters Returns void Functio Allows the user to set the value of the timer n Availabi This function is available on all devices that have a valid timerX lity Require Nothing s Exampl if EventOccured es set_timer2 0 reset the timer Exampl None e Files Also Timer Overview set_timerX See set _tris_x 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 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 direction TRI State registers to be set This must be used with FAST_IO and when l O ports are accessed as memory such as when a BYTE directive is used to access an l O port Using the default standard l 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 283 CCS C 10082015 Requires Nothing Examples SET TRIS B Ox0F
18. CCS C 10082015 labs Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result labs value value is a 16 bit signed long int A 16 bit signed long int Computes the absolute value of a long integer All devices INCLUDE lt stdlib h gt if labs target _value actual value gt 500 printf Error is over 500 points r n None abs Icd_contrast Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 202 Icd_contrast contrast contrast is used to set the internal contrast control resistance ladder undefined This function controls the contrast of the LCD segments with a value passed in between 0 and 7 A value of 0 will produce the minimum contrast 7 will produce the maximum contrast Only on select devices with built in LCD Driver Module hardware None lcd contrast 0 Minimum Contrast led_contrast 7 Maximum Contrast None Icd_load lcd_symbol setup Icd Internal LCD Overview Icd_load Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions Icd_load buffer_pointer offset length buffer_pointer points to the user data to send to the LCD offset is the offset into the LCD segment memory to write the data length is the number of bytes to transfer to
19. EIE E E E E E E E T E T 344 oroS E E E E E EE E eee eee eee ee ee ee ee eee 345 O e e S E a E a EN 345 MUIR REM E E E E E E EE E E E E E E E E T E TT 346 MIS EOMUIQUISTON Momo Jaiera ieie eree a e Ee aE Eaa neta RE a EE osas 347 A E E E E E E E E 347 ea MEMO A cima lia E 348 cl A T 349 le A ewes E E E eve tas E E 349 PICOS TIO adds 350 136 abs Syntax Parameters Returns Function Availability Requires Examples Example Files Also See sin atan Syntax Parameters Returns cos sinh Built in Functions value abs x xis a signed 8 16 or 32 bit int or a float Same type as the parameter Computes the absolute value of a number All devices INCLUDE lt stdlib h gt signed int target actual error abs target actual None labs tan cosh asin tanh acos atan2 val sin rad val cos rad val tan rad rad asin val rad1 acos vah rad atan val rad2 atan2 val val result sinh value result cosh value result tanh va ue rad is a float representing an angle in Radians 2pi to 2pi val is a float with the range 1 0 to 1 0 Value is a float rad is a float representing an angle in Radians pi 2 to pi 2 val is a float with the range 1 0 to 1 0 rad1 is a float representing an angle in Radians 0 to pi 137 CCS C 10082015 rad2 is a float representing an angle in Radians pi to pi Result is a float Function
20. If the keyword DEFAULT is used then this address range is used for all functions user and compiler generated from this point in the file until a ORG DEFAULT is encountered no address range If a compiler function is called from the generated code while DEFAULT is in effect the compiler generates a new version of the function within the specified address range ORG may be used to locate data in ROM Because CONSTANT are implemented as functions the ORG should proceed the CONSTANT and needs a start and end address For a ROM declaration only the start address should be specified When linking multiple compilation units be aware this directive applies to the final object file It is an error if any ORG overlaps between files unless the ORG matches exactly ORG 0x1E00 OxlFFF MyFunc This function located at 1E00 ORG 0x1E00 Anotherfunc This will be somewhere 1E00 1F00 ORG 0x800 0x8Z0 5 Nothing will be at 800 820 ORG 0x1B80 ROM int32 seridl NO0 12345 ORG 0x1C00 Ox1COF CHAR CONST ID 10 123456789 This LD will be at 1000 Note some extra code will proceed the 123456789 ORG 0x1F00 Ox1FFO Void loader loader c HROM pin_select Syntax PIN_SELECT function pin_xx 103 CCS C 10082015 Elements Purpose Examples 104 function is the Microchip defined pin function name such as U1RX UART1 receive INT1 external interrupt 1 T2CK timer 2 clock IC1 i
21. Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions None output_a value output_b va ue output_c value output_d value output_e value output_f value output_g value output_h value output _j value output_k value value is a 8 bit int undefined Output an entire byte to a port The direction register is changed in accordance with the last specified USE _lO directive All devices however not all devices have all ports A E Nothing OUTPUT _B 0xf0 ex _patg c input output _low output_high output float output bit USE FIXED 10 USE FAST IO USE STANDARD 1O General Purpose I O output_bit Syntax Parameters Returns output_bit p n value 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 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 l O with a variable instead of a constant will take much longer time Value is a 1 or a 0 undefined 213 CCS C 10082015 Function Availability Requires Examples Example Files Also See Outputs the specified value 0 or 1 to
22. Relevant Functions getc or getch getchar or fgetc 58 Gets a character on the receive pin from the specified stream in case of fgetc stdin by default Use KBHIT to check if the character is available gets or fgets putc or putchar or fputc puts or fputs printf or fprintf kbhit setup_uart baud stream or setup_uart_speed baud stream assert condition perror message putc_send or fputc_send rcv_buffer_bytes tx_buffer_bytes tx_buffer_full receive_buffer_full useRS232 Relevant Interrupts INT_RDA INT_TBE Functional Overview Gets a string on the receive pin from the specified stream in case of fgets STDIN by default Use getc to receive each character until return is encountered Puts a character over the transmit pin on the specified stream in the case of fputc stdout by default Puts a string over the transmit pin on the specified stream in the case of fputc stdout by default Uses putc to send each character Prints the formatted string on the specified stream in the case of fprintf stdout by default Refer to the printf help for details on format string Return true when a character is received in the buffer in case of hardware RS232 or when the first bit is sent on the RCV pin in case of software RS232 Useful for polling without waiting in getc Used to change the baud rate of the hardware UART at run time Specifying stream is option
23. Sets up the d a mode e g Right enable clock divisor Writes the 16 bit value to the specified channel Relevant Preprocessor USE DELAY clock 20M Aux crystal 6M clock 3M Relevant Interrupts None Relevant Include Files None all functions built in Relevant getenv parameters None Example Code int8 i 0 setup_dac DAC_VSS_VDD while TRUE itt dac_write i 46 Data Eeprom Functional Overview The data eeprom memory is readable and writable in some chips These options lets the user read and write to the data eeprom memory These functions are only available in flash chips Relevant Functions 8 bit or 16 bit depending on the device read_eeprom address write_eeprom address value Relevant Preprocessor ROM address list write_eeprom noint Relevant Interrupts INT_EEPROM Relevant Include Files None all functions built in Relevant getenv parameters DATA_EEPROM Example Code For 18F452 rom 0xf00000 1 2 3 4 5 write_eeprom 0x0 0x1 2 value read_eeprom 0x0 ROM 0x007FFCOO 1 2 3 4 5 write_eeprom 0x10 0x1337 value read_eeprom 0x0 Reads the data EEPROM memory location Erases and writes value to data EEPROM location address Reads N bytes of data EEPROM starting at memory location address The maximum return size is int64 Reads from EEPROM to fill variable starting at address Reads N bytes starting at address to pointer Writes value to EEPROM addres
24. TIMER1 Example Code For PIC18F452 setup_timer_1 T1_DISABLED or setup_timer_1 T1_INTERNAL T1_DI V_BY_8 set_timer1 0 time get_timer1 Timer2 Disables or sets the source and prescale for timer1 Initializes the timer1 clock counter Returns the value of the timer1 clock counter Interrupt fires when timer1 overflows Returns 1 if the device has timer1 disables timer1 sets the internal clock as source land prescale as 8 At 20Mhz timer1 will increment every 1 6us in this setup and overflows every 104 896ms this sets timer1 register to 0 this will read the timer1 register value These options lets the user configure and use timer2 The clock counter is 8 bit on pic16s and pic18s It counts up and also provides interrupt on overflow The options available differ and are listed in the device header file Relevant Functions setup_timer_2 mode period postscale set_timer2 value value get_timer2 64 Disables or sets the prescale period and a postscale for timer2 Initializes the timer2 clock counter Returns the value of the timer2 clock counter Functional Overview Relevant Preprocessor None Relevant Interrupts INT_TIMER2 Interrupt fires when timer2 overflows Relevant Include Files None all functions built in Relevant getenv parameters TIMER2 Returns 1 if the device has timer2 Example Code For PIC18F452 setup_timer_2 T2_DISABLED disables timer2 or setup_t
25. USE STANDARD 10 General Purpose I O 195 CCS C 10082015 input_state Syntax Parameters Returns Function Availability Requires Examples Example Files Also See input_x Syntax Parameters Returns Function 196 value input_state pin pinto 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 Bit specifying whether pin is high or low A 1 indicates the pin is high and a 0 indicates it is low This function reads the level of a pin without changing the direction of the pin as INPUT does All devices Nothing level input _ state pin A3 printf level d level None input set tris x output low output high General Purpose l O 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 None An 8 bit int representing the port input data Inputs an entire byte from a port The direction register is changed in accordance with the last specified USE _lO directive By default with standard I O before the input is done the data direction is set to input Availability Requires Examples Example Files Also See Built in Functions All devices Nothing data input_b
26. X 12 fe X 12 FE 4X 0012 OOFE 3 1W 1 8 25 4 Result is undefined Assume garbage Availability All Devices Requires USE RS232 unless fname is used Examples byte x y z printf HiThere RTCCValue gt 2x n r get_rtcc printf S2u SX 4X n r x y Z 7 printf LCD PUTC n u n printf Example Files ex_admm c ex_Icdkb c Also See atoi puts putc getc for a stream example RS232 I O Overview profileout Syntax profileout string profileout string value profileout value Parameters string is any constant string and value can be any constant or variable integer Despite the length of string the user specifies here the code profile run time will actually only send a one or two byte identifier tag to the code profile tool to keep transmission and execution time to a minimum Returns Undefined Function Typically the code profiler will log and display function entry and exits to show the call sequence and profile the execution time of the functions By using 224 Availability Requires Examples Example Files Also See Built in Functions profileout the user can add any message or display any variable in the code profile tool Most messages sent by profileout are displayed in the Data Messages and Call Sequence screens of the code profile tool If a profileout string is used and the first word of string is START the code profile tool wi
27. by one For example enum colors red green 2 blue ved will be 0 green will be 2 and blue will be 3 SEE ALSO Declarations Type Specifiers Type Qualifiers Structures amp Unions typedef Named Registers 27 CCS C 10082015 Structures and Unions Struct structure type creates a collection of one or more variables possibly of different types grouped together as a single unit struct id type qualifier id bits id t t One or more Zero semi colon or more separated For example struct data_record int a 2 int p 3 2 2 bits int e 37 3 birts 7 int d data_var data_record is a structure type data_var is a variable Union type holds objects of different types and sizes with the compiler keeping track of size and alignment requirements They provide a way to manipulate different kinds of data in a single area of storage union id type qualifier id bits id Seren Zero or more separated For example union u_tab int ival long lval float fval u_tag is a union type that can hold a float SEE ALSO Declarations Type Specifiers Type Qualifiers Enumerated Types typedef Named Registers 28 Data Definitions typedef If typedef is used with any of the basic or special types it creates a new type name that can be used in declarations The identifier does not allocate space but rather may be used as a type specifier in other data de
28. c will have C if PIN D5 is pressed c will have 5 None touchpad _state touchpad getc touchpad _hit warning Syntax Elements Purpose Examples 128 WARNING text text is optional and may be any text Forces the compiler to generate a warning at the location this directive appears in the file The text may include macros that will be expanded for the display This may be used to see the macro expansion The command may also be used to alert the user to an invalid compile time situation To prevent the warning from being counted as a warning use this syntax warning information text if BUFFER SIZE lt 32 warning Buffer Overflow may occur endif Example Files Also See word WORD id x Syntax Elements id is a valid C identifier Purpose Examples Example Files Also See PreProcessor x_psp c ERROR xis a C variable or a constant If the id is already known as a C variable then this will locate the variable at address x In this case the variable type does not change from the original definition If the id is not known a new C variable is created and placed at address x with the type int16 Warning In both cases memory at x is not exclusive to this variable Other variables may be located at the same location In fact when x is a variable then id and x share the same memory location word data 0x0800 SU int lowerByte 8 int upperByte
29. denom Idiv Idiv num ldenom Parameters num and denom are signed integers num is the numerator and denom is the denominator Inum and Idenom are signed longs Inum is the numerator and Idenom is the denominator Returns idiv is a structure of type div_t and lidiv is a structure of type Idiv_t The div function returns a structure of type div_t comprising of both the quotient and the remainder The Idiv function returns a structure of type Idiv_t comprising of both the quotient and the remainder Function The div and Idiv function computes the quotient and remainder of the division of the numerator by the denominator If the division is inexact the resulting quotient is the integer or long of lesser magnitude that is the nearest to the algebraic quotient If the result cannot be represented the behavior is undefined otherwise quot denom Idenom rem shall equal num Inum Availability All devices Requires INCLUDE lt STDLIB H gt Examples div_t idiv ldiv_t lidiv idiv div 3 2 idiv will contain quot 1 and rem 1 lidiv ldiv 300 250 lidiv will contain lidiv quot 1 and lidiv rem 50 Example Files None Also See None enable_interrupts Syntax enable_interrupts eve Parameters level is a constant defined in the devices h file Returns undefined Function This function enables the interrupt at the given level An interrupt procedure should have been defined for the indicated interrupt The
30. labove 3 6 volts PMP EPMP The Parallel Master Port PMP Enhanced Parallel Master Port EPMP is a parallel 8 bit 16 bit I O module specifically designed to communicate with a wide variety of parallel devices Key features of the PMP module are 8 or 16 Data lines Up to 16 or 32 Programmable Address Lines Up to 2 Chip Select Lines Programmable Strobe option Address Auto Increment Auto Decrement Programmable Address Data Multiplexing Programmable Polarity on Control Signals Legacy Parallel Slave PSP Support Enhanced Parallel Slave Port Support Programmable Wait States Relevant Functions This will setup the PMP EPMP module for various mode and specifies which address lines to be used 53 CCS C 10082015 setup_psp options address_mask setup_pmp_csx options offset 1 setup_psp_es options psp_input_full psp_output_full Relevant Preprocessor None Relevant Interrupts INT_PMP Relevant Include Files None all functions built in Relevant getenv parameters None Example Code setup_pmp PAR_ENABLE PAR_MASTER_MODE_1 PAR_STOP_IN_IDLE OxOOFF If pmp_output_full pmp_write next_byte Power PWM This will setup the PSP module for various mode and specifies which address lines to be used Sets up the Chip Select X Configuration Mode and Base Address registers Sets up the Chip Select X Configuration and Mode registers Write the data byte
31. long long int32 float float32 double N A Note All types except float char by default are un signed however may be preceded by unsigned or signed Except int64 may only be signed Short and long may have the keyword INT following them with no effect Also see TYPE to change the default size SHORT INT1 is a special type used to generate very efficient code for bit operations and I O Arrays of bits INT1 or SHORT in RAM are now supported Pointers to bits are not permitted The device header files contain defines for BYTE as an int8 and BOOLEAN as an inti Integers are stored in little endian format The LSB is in the lowest address Float formats are described in common questions SEE ALSO Declarations Type Qualifiers Enumerated Types Structures amp Unions typedef Named Registers Type Qualifiers Type Qualifier static Variable is globally active and initialized to O Only accessible from this compilation unit auto Variable exists only while the procedure is active This is the default and AUTO need not be used double Is a reserved word but is not a supported data type extern External variable used with multiple compilation units No storage is allocated Is used to make otherwise out of scope data accessible there must be a non extern definition at the global level in some compilation unit register Is allowed as a qualifier however has no effect _fixed n Creates a fixed point decimal number where nis
32. milliseconds This function works by executing a precise number of instructions to cause the requested delay It does not use any timers If interrupts are enabled the time spent in an interrupt routine is not counted toward the time The delay time may be longer than requested if an interrupt is serviced during the delay The time spent in the ISR does not count toward the delay time Availability All devices Requires USE DELAY Examples use delay clock 20000000 delay ms 2 void delay seconds int n for n 0 n delay ms 1000 Example Files eX_SQw C Also See delay us delay cycles USE DELAY delay_us Syntax delay_us time Parameters time a variable 0 65535 int16 or a constant 0 65535 Note Previous compiler versions ignored the upper byte of an int16 now the upper byte affects the time Returns undefined Function Creates code to perform a delay of the specified length Time is specified in microseconds Shorter delays will be INLINE code and longer delays and variable delays are calls to a function This function works by executing a precise number of instructions to cause the requested delay It does not use any timers If interrupts are enabled the time 166 Availability Requires Examples Example Files Also See Built in Functions spent in an interrupt routine is not counted toward the time The delay time may be longer than requested if an interrupt is s
33. none Also See set_timerA setup_timer_A TimerA Overview 181 CCS C 10082015 get_timerB Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value get_timerB none The current value of the timer as an int8 Returns the current value of the timer All timers count up When a timer reaches the maximum value it will flip over to O and continue counting 254 255 0 1 2 This function is only available on devices with Timer B hardware Nothing set_timerB 0 while timerB lt 200 none set_timerB setup_timer_B TimerB Overview get_timerx Syntax Parameters Returns Function Availability 182 value get_timer0 Same as value get_rtcc value get_timer1 value get_timer2 value get_timer3 value get_timer4 value get_timer5 value get_timer6 value get_timer7 value get_timer8 value get_timer10 value get_timer12 None Timers 1 3 5 and 7 return a 16 bit int Timers 2 4 6 8 10 and 12 return an 8 bit int Timer O AKA RTCC returns a 8 bit int except on the PIC18XXX where it returns a 16 bit int Returns the count value of a real time clock counter RTCC and Timero0 are the same All timers count up When a timer reaches the maximum value it will flip over to O and continue counting 254 255 0 1 2 Timer 0 All devices Timers 1 amp 2 Most but not all PCM devic
34. or one of the following 1 SDADC_CH1SE_SVSS 2 SDADC_REFERENCE Nothing To select the channel that the Sigma Delta Analog to Digital Converter SD ADC performs the conversion on Only devices with a SD ADC module set_sd_adc_channel 0 None setup sd adc read sd adc set sd adc calibration set_timerA value An 8 bit integer Specifying the new value of the timer int8 281 CCS C 10082015 Returns undefined Function Sets the current value of the timer All timers count up When a timer reaches the maximum value it will flip over to O and continue counting 254 255 0 1 2 Availability This function is only available on devices with Timer A hardware Requires Nothing Examples 20 mhz clock no prescaler set timer A to overflow in 35us set_timerA 81 256 000035 4 20000000 Example Files none Also See 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 Returns undefined Function Sets the current value of the timer All timers count up When a timer reaches the maximum value it will flip over to O and continue counting 254 255 0 1 2 Availability This function is only available on devices with Timer B hardware Requires Nothing Examples 20 mhz clock no prescaler set timer B to overflow in 35us set_timerB 81 256 000035
35. returned The strtol function converts the initial portion of the string pointed to by nptr to a signed long int representation in some radix determined by the value of base The part of the string after conversion is stored in the object pointed to endptr provided that endptr is not a null pointer If nptr is empty or does not have the expected form no conversion is performed and the value of nptr is stored in the object pointed to by endptr provided endptr is not a null pointer All devices INCLUDE lt stdlib h gt signed long result char str 9 123hello char ptr result strtol str amp ptr 10 result is 123 and ptr is hello None strtod strtoul result strtoul nptr endptr base nptr and endptr are strings pointers and base is an integer 2 36 result is an unsigned long int returns the converted value in result if any If no conversion could be performed zero is returned The strtoul function converts the initial portion of the string pointed to by nptr to a long int representation in some radix determined by the value of base The part of the string after conversion is stored in the object pointed to endptr provided that endptr is not a null pointer If nptr is empty or does not have the expected form no conversion is performed and the value of nptr is stored in the object pointed to by endptr provided endptr is not a null pointer Built in Functions Availability All devices Requires STD
36. rtos_enable task Parameters task is the identifier of a function that is being used as an RTOS task Returns None Function This function enables a task to execute at it s specified rate Availability All devices Requires USE RTOS Examples rtos_enable toggle green Also See rtos disable rtos_msg_poll The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax i rtos_msg_poll Parameters None 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 256 Examples Also See Built in Functions if rtos_msg_poll rtos msg send rtos msg read rtos_msg_read The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires Examples Also See b rtos_msg_read None A byte that is a message for the task 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 All devices USE RTOS if rtos msg poll b rtos msg read rtos msg poll rtos msg send rtos_msg_send The RTOS is only include
37. set cog blanking set cog phase cog status crc_calcg8 crc_calc16 Result crc_calc data width Result crc_calc ptr len width Result crc_calc8 data width Result crc_calc8 ptr len width Result crc_calc16 data width lisame as crc_calc Result crc_calc16 ptr len width lisame as crc_calc data This is one double word word or byte that needs to be processed when using crc_calc16 or crc_calc8 ptr is a pointer to one or more double words words or bytes of data len number of double words words or bytes to process for function calls crc_calc16 or crc_calc8 width optional parameter used to specify the input data bit width to use with the functions crc_calc16 and crc_calc8 If not specified it defaults to the width of the return value of the function 8 bit for crc_calc8 16 bit for crc_calc16 For devices with a 16 bit for CRC the input data bit width is the same as the return bit width crc_calc16 and 8 bit crc_calc8 Returns the result of the final CRC calculation This will process one data double word word or byte or len double words words or bytes of Availability Requires Examples Example Files Also See Built in Functions data using the CRC engine Only the devices with built in CRC module Nothing int16 data 8 Result crce_calc data 8 None setup_cre crc_init crc_init mode Syntax Pa
38. size is the number of bytes to be allocated for each one of them A pointer to the allocated memory if any Returns null otherwise The calloc function allocates space for an array of nmem objects whose size is specified by size The space is initialized to all bits zero All devices INCLUDE lt stdlibm h gt int iptr iptr calloc 5 10 iptr will point to a block of memory of 50 bytes all initialized to 0 None realloc free malloc result ceil va ue value is a float 157 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See A float Computes the smallest integer value greater than the argument CEIL 12 67 is 13 00 All devices INCLUDE lt math h gt Calculate cost based on weight rounded up to the next pound cost ceil weight DollarsPerPound None floor clc1_setup_gate clc2_setup_gate clc3_setup_gate clc4 setup_gate Syntax clc1_setup_gate gate mode Parameters gate selects which data gate of the Configurable Logic Cell CLC module to Returns Function Availability Retu rns clc1l setup _gate 1 CLC_ GATE AND Examples 158 clc2_setup_gate gate mode clc3_setup_gate gate mode clc4_setup_gate gate mode setup value can be 1 to 4 mode the mode to setup the specified data gate of the CLC module into The options are CLC_GATE_AND CLC_GATE_NA
39. stdlib h structure type that contains two signed integers quot and rem structure type that contains two signed longs quot and rem returns 1 returns 0 4 Returns 0 not supported Multibyte characters not supported Returns the length of the string Returns 1 Returns 1 Returns length of string Returns length of string Stdlib h functions included just for compliance with ANSI C 353 SOFTWARE LICENSE AGREEMENT SOFTWARE LICENSE AGREEMENT Carefully read this Agreement prior to opening this package By opening this package you agree to abide by the following provisions If you choose not to accept these provisions promptly return the unopened package for a refund All materials supplied herein are owned by Custom Computer Services Inc CCS and is protected by copyright law and international copyright treaty Software shall include but not limited to associated media printed materials and electronic documentation These license terms are an agreement between You Licensee and CCS for use of the Software Software By installation copy download or otherwise use of the Software you agree to be bound by all the provisions of this License Agreement 1 LICENSE CCS grants Licensee a license to use in one of the two following options 1 Software may be used solely by single user on multiple computer systems 2 Software may be installed on single computer system for use by multiple
40. users Use of Software by additional users or on a network requires payment of additional fees Licensee may transfer the Software and license to a third party and such third party will be held to the terms of this Agreement All copies of Software must be transferred to the third party or destroyed Written notification must be sent to CCS for the transfer to be valid 2 APPLICATIONS SOFTWARE Use of this Software and derivative programs created by Licensee shall be identified as Applications Software are not subject to this Agreement Royalties are not be associated with derivative programs 3 WARRANTY CCS warrants the media to be free from defects in material and workmanship and that the Software will substantially conform to the related documentation for a period of thirty 30 days after the date of purchase CCS does not warrant that the Software will be free from error or will meet your specific requirements If a breach in warranty has occurred CCS will refund the purchase price or substitution of Software without the defect 4 LIMITATION OF LIABILITY AND DISCLAIMER OF WARRANTIES CCS and its suppliers disclaim any expressed warranties other than the warranty 355 CCS C 10082015 contained in Section 3 herein all implied warranties including but not limited to the implied warranties of merchantability of satisfactory quality and of fitness for a particular purpose regarding the Software Neither CCS nor its su
41. usually pin B6 and the ICSP data line is the PIC s transmit pin usually pin B7 MAX_ERROR x Specifies the max error percentage the compiler can set the RS232 baud rate from the specified baud before generating an error Defaults to 3 if not specified Serial Buffer Options RECEIVE_BUFFER x Size in bytes of UART circular receive buffer default if not specified is zero Uses an interrupt to receive data supports RDA interrupt or external interrupts TRANSMIT_BUFFER x Size in bytes of UART circular transmit buffer default if not specified is zero TXISR If TRANSMIT_BUFFER is greater then zero specifies using TBE interrupt for transmitting data Default is NOTXISR if TXISR or NOTXISR is not specified TXISR option can only be used when using hardware UART NOTXISR If TRANSMIT_BUFFER is greater then zero specifies to not use TBE interrupt for transmitting data Default is NOTXISR if TXISR or NOTXISR is not specified and XMIT_BUFFER is greater then zero Flow Control Options RTS PIN_xx Pin to use for RTS flow control When using FLOW_CONTROL_MODE this pin is driven to the active level when it is ready to receive more data In SIMPLEX_MODE the pin is driven to the active level when it has data to transmit FLOW_CONTROL_MODE can only be use when using RECEIVE_BUFFER RTS_LEVEL x Specifies the active level of the RTS pin HIGH is active high and LOW is active low Defaults to LOW if not specified CTS PIN_xx Pin to use for CTS flow co
42. value is a float A float Computes the base ten logarithm of the float x If the argument is less than or equal to zero or too large the behavior is undefined Note on error handling If errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Domain error occurs in the following cases e log10 when the argument is negative All devices INCLUDE lt math h gt db logl0 read_adc 5 0 255 10 None log expQ pow 205 CCS C 10082015 longjmp Syntax Parameters Returns Function Availability Requires Examples Example Files Also See make8g Syntax Parameters Returns Function Availability Requires Examples 206 longjmp env val env The data object that will be restored by this function val The value that the function setjmp will return If val is O then the function setjmp will return 1 instead After longjmp is completed program execution continues as if the corresponding invocation of the setjmp function had just returned the value specified by val Performs the non local transfer of control All devices INCLUDE lt setjmp h gt longjmp jmpbuf 1 None setimp i8 MAKE8 var offset var is a 16 or 32 bit integer offset is a byte offset of 0 1 2 or 3 An 8 bit integer Extracts the b
43. values is a list of variables separated by commas stream is a stream identifier 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 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 nis 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 263 CCS C 10082015 Lu Ld Lo x or X Lx or LX Li f g ore 264 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 a
44. 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 Nothing To setup the Proportional Integral Derivative PID module and to set the input coefficients K1 K2 and K3 All devices with a PID module Constants are defined in the device s h file Built in Functions Examples setup pid PID MODE PID 10 3 50 Example Files None Also See 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 PAR_CONTINUE_IN_IDLE PAR_INTR_ON_RW Interrupt on read write PAR_INC_ADDR Increment address by 1 every read write cycle PAR_MASTER_MODE_1 Master Mode 1 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 value This value determines which address lines are active from the available 16 address lines PMAO PMA15 Returns Undefined Function Configures various options in the PMP module The options are pres
45. 8 control word word control word 0x85 control word upperByte 0x42 None bit byte locate reserve Named Registers Type Specifiers Type Qualifiers Enumerated Types Structures amp Unions Typedef 129 CCS C 10082015 zero_ram Syntax ZERO_RAM Elements None Purpose This directive zero s out all of the internal registers that may be used to hold variables before program execution begins Examples zero_ ram void main Example ex_cust c Files Also See None 130 BUILT IN FUNCTIONS BUILT IN FUNCTIONS The CCS compiler provides a lot of built in functions to access and use the PIC microcontroller s peripherals This makes it very easy for the users to configure and use the peripherals without going into in depth details of the registers associated with the functionality The functions categorized by the peripherals associated with them are listed on the next page Click on the function name to get a complete description and parameter and return value descriptions PONY AE E E E EEA E E A A E AA 137 sin cos tan asin acos atan sinh cosh tanh atan2 cccccccncccncnenonenenennnenenenenenineneneneneneninenos 137 TI O aca 138 E 139 A A 140 A O LE 140 DI BOCES ccoo E ao cia 141 atoi IOE 10 E 74 UN OCRE OOO OU be avccdonyed T 142 EEEE LE Pousada ei 142 Al disable MMSE 0 eiie nineio O 143 al enable WUE Fe eee A E eE ea a raa aaaea E eaor Eaa
46. Compiler error file used to link Windows 8 apps to CCSLoad CCS C 10082015 ccssi used to link Windows 8 apps to Serial Port Monitor ow Invoking the Command Line Compiler The command line compiler is invoked with the following command CESC options cfilename Valid options FB Select PCB 12 bit D Do not create debug file FM Select PCM 14 bit DS Standard COD format debug file FH Select PCH PIC18XXX DM MAP format debug file YX Optimization level x 0 9 DC Expanded COD format debug file DF Enables the output of an COFF debug file FS Select SXC SX EO Old error file format ES Standard error file T Do not generate a tree file T Create call tree TRE A Do not create stats file STA A Create stats file STA EW Suppress warnings use with EA EW Show warning messages E Only show first error EA Show all error messages and all warnings EX 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 08xxx 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 Keep compile status window up after compile Pxx Keep status window up for xx seconds after compile PN Keep status window up
47. E E E E A O 333 Srand Jenene aena A E E A E O ee aS 333 STANDARD STRING FUNCTIONS memchr memcmp strcat strchr stremp strcoll strespn strerror stricmp strlen strlwr strncat strncmp strncpy strpbrk strrchr strspn strstr strxfrm 334 SUCPY SUPCOPY AO 335 SO ad eee ed E ee eS 336 SMOK are a aaa 336 LADLE A E A E A E T E A E A E ete cuted mature oes 338 AOUN O E AEEA EEE EE T 338 O E E A E E E 339 tolower toupper Jesse i nrar N een tes tie viene E R Se N int eee 339 touchpad gala circa Sage alada 340 touchpad hist til Pcia art lt brida dci cadera 341 t uchp d Stale Joea r a Ta a aa a E aer aa e Ea eaa a a a a ee Ee a a ea iea EE a A aaia 342 X b ffer avalable i cia o aa sia dia ee need lain 342 t buffer bytes cani a aa avis aa Aaa E aa Jaen bite teense eee ar ae 343 NOLEN ISTERANI tod ooo 344 A T E E T E 344 AREIA O A EEEE AA A A A E ET 345 hV EEI Ke EE E E ro de Io E A ee a ee Sas 345 Write Danko a eed ee ei ee es 346 write configuration memory inside E Ea aA ie a incio cri 347 A O T E E E sani sna tenses igneag dave abisesiancapasseie 347 CCS C 10082015 write external Memory Jo viii ap bea 348 write extended ram iii ed he aiii n 349 Write program O tg ensue enh aa a a dicey Taaa aaa Aae aA EAE a EENE apao a aaa E AE a Ea S TETERE a iiaia 349 O AR 350 Standard C Include Files o anta iaa 351 E 351 E CA 351 ode 352 A A 352 semp Mireia aaa 352 A Hie ERE
48. Examples Example Files Also See log Syntax Parameters Returns Function 204 for i 0 i lt 9 i lcd_symbol DIGIT MAP i DIGITI delay ms 1000 ex 92lcd c setup Icd lcd load led_contrast Internal LCD Overview result Idexp value exp value is float exp is a signed int result is a float with value result times 2 raised to power exp The Idexp function multiplies a floating point number by an integral power of 2 All devices INCLUDE lt math h gt float result result ldexp 5 0 result is 5 None frexp exp log log10 modf result log value value is a float A float Computes the natural logarithm of the float x If the argument is less than or equal to zero or too large the behavior is undefined Availability Requires Examples Example Files Also See log10 Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions Note on error handling errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Domain error occurs in the following cases e log when the argument is negative All devices INCLUDE lt math h gt Inx log x None log10 exp pow result log10 value
49. High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices Constants are defined in the device s h file set_hspwm_event HSPWM SPECIAL EVENT INT ENABLED 0x1000 None 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_override Syntax Parameters Returns Function Availability Requires Examples 270 set_hspwm_override unit setting 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 HSPWM_FORCE_L_1 HSPWM_FORCE_L_0 Undefined Setup and High Speed PWM uoverride settings Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None setup _hspwm override 1 HSPWM_ FORCE H 1 HSPWM_ FORCE L 0 Example Files Also See Built in Functions None 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 set
50. I A ES 255 EE A E E E E E E E E 256 PROS MSGI E E E E E E 256 DE SED EEA E ON 257 A E O 257 APR A A canbetec sues A A E T 258 PE WUE o aa EEA 258 Ts O A A E eamplenccatauannwaieence 259 O 259 ASI E A ea AT 260 NOS WA Ys O AA AN 260 A A O NS 261 Sel Bac CR Aena ee ee id 262 Gt UNO M e E CORO OOOO On NA 262 A A A E 263 SECO SAI coco E E E maha S EE 265 Sel cog dead bardi e beat a 266 R O 266 AAE L E T E E T 267 Set dedicated ade cal Jenie ia 268 Sat ANT AU NN 269 set hspwm_event set hspwm event _secondary cccccecsceccessnececseceeeeesseeeeessnaeeeeseaeeeeseeeeeesseeeeeescnneessnaees 269 E OS A o E E E E ES 270 Maa a T 271 Sel NCO IME Wale E E E A E A A ids es TT 272 A O E E E E E 272 set power pwin DUST Ko ci oda ed 273 SL CEE WWII TAU Bo cnc foe cea cd pate ccengees Seebaete fevieseavaeeapamedevapesvon used sadeipananssd ocinasuestananceaesdesGennencesdeduslteesteteadeasties 273 A EE A A E E EE fasaavelaeusus E EE GEHe tes eee 274 Beet e E E E E dias ii a ii cen 274 set pwm1 duty set pwm2 duty set pwm3 duty set pwm4 duty set_pwm5 duty 275 set pwm1 offset set pwm2 offset set pwm3 offset set pwm4 offset set pwm5 offset set pwm6_ Offset cccscccccsssecsseneeeessneeeeeseeeseseaeeecssanecesaceeeeessaeeseseaeeeesseeeeeseneeesssnneessssees 276 set pwm1 period set pwm2 period set pwm3 period set pwm4 period set pwm5 period set pwm periodi Di edi seventeen 277 set pwm1
51. If the keyword const is used before the identifier the identifier is treated as a constant Constants should be initialized and may not be changed at run time This is an easy way to create lookup tables The rom Qualifier puts data in program memory with 3 bytes per instruction space The address used for ROM data is not a physical address but rather a true byte address The amp operator can be used on ROM variables however the address is logical not physical The syntax is const type id cexpr value 30 Data Definitions For example Placing data into ROM const int table 16 0 1 2 15 Placing a string into ROM const char cstring 6 hello Creating pointers to constants const char cptr cptr string The org preprocessor can be used to place the constant to specified address blocks For example The constant ID will be at 1C00 ORG 0x1C00 Ox1COF CONST CHAR ID 10 123456789 Note Some extra code will precede the 123456789 The function label_address can be used to get the address of the constant The constant variable can be accessed in the code This is a great way of storing constant data in large programs Variable length constant strings can be stored into program memory A special method allows the use of pointers to ROM This method does not contain extra code at the start of the structure as does constant For example char rom commands putlget status shutdown The compiler allows
52. PSMC_EVENT_C40UT PSMC_EVENT_IN_PIN undefined This function is used when system noise can cause an incorrect trigger from one of the specified events This function allows for ignoring these events for a period of time around either edge of the signal See setup_psmc for a definition of a tick Pass a 0 or FALSE for the events to disable blanking for an edge All devices equipped with PSMC module None setup psmc psmc_deadband psmc_sync psmc modulation psmc_shutdown psmc_duty psmc_freq_adjust psmc_pins psmc_deadband Syntax Parameters Returns Function 226 psmc_deadband unit rising_edge falling_edge unit is the PSMC unit number 1 4 rising_edge is the deadband time in ticks after the signal goes active If this function is not called 0 is used falling_edge is the deadband time in ticks after the signal goes inactive If this function is not called 0 is used undefined This function sets the deadband time values Deadbands are a gap in time where both sides of a complementary signal are forced to be inactive The time values are in ticks See setup_psmc for a definition of a tick Availability Requires Examples Example Files Also See Built in Functions All devices equipped with PSMC module undefined 5 tick deadband when the signal goes active psmc_deadband 1 5 0 None setup psmc psmc_sync psmc_blanking psmc_modulation
53. Parameters Returns Function Availability Examples Example Files Also See smt1_start smt2_start None Nothing To have the Signal Measurement Timer SMT module start acquiring data Only devices with a built in SMT module smtelfstanmt 07 None smtx_status setup smtx smtx_stop smtx_update smtx_reset timer smtx_read smtx write smtx_status Syntax Parameters Returns Function Availability Examples Example Files Also See value smt1_status value smt2_status None The status of the SMT module To return the status of the Signal Measurement Timer SMT module Only devices with a built in SMT module status SMS tatu None setup smtx stmx_start smtx_stop smtx_update smtx reset timer smtx_read smtx_write smtx_stop Syntax Parameters Returns smt1_stop smt2_stop None Nothing 325 CCS C 10082015 Function Availability Examples Example Files Also See Configures the Signal Measurement Timer SMT module Only devices with a built in SMT module smt1_stop None smtx_status stmx_start setup smtx smtx_update smtx reset timer smtx_read smtx_write smtx_write Syntax Parameters Returns Function Availability Examples Example Files Also See smt1_write which value smt2_write which value which Specifie
54. Relevant Interrupts INT_AD INT_ADOF Relevant Include Files None all functions built in Relevant getenv parameters ADC_CHANNELS ADC_RESOLUTION Example Code DEVICE ADC 10 long value setup _adc ADC_CLOCK_INTERNAL setup_adc_ports ALL_ANALOG set_adc_channel 0 delay_us 10 value read_adc read_adc ADC_START_ONLY value read_adc ADC_READ ONLY 40 Sets up the a d mode like off the adc clock etc Sets the available adc pins to be analog or digital Specifies the channel to be use for the a d call Starts the conversion and reads the value The mode can also control the functionality Returns 1 if the ADC module has finished its conversion Configures the read_adc return size For example using a PIC with a 10 bit A D you can use 8 or 10 for xx 8 will return the most significant byte 10 will return the full A D reading of 10 bits Interrupt fires when a d conversion is complete Interrupt fires when a d conversion has timed out Number of A D channels Number of bits returned by read_adc enables the a d module and sets the clock to internal adc clock sets all the adc pins to analog the next read_adc call will read channel O a small delay is required after setting the channel land before read starts the conversion and reads the result and store it in value only starts the conversion reads the result of the last conversion and store it in value Assuming Functiona
55. See 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 O sets up ADC pair ANO and AN1 1 sets up ADC pair AN2 and ANS 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 Undefined 296 Function Availability Requires Examples Example Files Also See Built in Functions 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 Only on dsPIC33FJUxxGSxxx devices Constants are define in the device h file 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 None setup high speed adc read high speed adc high speed adc done setup _hspwm_blanking Syntax Parameters Returns Function Ava
56. See the device s h file for all the options Some typical options include COG_AUTO_RESTART COG_SHUTDOWN_ON_C10UT COG_SHUTDOWN_ON_C20UT 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 undefined 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 All devices with a COG module 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 None set_cog dead band set cog phase set_cog blanking cog status cog restart setup_crc polynomial terms polynomial This will setup the actual polynomial in the CRC engine The power of each term is passed separated by acomma 0 is allowed but ignored The following define is added to the device s header file to enable little endian shift direction CRC_LITTLE_ENDIAN Returns Function Availability Examples Example Files Also See Built in Functions Nothing Configures the CRC
57. Syntax 142 at_clear_interrupts interrupts Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions interrupts an 8 bit constant specifying which AT interrupts to disable The constants are defined in the device s header file as AT_PHASE_INTERRUPT AT_MISSING_PULSE_INTERRUPT AT_PERIOD_INTERRUPT AT_CC3_INTERRUPT AT_CC2_INTERRUPT AT_CC1_INTERRUPT Nothing To disable the Angular Timer interrupt flags More than one interrupt can be cleared at a time by or ing multiple constants together in a single call or calling function multiple times for each interrupt to clear All devices with an AT module Constants defined in the device s header file INT AT1 voidl_isr void FU if at_interrupt active AT PERIOD INTERRUPT handle period interrupt ERIOD_INTERRUPT FU at_clear interrupts AT_ FU if at_interrupt active AT PHASE INTERRUPT 7 HASE INTERRUPT handle phase _ interrupt FU at_clear interrupts AT_ None 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 interrupt active at setup cc at set compare time at get capture at get status setup_at at
58. These functions perform basic Trigonometric functions sin returns the sine value of the parameter measured in radians cos returns the cosine value of the parameter measured in radians tan returns the tangent value of the parameter measured in radians asin returns the arc sine value in the range pi 2 pi 2 radians acos returns the arc cosine value in the range 0 pi radians atan returns the arc tangent value in the range pi 2 pi 2 radians atan2 returns the arc tangent of y x in the range pi pi radians sinh returns the hyperbolic sine of x cosh returns the hyperbolic cosine of x tanh returns the hyperbolic tangent of x Note on error handling If errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Domain error occurs in the following cases asin when the argument not in the range 1 1 acos when the argument not in the range 1 1 atan2 when both arguments are zero Range error occur in the following cases cosh when the argument is too large sinh when the argument is too large Availability All devices Requires INCLUDE lt math h gt Examples float phase Output one sine wave for phase 0 phase lt 2 3 141596 phase 0 01 set_analog voltage sin phase 1 Example Files ex_tank c Also See log log10 exp pow sart adc_done Syntax va
59. XORWF f d PreProcessor BCF f b BSF f b BTFSC f b BTFSS f b ANDLW k CALL k CLRWDT GOTO k IORLW k MOVLW k RETLW k SLEEP XORLW OPTION TRIS k 14 Bit ADDLW k SUBLW k RETFIE RETURN f may be a constant file number or a simple variable d may be a constant 0 or 1 or W or F f b may be a file as above and a constant 0 7 or it may be just a bit variable reference k may be a constant expression Note that all expressions and comments are in C like syntax PIC 18 ADDWF f d ADDWFC f d ANDWF f d CLRF f COMF f d CPFSEQ f CPFSGT f CPFSLT f DECF f d DECFSZ f d DCFSNZ f d INCF f d INFSNZ f d IORWF f d MOVF f d MOVFF fs d MOVWF f MULWF f NEGF f RLCF f d RLNCF f d RRCF f d RRNCF f d SETF f SUBFWB f d SUBWF f d SUBWFB f d SWAPF f d TSTFSZ f XORWF f d BCF f b BSF f b BTFSC f b BTFSS f b BTG f d BC n BN n BNC n BNN n BNOV n BNZ n BOV n BRA n BZ n CALL n s CLRWDT DAW GOTO n NOP NOP POP PUSH RCALL n RESET RETFIE s RETLW k RETURN s SLEEP ADDLW k ANDLW k IORLW k LFSR fk MOVLB k MOVLW k MULLW k RETLW k SUBLW k XORLW k TBLRD A TBLRD TBLRD TBLRD TBLWT i TBLWT TBLWT TBLWT The compiler will set the access bit depending on the value of the file register If there is just a variable identifier in the asm block then the compiler inserts an amp before it And if it is an expression it must be a valid C expression that evaluates to a constant no amp here In C an un subscripted array name is a pointer and
60. a constant no need for amp 79 CCS C 10082015 bit Syntax BIT id x y Elements id is a valid C identifier xis a constant or a C variable yis aconstant 0 7 Purpose A new C variable one bit is created and is placed in memory at byte x and bit y This is useful to gain access in C directly to a bit in the processors special function register map It may also be used to easily access a bit of a standard C variable Examples bit TOIF 0x b 2 mts 07 Clear Timer 0Ointerrupt flag cite re SU te toit result_odd result 0 e esulitkodd Example ex_glint c Files Also See BYTE RESERVE LOCATE WORD _ buildcount _ Only defined if Options gt Project Options gt Global Defines has global defines enabled This id resolves to a number representing the number of successful builds of the project build Syntax BUILD segment address BUILD segment address segment address BUILD segment start end BUILD segment start end segment start end BUILD nosleep Elements segment is one of the following memory segments which may be assigned a location MEMORY RESET or INTERRUPT address is a ROM location memory address Start and end are used to specify a range in memory to be used 80 Purpose Examples Example Files Also See byte Syntax Elements Purpose Examples PreProcessor start is the first ROM location and end is the last ROM location
61. a max value of 255 void Configures the alarm of the RTCC module Devices that have the RTCC module Nothing setup _rtc_alarm RTC_ALARM ENABLE RTC_ALARM HOUR 3 None rtc_read rtc_alarm read rtc_alarm write setup rtc_alarm rtc_write setup _rtc setup sd_adc Syntax 314 setup_sd_adc settings1 settings 2 settings3 Parameters Returns Function Availability Examples Example Files Also See Built in Functions 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 SDADC_NO_HALT SDADC_GAIN_1 SDADC_NO_DITHER SDADC_SVDD_SVSS SDADC_BW_NORMAL oof W PY 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 SD1CONS3 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 Nothing To setup the Sigma Delta Analog to Digital Converter SD ADC module Only devices with a SD ADC module 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 None set_sd_a
62. as requested even if there is not enough stack space to execute Examples separate swapboyte int a int b ine tt t a a b xb t Example ex_cust c Files Also See INLINE serialize Syntax SERIALIZE id xxx next x file filename txt listfile filename txt prompt text log filename txt or SERIALIZE dataees x binary x next x file filename txt listfile filename txt prompt text log filename txt Elements id xxx Specify a C CONST identifier may be int8 int16 int32 or char array Use in place of id parameter when storing serial number to EEPROM dataee x The address x is the start address in the data EEPROM 109 CCS C 10082015 Purpose Examples Example Files Also See 110 binary x The integer x is the number of bytes to be written to address specified or string x The integer x is the number of bytes to be written to address specified unicode n lf n is a 0 the string format is normal unicode For n gt 0 n indicates the string number in a USB descriptor Use only one of the next three options file filename txt The file x is used to read the initial serial number from and this file is updated by the ICD programmer It is assumed this is a one line file with the serial number The programmer will increment the serial number listfile filename txt The file x is used to read the initial serial number from and this file is u
63. bit Input Capture module Nothing setup_timer2 TMR_INTERNAL TMR DIV BY 1 TMR 32 BIT setup capture 1 CAPTURE_FE CAPTURE_TIMER2 CAPTURE 32 BIT while TRUE timerValue get_capture32 1 TRUE printf Capture 1 occurred at SLU timerValue None setup_capture setup_compare get capture Input Capture Overview get_hspwm_capture Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result get_hspwm_capture unit unit The High Speed PWM unit to set Unsigned in16 value representing the capture PWM time base value ieee the captured PWM time base value from the leading edge detection on the current limit input Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None result get_hspwm capture 1 None setup hspwm_unit set hspwm_phase set hspwm_duty set hspwm_event 179 CCS C 10082015 setup hspwm_blanking setup hspwm_trigger set hspwm_override setup hspwm chop clock setup hspwm_ unit chop clock setup hspwm setup hspwm_secondary get_nco_accumulator Syntax Parameters Returns Availability Examples Example Files Also See value get_nco_accumulator none current value of accumulator On devices with a NCO module value get_nco accumulator Non
64. capture time get_capture_time Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result get_capture_time stream stream optional parameter specifying the stream defined in JSE CAPTURE An int16 value representing the last capture time To get the last capture time All devices USE CAPTURE USE CAPTURE INPUT PIN C2 CAPTURE_ RISING TIMER 1 FASTEST result get capture time None use capture get capture event get_capture32 Syntax Parameters Returns 178 result get_capture32 x wait x is 1 16 and defines which input capture result buffer modules to read from wait is an optional parameter specifying if the compiler should read the oldest result in the bugger or the next result to enter the buffer A 32 bit timer value Function Availability Requires Examples Example Files Also See Built in Functions If wait is true the current capture values in the result buffer are cleared and the next result to be sent to the buffer is returned If wait is false the default setting the first value currently in the buffer is returned However the buffer will only hold four results while waiting for them to be read so if get_capture32 is not being called for every capture event When wait is false the buffer will fill with old capture values and any new results will be lost Only devices with a 32
65. character following the left bracket up to the matching right bracket Unless the first character after the left bracket is a 4 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 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 Built in Functions 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 Availability Requires Examples Example Files Also See function A string composed of ordinary non white space characters is executed by reading the next character of the string If one of the inputted chara
66. chips with multiple ICSP ports specify the port number being used The default is 1 Prevents WRITE_EEPROM from hanging while writing is taking place When used do not write to EEPROM from both ISR and outside ISR Allows interrupts to occur while the write_eeprom operations is polling the done bit to check if the write operations has completed Can be used as long as no EEPROM operations are performed during an ISR Use this option for high low priority interrupts on the PIC 18 No 0 before a decimal pint on f numbers less than 1 Overloading of functions is now supported Requires the use of the keyword for overloading Default mode for overloading A new way to pass constant strings to a function by first copying the string to RAM and then passing a pointer to RAM to the function Uses the ANSI keyword CONST definition making CONST variables read only rather than located in program memory Uses the CCS compiler traditional keyword CONST definition making CONST variables located in program memory Enables interrupt nesting for PIC24 dsPIC30 and dsPIC33 devices Allows higher priority interrupts to interrupt lower priority interrupts ISR functions preceeded by a int_xxx will use a RETURN opcode instead of the RETFIE opcode This is not a commonly used option used rarely in cases where the user is writing their own ISR handler Normally the compiler sets all I O pins to digital and turns off the comparator This option
67. clock source the clock divisor and the events that can cause the period to start Sources e PSMC_SOURCE_FOSC PSMC_SOURCE_64MHZ PSMC_SOURCE_CLK_PIN Divisors e PSMC_DIV_1 e PSMC_DIV_2 e PSMC_DIV_4 e PSMC_DIV_8 Events e 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 Returns Function Availability Requires Examples Example Files Also See Built in Functions rise_time is the time in ticks that the signal goes active after the start of the period if the event is PSMC_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 PSMC_EVENT_C10UT e PSMC_EVENT_C20UT PSMC_EVENT_C30UT PSMC_EVENT_C40UT PSMC_EVENT_PIN_PIN undefined 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 Itis 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 func
68. defined in the device s header file as AT_PHASE_INTERRUPT AT_MISSING_PULSE_INTERRUPT AT_PERIOD_INTERRUPT AT_CC3_INTERRUPT AT_CC2_INTERRUPT AT_CC1_INTERRUPT Nothing To enable the Angular Timer interrupts More than one interrupt can be enabled at a time by or ing multiple constants together in a single call or calling function multiple times for each interrupt to be enabled Availability Requires Examples Example Files Also See Built in Functions All devices with an AT module Constants defined in the device s header file at_enable interrupts AT PHASE INTERRUPT at_enable interrupts AT PERIOD INTERRUPT AT CC1 INTERRUPT None setup_at at_set_resolution at_get_resolution at_set_missing_pulse_delay at_get_missing_pulse_delay at_get_phase_counter at_set_set_point at_get_set_point at_get_set_point at_get_set_point_error at_disable_interrupts at_clear_interrupts at_interrupt_active at_setup_cc at_set_compare_time at_get_capture at_get_status at_get_capture Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result at_get_capture which which an 8 bit constant specifying which AT Capture Compare module to get the capture time from can be 1 2 or 3 A 16 bit integer To get one of the Angular Timer Capture Compare modules capture time All devices with an AT modul
69. devices h file For example 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 undefined 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_O 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 All devices Constants are defined in the devices h file setup_counters RTCC_INTERNAL WDT_2304MS None setup wat setup timer 0 see header file for device selected setup_cog mode shutdown setup_cog mode shutdown sterring mode the setup of the COG module See the device s h file for all options Some typical options include COG_ENABLED 291 CCS C 10082015 Returns Function Availability Examples Example Files Also See setup _crc Syntax Parameters 292 COG_DISABLED COG_CLOCK_HFINTOSC COG_CLOCK_FOSC shutdown the setup for the auto shutdown feature of COG module
70. devices with a CLC module Undefined setup _clcl CLC_ ENABLED CLC MODE AND OR None clcx_setu ate clcx_setup input setup_comparator Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 290 setup_comparator mode 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 AO_A3 A1_A2 AO_A2 A1_A2 NC_NC_A1_A2 NC_NC_NC_NC AO_VR_A1_VR A3_VR_A2 VR A0_A2 A1_A2 OUT_ON_A3_A4 A3_A2 A1_A2 undefined Sets the analog comparator module The above constants have four parts representing the inputs C1 C1 C2 C2 This function is only available on devices with an analog comparator Constants are defined in the devices h file Sets up two independent comparators C1 and C2 Cl uses AO and A3 as inputs and and C2 uses Al and A2 as inputs setup _comparator A0_A3_ Al A2 ex_comp c Analog Comparator overview Built in Functions setup _counters Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup _cog Syntax Parameters setup_counters ricc_state ps_state rtcc_state may be one of the constants defined in the devices h file For example RTCC_INTERNAL RTCC_EXT_L_TO_H or RTCC_EXT_H_TO_L ps_state may be one of the constants defined in the
71. directive will accept files with this extension and decrypt them as they are read This allows include files to be distributed without releasing the source code Purpose Text from the specified file is used at this point of the compilation If a full path is not specified the compiler will use the list of directories specified for the project to search for the file If the filename is in then the directory with the main source file is searched first If the filename is in lt gt then the directory with the main source file is searched last Examples include lt 16C54 H gt include lt C INCLUDES COMLIB MYRS232 C gt Example ex_sqw c Files Also See None inline Syntax INLINE Elements None Purpose Tells the compiler that the function immediately following the directive is to be implemented INLINE This will cause a duplicate copy of the code to be placed everywhere the function is called This is useful to save stack space and to increase speed Without this directive the compiler will decide when it is best to make procedures INLINE Examples inline swapbyte int amp a int amp b ae eg p a b b t PreProcessor Example ex_cust c Files Also See SEPARATE int_xxxx Syntax INT_AD Analog to digital conversion complete INT_BUSCOL Bus collision INT_BUTTON Pushbutton INT_CANIRX An invalid message has occurred on the CAN bus INT_CANRX1 CAN Receive buffer 1 has received a new message INT
72. dite aE aaa eth sgeschhaadecaueeasecdessheciceensueisevys EA EEEa ESEE apai 152 at set set point ici o ede Ee ee ee aas 152 o EE E E a ed eed ed Ae eg A E 153 O A O E A A tet cubevtes 154 O A E E E E T 154 DIOS a a aia tol des 155 brownout enable Hita A att 156 DSC iii E eect T eae ee 156 CAllOC este eeceies exces ee sect shee sate aut ecu ca vis ceca ss 2a gods ue ven a a es eaeten a saat tartan Dies buctetey a aN e 157 ANOS 157 clc1_setup_gate clc2_setup_gate clc3_setup_gate clc4_Setup_gatel cccocncoccconncininccocaccnoconinanannncnancn ns 158 clc1_setup_input clc2_setup_input clc3_setup_input clc4_Setup_input oooooocccccccincnanocicinnconanananacinanin no 159 CACA IMTSMRUPtE ii a ia ta po lt 160 clear_pwm1_interrupt clear_pwm2_interrupt clear_pwm3_interrupt clear_pwm4_interrupt clear_pwm5_interrupt clear_pwm6_interrupt ooococonnoncconanacanonencnononencncnnnon cnn nono cnn nn nor rr nan n cnn ran n nn nn rn nera n nr nnnnnn 160 O ANA 161 COG FOSTAIT A scarves poet hi Peed sedan tcetaesceeetenet ae anar eeta anaa eed EE a ates Iie eases ie Ep aaO rakes 162 cres calch cre cale8 creCale16 still ra dle 162 oai aolo e iii Ets 163 CWgustatust ici a A Da E e e ee S 163 Westin A E E A E EN 164 dac write ici ia rie aaa ia a a 164 delay Cycles irradia even da anda cocine cias Didi e 165 O seceeec AEE AA thcledeneta ce A A E E TAT 165 delay s J a a eS Aa 166 disable interrupts O cint
73. engine register with the polynomial Only devices with a built in CRC module Setup cre 12 5 CRC Polynomial is e serle IS 3 lye CRC Polynomial is x x x x1 1 None crc_init crc_calc crc_calc8 setup_cwg Syntax Parameters Returns Function Availability Examples setup_cwg mode shutdown dead_time_rising dead_time_falling 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 undefined Sets up the CWG module the auto shutdown feature of module and the rising and falling dead times of the module All devices with a CWG module setup _cwg CWG_ENABLED CWG_OUTPUT_A CWG OUTPUT B 293 CCS C 10082015 CWG INPUT PWM1 CWG SHUTDOWN ON FLT 60 30 Example Files None Also See cwg status cwg restart setup_dac Syntax setup_dac mode Parameters mode The valid options vary depending on the device See the devices h file for all options So
74. enumerated by the PC If the device has been enumerated by the PC that means it is in normal operation mode and you can send receive packets Places the packet of data into the specified endpoint buffer Returns TRUE if success FALSE if the buffer is still full with the last packet Sends the following data to the specified endpoint usb_puts differs from usb_put_packet in that it will send multi packet messages if the data will not fit into one packet Returns TRUE if the specified endpoint has data in it s receive buffer Reads up to max bytes from the specified endpoint buffer and saves it to the pointer ptr Returns the number of bytes saved to ptr Reads a message from the specified endpoint The difference usb_get_packet and usb_gets is that usb_gets will wait until a full message has received which a message may contain more than one Relevant CDC Functions Functional Overview packet Returns the number of bytes received A CDC USB device will emulate an RS 232 device and will appear on your PC as a COM port The follow functions provide you this virtual RS 232 serial interface Note When using the CDC library you can use the same functions above but do not use the packet related function such as usb_kbhit usb_get_packet etc usb_cdc_kbhit usb_cdc_getc usb_cdc_putc c usb_cdc_putc_fast c usb_cdc_puts str usb_cdc_putready Relevant Preporcessor None Relevant Interrupts
75. for each task This function will return only when rtos_terminate is called 258 Availability Requires Examples Also See rtos_signal Built in Functions All devices USE RTOS rtos_run rtos terminate The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires Examples Also See rtos_ stats rtos_ signal sem sem is a global variable that represents the current availability of a shared system resource a semaphore None 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 All devices USE RTOS rtos_signal uart_use ritos wait The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters rtos_stats task amp stat 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 lused unsigned int16 task_min_ticks the minimum number of ticks lused unsigned int16 task_max_ticks the maximum number of ticks 259 CCS C 10082015 Returns Function Availability Requires Examples Also See used unsigned int16 hns_per_tick lus ticks hns_per_tick 10 Undefined This function returns the
76. get the clock If this device is a SLAVE then either call spi_read to wait for the clock and data or use_spi_data_is_in to determine if data is ready This function is only available on devices with SPI hardware Nothing data_in spi_read out_data ex_spi c spi write spi data is in SPI Overview spi_read_16 spi_read2_16 spi_read3_16 spi_read4_16 Syntax Parameters Returns Function Availability Requires Examples value spi_read_16 data value spi_read2_16 data value spi_read3_16 data value spi_read4_16 data data optional parameter and if included is a 16 bit int A 16 bit int Return a value read by the SPI If a value is passed to the spi_read_16 the data will be clocked out and the data received will be returned If no data is ready spi_read_16 will wait for the data is a SLAVE or return the last DATA clocked in from spi_write_16 If this device is the MASTER then either do a spi_write_16 data followed by a spi_read_16 or do a spi_read_16 data These both do the same thing and will generate a clock If there is no data to send just do a spi_read_16 0 to get the clock If this device is a slave then either call spi_read_16 to wait for the clock and data or use_spi_data_is_in to determine if data is ready This function is only available on devices with SPI hardware NThat the option SPI_MODE_16B be used in setup_spi function or t
77. gt about and clicking other versions Command Line users use start gt all programs gt PIC C gt compiler version Two directories are used outside the PICC tree Both can be reached with start gt all programs gt PIC C File pjt ccspj st sym sta tre hex cof cod rtf rvf dgr esym xsym osym err ccslo ad Overview 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 APICC Formats This is the source file containing user C source code These are standard or custom header files used to define pins register register bits functions and preprocessor directives This is the older pre Version 5 project file which contains information related to the project This is the project file which contains information related to the project This is the listing file which shows each C source line and the associated assembly code generated for that line The elements in the LST file may be selected in PCW under Options gt Project gt Output Files CCS Basic Standard assembly instructions with Opcodes Includes the HEX opcode for each instruction Old Standard Symbolic Shows variable names instead of addresses This is the symbol map which shows each register location and what program variables are stored in each location The statis
78. how many decimal places to implement 26 Data Definitions unsigned Data is always positive This is the default data type if not specified signed Data can be negative or positive volatile Tells the compiler optimizer that this variable can be changed at any point during execution const Data is read only Depending on compiler configuration this qualifier may just make the data read only AND OR it may place the data into program memory to save space see DEVICE const rom Forces data into program memory Pointers may be used to this data but they can not be mixed with RAM pointers void Built in basic type Type void is used to indicate no specific type in places where a type is required readonly Writes to this variable should be dis allowed _bif Used for compiler built in function prototypes on the same line _ attribute __ Sets various attributes SEE ALSO Declarations Type Specifiers Enumerated Types Structures amp Unions typedef Named Registers Enumerated Types enum enumeration type creates a list of integer constants enum lid id cexpr t One or more comma separated The id after enum is created as a type large enough to the largest constant in the list The ids in the list are each created as a constant By default the first id is set to zero and they increment by one If a cexpr follows an id that id will have the value of the constant expression an d the following list will increment
79. ignored Devices with i2c hardware USE 12C INT_SSP void ize isr state i2c_isr state if state i2c_read i c_read if state 0x80 i2c_read 2 if state gt 0x80 i2c write send buffer state 0x80 else if state gt 0 rcv_buffer state 1 i2c read 189 CCS C 10082015 Example Files Also See 2c_poll Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 2c_read Syntax Parameters Returns 190 ex_slave c i2c poll i2c_ speed i2c_ start i2c stop i2c_slaveaddr i2c write i2c_ read USE 12C 12C Overview i2c_poll i2c_poll stream stream optional specify the stream defined in USE 12C 1 TRUE or 0 FALSE The 12C_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 12C_READ will immediately return the byte that was received Devices with built in 12C USE 12C if i2c poll buffer index i2c read read data None i2c_speed i2c start i2c_ stop i2c_ slaveaddr i2c isr state i2c write i2c read USE 12C 12C Overview data i2c_read data i2c_read ack data i2c_read stream ack 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
80. inline funct_a int x int y Traditional if x 5 y xt3 funct_a amp a amp b funct_b int amp x int amp y Reference params if x 5 y xt3 funct_b a b Default Parameters Default parameters allows a function to have default values if nothing is passed to it when called int mygetc char c int n 100 This function waits n milliseconds for a character over RS232 If a character is received it saves it to the pointer c and returns TRUE If there was a timeout it returns FALSE gets a char waits 100ms for timeout mygetc amp c gets a char waits 200ms for a timeout mygetc amp c 200 Variable Argument Lists The compiler supports a variable number of parameters This works like the ANSI requirements except that it does not require at least one fixed parameter as ANSI does The function can be passed any number of variables and any 36 Function Definition data types The access functions are VA_START VA_ARG and VA_END To view the number of arguments passed the NARGS function can be used stdarg h holds the macros and va_list data type needed for variable number of parameters E include lt stdarg h gt A function with variable number of parameters requires two things First it requires the ellipsis which must be the last parameter of the function The ellipsis represents the variable argument list Second it requires one more variable before the el
81. into strings nostrspace Spaces terminate string entry default iosdefault All manipulators to default settings cout lt lt Enter number cin gt gt value cout lt lt Enter title cin gt gt strspace gt gt title cin gt gt datal i recordid gt gt datali xpos gt gt datali ypos gt gt datali sample string1 gt gt data Icdputc lt lt fEnter count Icdputc lt lt keypadgetc gt gt count read from keypad echo to led This syntax only works with user defined functions PREPROCESSOR PRE PROCESSOR DIRECTORY Pre processor directives all begin with a and are followed by a specific command Syntax is dependent on the command Many commands do not allow other syntactical elements on the remainder of the line A table of commands and a description is listed on the previous page Several of the pre processor directives are extensions to standard C C provides a pre processor directive that compilers will accept and ignore or act upon the following data This implementation will allow any pre processor directives to begin with PRAGMA To be compatible with other compilers this may be used before non standard features Examples Both of the following are valid INLINE PRAGMA INLINE UMN eae caine oes ata ats NO A A O O Hasm Hendasm asm ASIS cccccessssseceeecccceessscceececceuassecceeecceeusseceeccesucesseceeecensuagssececeeeneuanececeseteneeaaeceseeetseenaneeeseees
82. num i sum sum va_arg argptr int Example Files Also See va_end Syntax Parameters Returns Function Availability Requires Examples Example Files Also See va_start Syntax Parameters Built in Functions va_end argptr end variable processing return sum None nargs va_end va_start va_end argptr argptr is a special argument pointer of type va_list None A call to the macro will end variable processing This will facillitate a normal return from the function whose variable argument list was referred to by the expansion of va_start All devices INCLUDE lt stdarg h gt int foo int num int sum 0 int i va_list argptr create special argument pointer va_start argptr num initialize argptr for i 0 i lt num i sum sum va_arg argptr int va_end argptr end variable processing return sum None nargs va_start va_arg va_start argptr variable argptr is a special argument pointer of type va_list 345 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See variable The second parameter to va_start is the name of the last parameter before the variable argument list None The function will initialize the argptr using a call to the macro va_start All devices INCLUDE lt stdarg h gt int foo int num int sum
83. only if there are no errors PE Keep status window up only if there are errors Z Keep scratch files on disk after compile DF COFF Debug file lit Same as Except the path list is appended to the current list Set include directory search path for example I cApicclexamples cApiccimyinciludes If no l appears on the command line the PJT file will be used to supply the include file paths P Close compile window after compile is complete M Generate a symbol file SYM ICD xxx yyy Gxxx yyy STDOUT SETUP sourceline V Q Overview 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 Same as Hxxx yyy Brings up a help file Same as Outputs errors to STDOUT for use with third party editors 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 lt 16F887 h gt 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 LNist 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 th
84. phase set pwm2 phase set pwm3 phase set pwm4 phase set pwmio phasel set pwm PHASE cise ce ccuseteeccseseentecesccnadebesbeseye shad deheabicesasasahes eayetcennedeccasuseegensiecatanseses 278 et E A EA EEE E E ek chcecelgvessasebsad N E deuhescbeneaadscace acta salwases acegdiasnandnetansandioad 278 set rtcc set timerO set timer set timer2 set timer3 set timer4 set timer5 279 A A tapas E E 280 A E O EEA 280 set O OT 281 SAMA tias 281 A anduben egigaane E geceapeegaaas deat 282 E E enc EE ness Se ds a 283 A 0 AE Fe snes E A E E E E A E S 283 SIERE E E E A E E AA N A A E E A E E 284 E L A E E E E E A A E E E E E EE S 285 Ads o A O 285 A A 286 TETU E IA od iii 286 134 Built in Functions A nn falapens casupaedseaiibe ses dslieesdeadies E sane 287 setup ccp1 setup ccp2 setup ccp3 setup ccp4 setup ccp5 Setup CCDG ecccccccccncccncncncnnns 287 setup clc1 setup clc2 setup clc3 setup ClC4 ccccccccccccccconococennnncnnnnnononononononononnnnnnnnnnnnncnnonnnonananennnnnns 289 SEU MM ea lets 290 SOM e 291 Se A 291 STU e 10 0 COPPER OO E ceed phoeddedeaga ced u adi apaendnnnateadaapesandineeacabiaeareadeseateatiaeeeae 292 A A EE ising cavcee tuted sade save E E E TE 293 UNS CN Wee dices voi deatie E A in edcegs a da A ene sarees 294 setup dedicated A A a daban 294 AA TIVE J se scee cccecasessucctes ce ces sevecccttes cade eroii ai an EAE a EE ai ae E e aD E
85. prevents that action Both chip and options are optional so multiple DEVICE lines may be used to fully define the device Be warned that a DEVICE with a chip identifier will clear all previous DEVICE and FUSE settings Compilation mode selection The DEVICE directive supports compilation mode selection The valid keywords are CCS2 CCS3 CCS4 and ANSI The default mode is CCS4 For the CCS4 and ANSI mode the compiler uses the default fuse settings NOLVP PUT for chips with these fuses The NOWDT fuse is default if no call is made to restart_wat CCS4 This is the default compilation mode The pointer size in this mode for PCM and PCH is set to 16 if the part has RAM over OFF ANSI Default data type is SIGNED all other modes default is UNSIGNED Compilation is case sensitive all other modes are case insensitive Pointer size is set to 16 if the part has RAM over OFF CCS2 CCS3 var16 NegConst8 is compiled as var16 NegConst8 amp Oxff no sign extension Pointer size is set to 8 for PCM and PCH and 5 for PCB The overload 85 CCS C 10082015 Purpose Examples Example Files Also See keyword is required CCS2 only The default DEVICE ADC is set to the resolution of the part all other modes default to 8 onebit eightbits is compiled as onebit eightbits 0 All other modes compile as onebit eightbits amp 1 Chip Options Defines the target processor Every program must have
86. return value depends on number of bits in the chips A D converter and the setting in the DEVICE ADC directive as follows FDEVICE 8 bit 10 bit 11 bit 12 bit 16 bit ADC 8 00 FF 00 FF 00 FF 00 FF 00 FF ADC 10 Xx 0 3FF x 0 3FF x ADC 11 x 0 7FF x x x ADC 16 OFFOO 0 FFCO 0 FFEO 0 FFFO 0 FFFF Note x is not defined Availability This function is only available on devices with A D hardware Requires Pin constants are defined in the devices h file Exa setup_adc ADC_CLOCK_INTERNAL mple setup_adc ports ALL ANALOG Ss set_adc channel 1 while input PIN BO delay ms 5000 value read _adc printf A D value 2x n r value read_adc ADC START ONLY sleep value read_adc ADC_READ ONLY Exa ex admm c ex 14kad c mple Files 241 CCS C 10082015 Also setup adc set adc channel setup adc ports DEVICE ADC See 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 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
87. 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 05 27 06 Fixed Flashing problem id 11 CCS C 10082015 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
88. setup cc at set compare time at get capture at get status setup at Built in Functions at_set_compare_time Syntax Parameters Returns Function Availability Requires Examples Example Files Also See at_set_compare_time which compare_time which an 8 bit constant specifying which AT Capture Compare module to set the compare time for can be 1 2 or 3 compare_time a 16 bit constant or variable specifying the value to trigger an interrupt ouput pulse Nothing To set one of the Angular Timer Capture Compare module s compare time All devices with an AT module Constants defined in the device s header file at_set_compare time 1 0x1FF at_set compare time 3 compare time None 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 get capture at_get status setup_at at_set_missing_pulse_delay Syntax Parameters Returns Function Availability Requires Examples at_set_missing_pulse delay pulse_delay pulse_delay a signed 16 bit constant or variable to set the missing pulse delay Nothing To setup the Angular Timer Missing Pulse Delay All devices wit
89. software 12C functions Does not allow signals to float high signals are driven from low to high Bus used is not 12C bus but very similar Associates a stream identifier with this 12C port The identifier may then be used in functions like i2c_read or i2c_write Do not allow clock streaching Set an address mask for parts that support it Instead of SCL and SDA this sets the pins to the first module Instead of SCL and SDA this sets the pins to the second module No initialization of the 12C peripheral is performed Use I2C_INIT to initialize peripheral at run time Only some chips allow the following DATA_HOLD No ACK is sent until I2C_READ is called for data bytes slave only ADDRESS_HOLD No ACK is sent until 12C_ read is called for the address byte slave only SDA_HOLD Min of 300ns holdtime on SDA a from SCL goes low CCS offers support for the hardware based 12C and a software based master I2C device For more information on the hardware based 12C module please consult the datasheet for your target device not all PICs support 12C The 12C library contains functions to implement an 12C bus The USE 12C remains in effect for the 12C_START 12C_STOP 12C_READ 12C_WRITE and I12C_POLL functions until another USE 12C is encountered Software functions are generated unless the FORCE_HW is specified The SLAVE mode should only be used with the built in SSP The functions created with this directive are exported when
90. statement The expressions are loop control statements expr1 is the initialization expr2 is the termination check and expr is re initialization Any of them can be omitted Example for i 1 i lt 10 i o printf Sulrin i Also See Statements switch Switch is also a special multi way decision maker The syntax is switch expr case const1 stmt sequence break default stmt This tests whether the expression matches one of the constant values and branches accordingly If none of the cases are satisfied the default case is executed The break causes an immediate exit otherwise control falls through to the next case Example switch cmd case O printf cmd 0 break 17 CCS C 10082015 case l printf cmd 1 break default printf bad cmd break Also See Statements return return A return statement allows an immediate exit from a switch or a loop or function and also returns a value The syntax is return expr Example return 5 Also See Statements goto goto The goto statement cause an unconditional branch to the label The syntax is goto label A label has the same form as a variable name and is followed by a colon The goto s are used sparingly if at all Example goto loop Also See Statements label label The label a goto jumps to The syntax is label stmnt Example loop i Also See Statements 18 Statements br
91. statistic data for a specified task All devices USE RTOS statistics rtos_stats echo amp stats None rtos_terminate The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires Examples Also See rtos_wait rtos_terminate None None 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 All devices USE RTOS rtos_terminate rtos run The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters 260 rtos_wait sem sem is a global variable that represents the current availability of a shared Built in Functions system resource a semaphore Returns None 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 Availability All devices Requires USE RTOS Examples rtos wait uart_use Also See rios signal rtos_yield The RTOS is only included in the PCW PCWH and PCWHD software packages Syn
92. tada 35 Reterence ParaMeterS inc mit E AE E dol ibs Ben seabed ii tena ae pode LALO in OE lio ce 3 36 Default PaA A E S tothe ck cvepsaacacdovestcvesseaaaluctessaceesvanasdsvsetecanyvasclelsa ds cabeuesehilaiaiceupievesSeeleduesbacdpeiduousvcavieuee 36 Variable Argument LISTS atico cia a e iba 36 Table of Contents Finci na OVE OV o te 39 o A E AS dah edb E E E E ES 39 PD EEEE EE E A EEE E O E AE A E E E 40 Analog Comparator oessa NSE EEE E ETENE E TEE E EEE E AE a VOET Ee eTEN ENA 41 CAN BUS 5322 E cane A seis tie ester E TE 41 cs 43 Gode Profile sota ocacion od Atle scons Beles A 8 coe a tis thee act aoe tal Mento ak letra a Rector shen sts Recess 44 Configuration Memo ta iii 45 A eee EEE EEEE AENA E eeu E E sched E A EE egal due selaveedbcaudeedtedesdeddeaedeedes 46 Datta Ee pron snin donante AA E a ee 47 Data Signal Mod latot ss ccoo ata hast seen eases Meat ceed Wa eeu AE cl ENET ete ee 48 Externa MEM O y O pa ae a EAEE e A ENE AEAEE aTa A Eaa aAa 49 General Purpose VO oses eiieeii ii A ents 49 Internal MC D AEE E A E o AE e eh ret te 50 Internal Oscilator coto a rl a AE a Ea E aTa 51 INtOrUPiS cad tt T E E A sere 51 Low Voltage Detect a Arp a eaaa aa Eea aa a ia 53 PMP EP MP colono iii aida 53 Power mA A A AAE AA EAE o id a lid A E ea ened ie 54 Program Eeprom eamin castes er ar a a ed be eau ese ctv ace gee a ote aa a a a a 55 R E E E E EE EE E A E ANE E E E 57 QE iire e E E E a e E EE Eee a E cda 58 A E E O A eo 58 OS a A Se
93. the LCD segment memory undefined This function will load length bytes from buffer_pointer into the LCD segment memory beginning at offset The Ilcd_symbol function provides as easier way to write data to the segment memory Only on devices with built in LCD Driver Module hardware Constants are defined in the devices h file lcd_load buffer 0 16 ex 92lcd c Icd_symbol setup Icd lcd_contrast Internal LCD Overview Icd_symbol Syntax Parameters Returns Function Availability Requires Examples Icd_symbol symbol bX_adadr symbol is a 8 bit or 16 bit constant bX_addris a bit address representing the segment location to be used for bit X of the specified symbol 1 16 segments could be specified undefined This function loads the bits for the symbol into the segment data registers for the LCD with each bit address specified If bit X in symbol is set the segment at bX_addr is set otherwise it is cleared The bX_addr is a bit address into the LCD RAM Only on devices with built in LCD Driver Module hardware Constants are defined in the devices h file byte CONST DIGIT MAP 10 OxFC 0x60 OxDA OxF2 0x66 0xB6 OxBE OxE0 OxFE OxE6 define DIGIT1 COM1 20 COM1 18 COM2 18 COM3 20 COM2 28 COM1 28 COM2 20 COM3 18 203 CCS C 10082015 Example Files Also See Idexp Syntax Parameters Returns Function Availability Requires
94. the chip Returns 1 if the output buffer is full waiting to be read by the external bus Returns 1 if the input buffer is full waiting to read by the cpu Returns 1 if a write occurred before the previously written byte was read Interrupt fires when PSP data is in Returns 1 if the device has PSP waits till the output buffer is cleared writes to the port waits till input buffer is cleared if there is an overflow set the error flag if there is no overflow then read the port 57 CCS C 10082015 QEl The Quadrature Encoder Interface QEI module provides the interface to incremental encoders for obtaining mechanical positional data Relevant Functions setup_qei options filter maxcount qei_status qei_set_count value qei_get_couni Relevant Preprocessor None Relevant Interrupts INT_QEI Relevant Include Files None all functions built in Relevant getenv parameters None Example Code int16 Value setup_qei QEI_MODE_X2 QEI_TIMER_INTERNAL QEl_FILTER_DIV_2 QEl_ FORWARD Value qei_get_coun RS232 1 0 Configures the QE module Returns the status of the QUI module Write a 16 bit value to the position counter Reads the current 16 bit value of the position counter Interrupt on rollover or underflow of the position counter Setup the QEI module Read the count These functions and directives can be used for setting up and using RS232 I O functionality
95. 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 Installation Insert the CD ROM select each of the programs you wish to install and follow the on screen 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 CCS C 10082015 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 WIN8 Start Menu 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
96. the object integral All devices INCLUDE lt math h gt float result integral result modf 123 987 amp integral result is 987 and integral is 123 0000 None None prod _mul va 7 val2 val1 and val2 are both 8 bit or 16 bit integers A 16 bit integer if both parameters are 8 bit integers or a 32 bit integer if both parameters Function Availability Req uires Exa mple s Exa mple Files Also See nargs Syntax Parameters Returns Function Availability Requires Examples Built in Functions are 16 bit integers Performs an optimized multiplication By accepting a different type than it returns this function avoids the overhead of converting the parameters to a larger type All devices Nothing int a 50 b 100 long int c c mul a b c holds 5000 None None void foo char str int count The function can take variable parameters The user can use stdarg library to create functions that take variable parameters Function dependent The stdarg library allows the user to create functions that supports variable arguments The function that will accept a variable number of arguments must have at least one actual known parameters and it may have more The number of arguments is often passed to the function in one of its actual parameters lf the variable length argument list can involve more that one type the type information is generally p
97. the setup_wdt function and on PCH using fuses like WDT16 WDT256 etc RESTART_WDT when specified in USE DELAY USE I2C and USE RS232 statements like this USE DELAY clock 20000000 restart_wdt will cause the wdt to restart if it times out during the delay or 12C_READ or GETC Relevant Preprocessor FUSES WDT NOWDT Enabled Disables wat in PCB PCM devices FUSES WDT16 Sets ups the timeout time in PCH devices Relevant Interrupts None 71 CCS C 10082015 Relevant Include Files None all functions built in Relevant getenv parameters None Example Code For PIC16F877 fuses wdt setup_wdt WDT_2304MS while true restart_wdt perform_activity For PIC18F452 fuse WDT1 setup_wdt WDT_ON while true restart_wdi perform_activity Some of the PCB chips are share the WDT prescalar bits with timer0 so the WDT prescalar constants can be used with setup counters or setup_timer0 or setup_wdt functions 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 defined in the device s h file Examples if interrupt_enabled INT_RDA disable_inte
98. the specified I O pin The method of setting the direction register is determined by the last USE _lO directive All devices Pin constants are defined in the devices h file output bit PIN BO 0 Same as output_low pin BO output _bit PIN _BO input PIN Bl Make pin BO the same as B1 output _bit PIN BO shift left amp data 1 input PIN _B1 Output the MSB of data to BO and at the same time shift Bl into the LSB of data int16 i PIN BO ouput_bit i shift left data 1 input PIN _B1 same as above example but uses a variable instead of a constant ex extee c with 9356 c input output_low output_high output float output_x USE FIXED_lO USE FAST IO USE STANDARD 1O General Purpose I O output_drive Syntax Parameters Returns Function Availability Requires Examples 214 output_drive pin 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 undefined Sets the specified pin to the output mode All devices Pin constants are defined in the devices h file output_drive pin AO sets pin A0 to output its value output _bit pin BO input pin_A0 makes BO the same as AO Example Files Also See Built in Functions None input output _low output high output bit
99. to be used nosleep is used to prevent the compiler from inserting a sleep at the end of main Bootload produces a bootloader friendly hex file in order full block size NOSLEEP_LOCK is used instead of A sleep at the end of a main A infinite loop PIC18XXX devices with external ROM or PIC18XXX devices with no internal ROM can direct the compiler to utilize the ROM When linking multiple compilation units this directive must appear exactly the same in each compilation unit build memory 0x20000 0x2FFFF Assigns memory space build reset 0x200 interrupt 0x208 Assigns start location of reset and interrupt vectors build reset 0x200 0x207 interrupt 0x208 0x2ff Assign limited space for reset and interrupt vectors build memory 0x20000 0x2FFFF Assigns memory space None LOCATE RESERVE ROM HORG byte id x id is a valid C identifier xis a C variable or a constant If the id is already known as a C variable then this will locate the variable at address x In this case the variable type does not change from the original definition If the id is not known a new C variable is created and placed at address x with the type int 8 bit Warning In both cases memory at x is not exclusive to this variable Other variables may be located at the same location In fact when x is a variable then id and x share the same memory location byte status toyte b port Il WwW Sei 4 short int rw EI
100. to the next buffer location This will write a byte of data to the next buffer location or will write a byte to the specified buffer location Reads a byte of data psp_read will read a byte of data from the next buffer location and psp_read address will read the buffer location address Configures the address register of the PMP module with the destination address during Master mode operation This will return the status of the output buffer underflow bit This will return the status of the input buffers This will return the status of the input buffers This will return the status of the output buffers This will return the status of the output buffers Interrupt on read or write strobe Sets up Master mode with address lines PMAO PMA7 These options lets the user configure the Pulse Width Modulation PWM pins They are only available on devices equipped with PWM The options for these functions vary depending on the chip and are listed in the device header file 54 Functional Overview Relevant Functions setup_power_pwm config Sets up the PWM clock period dead time etc setup_power_pwm_pins modu Configure the pins of the PWM to be in le x Complimentary ON or OFF mode set_power_pwmx_duty duty Stores the value of the duty cycle in the PDCXL H register This duty cycle value is the time for which the PWM is in active state set_power_pwm_override pwm This function determines whether the OVDCONS or the
101. undo the timer0 prescaler Als FUSES restart wdt WDT or Watch Dog Timer Overview o Internal Oscillator Overview See setup_zdc Syntax setup_zdc mode Parameters mode the setup of the ZDC module The options for setting up the module include e ZCD_ENABLED e ZCD_DISABLED e ZCD_INVERTED e ZCD_INT_L_TO_H e ZCD_INT_H_TO_L Returns Nothing Function To set up the Zero_Cross Detection ZCD module Availability All devices with a ZCD module Examples setup _zcd ZCD ENABLE ZCD INT H TO L Example Files None Also See zcd_status 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 amp data Bit O of the lowest byte in RAM is treated as the LSB 320 Availability Requires Examples Example Files Also See Built in Functions All devices Nothing byte buffer 3 for i 0 i lt 24 i Wait for clock high while input PIN A2 shift left buffer 3 input PIN _A3 Wait for clock low while input PIN _A2 veads 24 bits from pin A3 each bit is read on a low to high on pin A2 ex_extee c 9356 c shift_right rotate_right rotate_left shift_right
102. 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 Directories The compiler will search the following directories for Include files e Directories listed on the command line e Directories specified in the CCSPJT file e 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 PiICC devices The compiler itself is a DLL file The DLL files are in a DLL directory by default in PICC DLL 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
103. using multiple compilation units To access the correct function use the stream identifier use 20 master is da P INABOs cl PINE use I2C slave sda PIN C4 scl PIN C3 address 0xa0 FORCE_ HW use I2C master scl PIN BO sda PIN Bl fast 450000 sets the target speed to 450 KBSP PreProcessor Example ex_extee c with 16c74 h Files Also See i2c poll i2c_ speed i2c start i2c stop i2c slaveaddr 2c_isr_state i2c write i2c_ read 12C Overview use profile Syntax use profile options Elements options may be any of the following comma separated ICD Default configures code profiler to use the ICD connection TIMER1 Optional If specified the code profiler run time on the microcontroller will use the Timer1 peripheral as a timestamp for all profile events If not specified the code profiler tool will use the PC clock which may not be accurate for fast events BAUD x Optional If specified will use a different baud rate between the microcontroller and the code profiler tool This may be required on slow microcontrollers to attempt to use a slower baud rate Purpose Tell the compiler to add the code profiler run time in the microcontroller and configure the link and clock Examples profile ICD TIMER1 baud 9600 Example ex_profile c Files Also See profile profileout Code Profile overview use pwm Syntax use pwm options Elements options are separated by comm
104. variable function or type to be checked Returns A C status for the type of id entered as follows 0 not known 1 typedef or enum 2 struct or union type 3 typemod qualifier 4 defined function 5 function prototype 6 compiler built in function 7 local variable 8 global variable Function This function checks the type of the variable or function being passed in and returns a specific C status based on the type Availability All devices Requires None Examples int x y 0 y definedinc x y will return 7 x is a local variable Example None Files Also See None device Syntax DEVICE chip options DEVICE Compilation mode selection Elements Chip Options chip is the name of a specific processor like PIC16C74 To get a current list of supported devices START RUN CCSC Q Options are qualifiers to the standard operation of the device Valid options are 84 5 8 16 ADC x ICD TRUE ICD n WRITE_EEPROM ASYNC WRITE_EEPROM NOINT HIGH_INTS TRUE f OVERLOAD KEYWORD OVERLOAD AUTO PASS_STRINGS IN_RAM CONST READ_ONLY CONST ROM NESTED_INTERRUPTS TRUE NORETFIE NO_DIGITAL_INIT PreProcessor Use 5 bit pointers for all parts Use 8 bit pointers 14 and 16 bit parts Use 16 bit pointers for 14 bit parts Where x is the number of bits read_adc should return Generates code compatible with Microchips ICD debugging hardware For
105. 0 strcpy string Hi There strcepy string2 string Example Files ex_str c Also See strxxxx strtod Syntax result strtod nptr amp endptr Parameters nptr and endptr are strings Returns result is a float returns the converted value in result if any If no conversion could be performed zero is returned Function The strtod function converts the initial portion of the string pointed to by nptr to a float representation The part of the string after conversion is stored in the object pointed to endptr provided that endptr is not a null pointer If nptr is empty or does not have the expected form no conversion is performed and the value of nptr is stored in the object pointed to by endptr provided endptr is not a null pointer Availability All devices Requires INCLUDE lt stdlib h gt Examples float result char str 12 123 45hello char ptr result strtod str amp ptr result is 123 45 and ptr is hello Example Files None Also See strtol strtoul strtok Syntax ptr strtok s7 s2 336 Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions s1 and s2 are pointers to an array of characters or the name of an array Note that s1 and s2 MAY NOT BE A CONSTANT like hi s1 may be 0 to indicate a continue operation ptr points to a character in s1 or is 0 Finds next token in s1 delimited by
106. 0 int iy va_list argptr create special argument pointer va_start argptr num initialize argptr for i 0 i lt num i sum sum va_arg argptr int va_end argptr end variable processing return sum None nargs va_start va_arg write_bank Syntax Parameters Returns Function Availability Requires 346 write_bank bank offset value 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 value is the 8 bit data to write undefined Write a data byte to 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 on the PIC16C57 chip setting the pointer size to 5 bits 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 write to the hard to reach banks In this case the bank may be 1 3 and the offset may be 0 15 All devices but only useful on PCB parts with memory over 1Fh and PCM parts with memory over FFh Nothing Examples Example Files Also See Built in Functions i 0 Uses bank 1 as a RS232 buffer do c getc write bank 1 it c while c 0x13 ex_psp c See the Common Questions and Answers section for more information write_configuration_memory Syntax
107. 0 RECEIVE_BUFFER 100 void main void char c if rcv_buffer_bytes gt 10 c getc None USE _RS232 RCV BUFFER FULL TX BUFFER FULL TX BUFFER BYTES GETC PUTC PRINTF SETUP UART PUTC_SEND rcv_buffer_full Syntax Parameters Returns Function Availability Requires Examples 240 value rcv_buffer_full stream stream optional parameter specifying the stream defined in USE RS232 TRUE if receive buffer is full FALSE otherwise Function to test if the receive buffer is full All devices USE RS232 USE_RS232 UART1 BAUD 9600 RECEIVE_BUFFER 100 void main void char c if rcv_buffer_full Built in Functions c getc Example Files None Also See USE RS232 RCV_BUFFER BYTES TX BUFFER BYTES TX BUFFER FULL GETC PUTC PRINTF SETUP _UART PUTC SEND read_adc Syntax value read_adc mode 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 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
108. 015 if else The if else statement is used to make decisions The syntax is if expr stmt 1 else stmt 2 The expression is evaluated if it is true stmt 1 is done If it is false then stmt 2 is done else if This is used to make multi way decisions The syntax is if expr stmt else if expr stmt else stmt The expressions are evaluated in order if any expression is true the statement associated with it is executed and it terminates the chain If none of the conditions are satisfied the last else part is executed Example if x 25 x 1 else x x 1 Also See Statements while While is used as a loop iteration statement The syntax is while expr statement The expression is evaluated and the statement is executed until it becomes false in which case the execution continues after the statement Example while get_rtcc 0 putc n Also See Statements 16 Statements do while do while Differs from while and for loop in that the termination condition is checked at the bottom of the loop rather than at the top and so the body of the loop is always executed at least once The syntax is do statement while expr The statement is executed the expr is evaluated If true the same is repeated and when it becomes false the loop terminates Also See Statements While for For is also used as a loop iteration statement The syntax is for expr1 expr2 expr3
109. 15 Returns Undefined Function This function adds a fraction of a tick to the period time for some modes of operation Availability All devices equipped with PSMC module Requires Examples Example Files None Also See setup psmc psmc_deadbana psmc_sync psmc_blanking psmc_modulation psmc_shutdown psmc_dutyt psmc_pins psmc_modulation Syntax psmc_modulation unit options 228 Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions unit is the PSMC unit number 1 4 Options may be one of the following PSMC_MOD_OFF PSMC_MOD_ACTIVE PSMC_MOD_INACTIVE PSMC_MOD_C10UT PSMC_MOD_C20UT PSMC_MOD_C30UT PSMC_MOD_C40UT PSMC_MOD_CCP1 PSMC_MOD_CCP2 PSMC_MOD_IN_PIN The following may be OR ed with the above PSMC_MOD_INVERT PSMC_MOD_NOT_BDF PSMC_MOD_NOT_ACE undefined This function allows some source to control if the PWM is running or not The active inactive are used for software to control the modulation The other sources are hardware controlled modulation There are also options to invert the inputs and to ignore some of the PWM outputs for the purpose of modulation All devices equipped with PSMC module None setup psmc psmc_deadbana psmc_sync psmc_blanking psmc_shutdown psmc duty psmc freq adjust psmc_pins 229 CCS C 10082015 psmc_pins Sy
110. 2 Parameters val1 is a float val2 is a float Returns result is a float Function Returns the floating point remainder of val1 val2 Returns the value val1 i val2 for some integer i such that if val2 is nonzero the result has the same sign as val1 and magnitude less than the magnitude of val2 Availability All devices Requires INCLUDE lt math h gt Examples float result result fmod 3 2 result is 1 Example Files None Also See None 175 CCS C 10082015 free Syntax Parameters Returns Function Availability Requires Examples Example Files Also See frexp Syntax Parameters Returns Function Availability Requires 176 free ptr ptr is a pointer earlier returned by the calloc malloc or realloc No value The free function causes the space pointed to by the ptr to be deallocated that is made available for further allocation If ptr is a null pointer no action occurs If the ptr does not match a pointer earlier returned by the calloc malloc or realloc or if the space has been deallocated by a call to free or realloc function the behavior is undefined All devices INCLUDE lt stdlibm h gt int apts iptr malloc 10 free iptr iptr will be deallocated None realloc malloc calloc result frexp va ue amp exp value is a float exp is a signed int result is a float The frexp function breaks a float
111. 233 A A dice cate Meck cua tend focs baste EE E E E E A T PUNTA OTN is wcesse de cove E E E daaub saves E iene igysnacenosnetia ecco E nea eo ene PUTT BOT NIG sede sec hag 00d Peay seed hapduveesees Lodtd cad debd E E E lade one pwm set duty percent pwm set frequency pwm1 interrupt active pwm2 interrupt active pwm3 interrupt active pwm4 interrupt active pwm5 interrupt active pwm6 interrupt actiVe 0 eee eeseeeeeeeeeeseneeeeeeeneeerenaees 237 ARIEL ET A E E E E E E E E A c 237 oE e a a RS 238 O O 238 A E T E E E AEE E EET 239 AA O A E E E Gee Aes 240 Wie E L E E A E A E E E 240 eeo Ch e E E E E E 241 WE DO E EEE E T E AE E AT E A E 242 ead CBAC a o a a oi ast Ad a E ev idee i Le A OR aa a 242 tead contiguration Memory Li o a aci 243 CEE ee NO 244 AP O 244 read program memory read external MeMoryl c ccccccnnnnnoccconnninnnononcccncnnnncnnnnncnncnnnncnnnnnnnnnnnnnnnnnnnnnnnnnnnannnnns 245 wad Nigh Spoed O ii lie o o ii tia 245 fead fom MEON a e aTe a a ra E e Tae ra Ar a ar Ee a TAA a aE EEr A E E E a A a R E EEE 247 CEDR E E E E EE E E T E 247 O EE E E E EEN tee 248 133 CCS C 10082015 A ne 249 AS 249 AS A A Seok cade E E E A A E SEA E A T 250 CA PA ON 250 eee IM OA A A ee aes oes as eee EE deed ceeds ie E 251 A AO 252 aa AA E E A E EAE scdaageeswisedasvaaddentiee 252 A AT E N E T 253 ICA E E E E ON 254 A E E E A E E E 254 AEE RETE Ne E E E EE O 255 e T E
112. 25 SISI A As 325 AE AAA smatanengaaignane E A oeaeneees 326 PN MEM Me IP EEE E E E E E E E E E E T EE 326 sp data ie mt rep data SG Jennien nip nnii iaa arao Ea aeaaee Ea EEEa E e RENEE EE iade 327 ISC A e 327 MSE SPN Mie ad T coe seven fotos E ii ii E ie 328 spi read BRM lE A A E E E E AE A 328 spi read 16 spi read2 16 spi read3 16 Spi read4 16 ooocccccccinnnoccccnonocinnnanoncnnnnnnnnnnnnnncnnnnnnnnnnnnnccnnnnnns 329 SEIU E A hank ccna sda axes datse E I sacs hei et an deuh dat T E A E A E E T 330 135 CCS C 10082015 Spi Write SPi Write2 oo eececcccccccesssecceececceessseeceeeeeeeessseceesceeceesseceeeseeeeeesseceeeseeeeeeneseeesensuagseceeeseteuansseseneeeneues 330 A 331 A A A ET 332 A ENE E E seed S E a paietadeiane EE Hie Gee Risa Eee 332 A e 333 e A NO 333 STANDARD STRING FUNCTIONS memchr memcmp strcat strchr stremp strcoll strcspn strerror stricm strlen strlwr strncat strnem strnc strpbrk strrchr _ _strspn strstr strxfrm 334 MEE SMA A ii 335 A A ENE A 336 ALE E LIE NENE EEEE AT AEE A AAE TA A tea secs 336 Ln E ede A E A E T ETE ieeets 338 AO AE A A E E A E E E E coil alan ccediioscicaiErnos riales 338 BN A O CO A E T E E 339 Owen OUDOT lod e a n E I a a a O EEEa E ERASE E 339 A E T EE E A A T E E A EE A ET 340 OMG INN E cia ds E ia A E E E 341 TOA STRAT E aida 342 w purer avalible A e an eero ii pi ara pan sued E 342 aS IEI EE AE E E A T 343 ie PS HUM Fs E EE se E E E E A E 344
113. 2c_start i2c_write data i2c_stop Issues a start command when in the 12C master mode Sends a single byte over the 12C interface Reads a byte over the 12C interface Issues a stop command when in the 12C master mode Returns a TRUE if the hardware has received a byte in the buffer Configures the compiler to support I2C to your specifications 12C or SPI activity Bus Collision 12C Interrupt Only on 14000 Bus Collision Only supported on some PIC18 s 12C or SPI activity Only supported on some PIC18 s Returns a 1 if the device has 12C slave H W Returns a 1 if the device has a 12C master H W Pin defines Configure Device as Master Data to be transmitted Issues a start command when in the I2C master mode Sends a single byte over the 12C interface Issues a stop command when in the 12C master mode 39 CCS C 10082015 ADC These options let the user configure and use the analog to digital converter module They are only available on devices with the ADC hardware The options for the functions and directives vary depending on the chip and are listed in the device header file On some devices there are two independent ADC modules for these chips the second module is configured using secondary ADC setup functions Ex setup_ADC2 Relevant Functions setup_adc mode setup_adc_ports value set_adc_channel channel read_adc mode adc_done Relevant Preprocessor DEVICE ADC xx
114. 4 LCD STOP ON SLEEP 2 ALL LCD PINS PIC16CI2X setup _lcd LCD MUX13 LCD REF ENABLED LCD B HIGH POWER 0 OxFF0429 PIC16F LF193X Enables Segments 0 3 5 10 16 17 18 19 20 21 22 23 Example Files Also See Built in Functions ex_92lcd c Icd_symbol Icd load led_contrast Internal LCD Overview setup_low_volt_detect Syntax Parameters Returns Function Availability Requires Examples setup_low_volt_detect mode 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 undefined 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 This function is only available with devices that have the high low voltage detect module Constants are defined in the devices h file setup_low_volt_detect LVD TRIGGER BELOW
115. 4_interrupt interrupt enable_pwm5_interrupt interrupt enable_pwm6_interrupt interrupt interrupt 8 bit constant or variable Constants are defined in the device s header file as PWM_PERIOD_INTERRUPT e PWM_DUTY_INTERRUPT PWM_PHASE_INTERRUPT PWM_OFFSET_INTERRUPT undefined Enables one of the above PWM interrupts multiple interrupts can be enabled by or ing multiple options together For the interrupt to occur the overall PWMx interrupt still needs to be enabled and an interrupt service routine still needs to be created Devices with a 16 bit PWM module Nothing Examples Example Files Also See Built in Functions enable _pwml_ interrupt PWM PERIOD INTERRUPT enable pwml_ interrupt PWM PERIOD INTERRUPT PWM DUTY INTERRUPT setup pwm set pwm_duty set pwm phase set pwm period set pwm_offset disable pwm_interrupt clear pwm_interrupt pwm interrupt active erase _eeprom Syntax Parameters Returns Function Availability Requires Examples Example Files Also See erase_eeprom address address is 8 bits on PCB parts undefined This will erase a row of the EEPROM or Flash Data Memory PCB devices with EEPROM like the 12F519 Nothing erase eeprom 0 erase the first row of the EEPROM 8 bytes None write program eeprom write program memory Program Eeprom Overview erase program_eeprom Syntax Parameters Return
116. A E E EE A E E ATE 89 HILO Ms cir e BI E E A ae eet 90 A et cal od ad 90 FMOXCOMMEN Eis A E te EA evel E tiaa 91 a es Lent 2 E 92 CCS C 10082015 FINOS WAIMINGS vasca a i 92 FIIMPOMt OPUOMS tico oli in io ico ai 93 O AIN 94 OO a A a a O A Aaa 94 A NA 95 PINT DEF AU Tessa td da tt tt tangas gente ans 98 A O teased A eeaaehe 98 O e 98 iaa 99 PRUNING curada da a a tro Aita OY 99 HOC td dd tio iii oe ade aid 100 A A O AE 100 HNOS dial de A dt Gn eee IAE 101 E O E E 101 a be A E eet aT Teenie tees a tee 102 5 10 1O MAEN OPERE EEA oa ATi A A cda 102 IR tisazcesesecdeckiaed ose TAT ATA A tdeshcqaseessbacsteaassleeuahavanecbacideabscteesuaes ST 103 PCD O AN 105 A acta evil oer E E E eee peta Mental ated Lee eee le ece tet ce eet ta eee eee eee 105 POC Mie ca A Reese es MS CADE sae ee Be ten ak Ta E EA S A teu Naseer E A EA A 106 O 106 A 106 HproMle oi aaa a A N cee 0 Dt li a AIRIS ee ee 107 OA de eee cadets 108 HOM lalo ici Leds altivo ide ot cited Luli inte dci 108 A A A T 109 E a eee ae eee eee 109 Haski patata lt laica eens a erate a 111 A 111 O A TEE 112 HONOR ta 113 NICO at AA A AA ee Ae 113 HUSO CaplUlO rca atril arta aa a dro 114 A NN 115 HUSC AYNAMIC MEMOlY A E AEA Ahad seis eae ani E Oah nia lacio a EE 116 HUSO TAS cian ld ri Me el ae ee ee ae ee 117 HUSO ill vad ee ila edo aed dass 117 A A a NN 117 HUSO nia ARA rindo 119 HUSO PWM Jeren e ea e a ID eo a in ey 119 HUSO TS Ll nit ii a dhs iin eel Wie eee ee eee a 120 HU
117. ADC_CHANNEL_AN2 ADC_CHANNEL_AN11 ADC_CHANNEL_VREF_BAND_GAP O 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 On the dsPIC33EPxxGSxxx family of devices Requires Nothing Examples setup_dedicated_adc_channel 0 ADC_CHANNEL_ANO Example Files None Also See setup adc setup adc ports set adc channel read _adc adc_done setup dedicated adc ADC Overview 268 Built in Functions set_hspwm_duty Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_hspwm_duty duty set_hspwm_duty unit primary secondary 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
118. AVE Makes the RS232 line a synchronous slave making the receive pin a clock in and the data pin the data in out SYNC_MASTER Makes the RS232 line a synchronous master making the receive pin a clock out and the data pin the data in out SYNC_MATER_CONT Makes the RS232 line a synchronous master mode in continuous receive mode The receive pin is set as a clock out and the data pin is set as the data in out UART1 Sets the XMIT and RCV to the chips first hardware UART UART2 Sets the XMIT and RCV to the chips second hardware UART NOINIT No initialization of the UART peripheral is performed Useful for dynamic control of the UART baudrate or initializing the peripheral manually at a later point in the program s run time If this option is used then setup_uart needs to be used to initialize the peripheral Using a serial routine such as getc or putc before the UART is initialized will cause undefined behavior ICD Indicates this stream is used to send receive data through a CCS ICD unit The default trasmit pin is the PIC s ICSPDAT PGD pin and the default receive pin is the PIC s ICSPCLK PGC pin Use XMIT and RCV to change the pins used UART3 Sets the XMIT and RCV to the device s third hardware UART UART4 Sets the XMIT and RCV to the device s fourth hardware UART ICD Indicates this stream uses the ICD in a special pass through mode to send receive serial data to from PC The ICSP clock line is the PIC s receive pin
119. All devices Pin constants are defined in the devices h file output _low PIN AO Int16i PIN Al output _low PIN Al X_SQw c input output _high output float output bit output x USE FIXED 10 USE FAST IO USE STANDARD 1O General Purpose I O Built in Functions output_toggle Syntax Parameters Returns Function Availability Requires Examples Example Files Also See perror Syntax Parameters Returns Function Availability Requires Examples Example Files output_toggle pin 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 Undefined Toggles the high low state of the specified pin All devices Pin constants are defined in the devices h file output_toggle PIN B4 None Input output _high output _low output _bit output _x perror string string is a constant string or array of characters null terminated Nothing This function prints out to STDERR the supplied string and a description of the last system error usually a math error All devices USE RS232 INCLUDE lt errno h gt x sin y if errno 0 perror Problem in find area None 217 CCS C 10082015 Also See RS232 I O Overview pid_busy Syntax result pid_busy Paramet
120. CCS C Compiler Manual PCB PCM PCH APE 8 A We October 2015 ALL RIGHTS RESERVED Copyright Custom Computer Services Inc 2015 CCS C 10082015 Table of Contents OVENI Wisin he A oad eee AAA oe eee sit ea a a a a Red ete 1 G COmMpile tis imei id 1 PGB PGMiand PEH Overviews acera tie 1 Installation coria o aa 1 Technical SUPpoOrt cosita atlas ito tt a 2 e O NO 2 Ele OMS A o eii RECAE 3 Invoking the Command Line Compiler ooooconncconocccanccononcnanccononcnonononnnncnno crono cnn oran n nana r enn cnn nr n rra rene n ranma ra rnnannn nana 4 PGW Dr deta cuentiee 5 IMG cece tees NO 6 Editor aDS usina de pode lero ss da ole E lla bhi ee aos edd Oe on abl telat aa aid ohh coca EL o 6 Slide Out WindOWS canaria A eee aa ee 7 o A NR ont A ate Bata oe A E ee eh 7 Debugging WINDOWS id adn eee eee lacada 7 Status Bal a ti AT O es 8 OUIPUBMESSAGES AEA AAT A E A A AN AT 8 Program Syntaksi neco ane eaa din E e a era AK A beste aE SS A 11 ONE ESAU e U TE S TA N P OE EAE E e e A 11 COMMON dins AA EA E P T A I AE AEE AAEE AEE ad E EAT 11 Ae EI aS o OEI e E E E E E A E E E A NT 12 Multiple Project Files iinitan as iv ba eo es ete E EE A E E aE a ees 12 M ltiple Compilation UMIS ciiisean a a a aed ete ds et ee tees teas eek eevee ee 13 Full Example Program iiss tata tained iin E iv ek ee E ne ete ei le 13 SAME Sii a de dai tastes lao bates ote acia tes clan barra dra 15 Statements AAN EE O A A A e a a
121. C_STOP since All devices Requires Examples Example Files Also See i2c_stop Syntax Parameters Returns Function Availability Requires Examples Example Files Also See i2c_write Syntax Built in Functions USE 12C i2c_start 7 Oxa0 Device address i2c_write i2c_write address Data to device i2c_start Restart i2c write 0xal to change data direction data i2c_read 0 Now read from slave i2c_stop ex extee c with 2416 c i2c poll i2c speed i2c stop i2c slaveaddr i2c isr state i2c_ write i2c_ read USE 12C 12C Overview i2c_stop i2c_stop stream stream optional specify stream defined in USE 12C undefined Issues a stop condition when in the 12C master mode All devices USE 12C i2c_start Start condition O i2c_write 0xa0 Device address i2c write 5 Device command i2c write 12 Device data i2c_stop Stop condition ex_extee c with 2416 c 126 a i2c_write data 193 CCS C 10082015 Parameters Returns Function Availability Requires Examples Example Files Also See input Syntax Parameters Returns Function 194 i2c_write stream data data is an 8 bit int stream specify the stream defined in USE 12C This function returns the ACK Bit 0 means ACK 1 means NO ACK 2 means there was a collision if in Multi_Master Mode
122. Clears one of the above PWM interrupts multiple interrupts can be cleared by or ing multiple options together Availability Devices with a 16 bit PWM module Requires Nothing Examples clear _pwml_ interrupt PWM_PERIOD INTERRUPT clear _pwml_ interrupt PWM PERIOD INTERRUPT PWM DUTY INTERRUPT Example Files Also See setup pwm set pwm duty set pwm_phase set pwm period set pwm_offset enable pwm_interrupt disable pwm_ interrupt pwm_ interrupt active cog_status Syntax value cog_status Parameters None Returns value the status of the COG module Function To determine if a shutdown event occurred on the Complementary Output Generator COG module Availability All devices with a COG module Examples if cog_status COG AUTO SHUTDOWN cog_restart Example Files None Also See setup cog set cog dead band set cog blanking set cog phase cog restart 161 CCS C 10082015 cog_restart Syntax Parameters Returns Function Availability Examples Example Files Also See crc_calc Syntax Parameters Returns Function 162 cog_restart None Nothing To restart the Complementary Output Generator COG module after an auto shutdown event occurs when not using auto restart option of module All devices with a COG module if cog_status C0G_AUTO SHUTDOWN das mestesuate 0 5 None setup cog set cog dead band
123. D with the given text from this point of the program and on In the second form a C macro the local identifiers are matched up with similar identifiers in the text and they are replaced with text passed to the macro where it is used If the text contains a string of the form idx then the result upon evaluation will be the parameter id concatenated with the string x If the text contains a string of the form idx idy then parameter idx is concatenated with parameter idy forming a new identifier Within the define text two special operators are supported x is the stringize operator resulting in x x y is the concatination operator resulting in xy The varadic macro syntax is supported where the last parameter is specified as and the local identifier used is __va_args__ In this case all remaining arguments are combined with the commas define BITS 8 a a BITS same as a a 8 define hi x x lt lt 4 a hi a same as a a lt lt 4 define isequal a b primary a b backup_ a b usage iseaqual names 5 is the same as primary names 5 backup_names 5 define str s s define part device include str device h usage part 16F887 is the same as include 16F887 h define DBG fprintf debug VA ARGS ex_stwt c ex_macro c 83 CCS C 10082015 Also See UNDEF IFDEF IFNDEF definedinc Syntax value definedinc variable Parameters variable is the name of the
124. E E A E E E AT 266 vii CCS C 10082015 Seti Cogphase Juicio a ee 266 Set COMpare TIME uaiac ii vee eth in ieee na ace eels adie 267 set dedicated sade Caella 265 ochtcbecatecabet ist flen sale och Ga act A E T 268 A O AN 269 set_hspwm_event set_hspwm_event_Secondary cccccccnnnncccccnncccinnnenooncnnnnconnnnnnncnnnncnnnnnnnnncnnnnenannnnnnccnnncnns 269 Set ISpwIM OVOIdO mirra tata bbc ad dd 270 SOL NSpwimi phase Jaca cidcid iii datan aproba ae an AER 271 SOL NCO INC VAlUC tii indicaba 272 SOON A nes ad a ae aire 272 set power PWM OVE dE ductos A adas cee ate 273 set power PWMX AUty Josenea orean dees era eee secede oe did atacada codi cera EINEN 273 SOL O EE TA EE 274 set pullup Jenner ee ar de GEL eee ee eee Ss 274 set_pwm1_duty set_pwm2_duty set_pwm3_duty set_pwm4_duty set_pwm5_duty 275 set_pwm1_offset set pwm2_offset set_pwm3_offset set_pwm4_offset set_pwm5_offset set_pwm6_offset ceccescceeseseeceeeneeeeeeeseeeeseseeseeeseeeeeeeaseeeeesssneeenseeseseseesensseseenscnaenenscees 276 set_pwm1_period set_pwm2_period set_pwm3_period set_pwm4_period set_pwm5_period Set_PWM6_PeriOd eeeeeeeeeeeenneeeeeeeeeeeeneeeeeeaeeeeeeaeeeeeeaaeeeeseneeeeeseaeeesesaeeeeseneeeeeseneeeeenaaes 277 set_pwm1_phase set_pwm2_phase set_pwm3_phase set_pwm4_phase set_pwm5_phase set_pwm6_phase ccconocccinnicccnnonocccnnnnnccnnnnnco nn acercar
125. E E E A N 123 E E O E O 124 use standard 10 cccsceesssecesccecccesssesscccusccusseususceeucesecusscceeccousesuseseseueusseseusensecussevsueeensecussereveseuceeuecereueneuceeueass 125 AA EE E E E E E EE E E E E EEEE A E E E E N 126 PUSS MOCHA MEAE ds E 127 Pae aL did 128 o EE A E E EEE E E E A E E E E E E E E E E EEE 129 FACIAT ER ETE POS E E e EAE EE EEE 130 76 PreProcessor _ address __ A predefined symbol __address__ may be used to indicate a type that must hold a program memory address For example address__ testa 0x1000 will allocate 16 bits for test a and initialize to 0x1000 _attribute_x Syntax Elements Purpose _ attribute __x x is the attribute you want to apply Valid values for x are as follows packed By default each element in a struct or union are padded to be evenly spaced by the size of int This is to prevent an address fault when accessing an element of struct See the following example struct int8 a int16 b test On architectures where int is 16bit such as dsPIC or PIC24 PlCmicrocontrollers test would take 4 bytes even though it is comprised of3 bytes By applying the packed attribute to this struct then it would take 3 bytes as originally intended struct __attribute__ packed int8 a int16 b test Care should be taken by the user when accessing individual elements of a packed struct creating a pointer to b in test and atte
126. E O E AI EN Meucastcuuaes aucteehs ceaslensce Abearnat endtde E cane Ile 353 SUC Misczgec sei Nes rae A EA ATAATA ET 353 Sidlib Mirra td E Ae he A ad 353 Software License Agreement soraira apa aand aana aoaia E e aaa AE AEn a Eaa dean iba 355 SOFTWARE LICENSE AGREEMENT rrien e aaae ee E al ra EE a 355 OVERVIEW C Compiler PCB PCM and PCH Overview Technical Support Directories File Formats Invoking the Command Line Compiler PCB PCM and PCH Overview 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 high level language 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
127. EEPROM NOINT This will allow interrupts to occur while the write_eeprom operations is polling the done bit to check if the write operations has completed Can be used as long as no EEPROM operations are performed during an ISR This function is only available on devices with supporting hardware on chip Nothing define LAST VOLUME 10 Location in EEPROM volume write eeprom LAST VOLUME volume ex intee c ex extee c ce51x c ce62x c ce67x c read eeprom write program eeprom read_program_eeprom data Eeprom Overview write _external_memory Syntax Parameters Returns Function Availability Requires Examples 348 write_external_memory address dataptr count address is 16 bits on PCM parts and 32 bits on PCH parts dataptr is a pointer to one or more bytes count is a 8 bit integer undefined Writes count bytes to program memory from dataptr to address Unlike write_program_eeprom and read_program_eeprom this function does not use any special EEPROM FLASH write algorithm The data is simply copied from register address space to program memory address space This is useful for external RAM or to implement an algorithm for external flash Only PCH devices Nothing for i 0x1000 i lt 0x1fff 1 value read_adc write external memory i value 2 delay _ms 1000 Example Files Also See Built in Functions ex load c loader c write program eepr
128. GLOBAL level will not enable any of the specific interrupts but will allow any of the specified interrupts previously enabled to become active Some chips that have an interrupt 169 CCS C 10082015 Availability Requires Examples Example Files Also See on change for individual pins all the pin to be specified such as INT_RA1 For interrupts that use edge detection to trigger it can be setup in the enable_interrupts function without making a separate call to the set_int_edge function Enabling interrupts does not clear the interrupt flag if there was a pending interrupt prior to the call Use the clear_interrupt function to clear pending interrupts before the call to enable_interrupts to discard the prior interrupts Devices with interrupts Should have a INT_XXXX to define the ISR and constants are defined in the devices h file enable interrupts GLOBAL enable interrupts INT _TIMERO enable interrupts INT_EXT_H2L ex_sisr c ex stwt c disable interrupts clear interrupt ext_int_edge INT xxxx Interrupts Overview interrupt_active enable_pwm1_interrupt enable_pwm2_interrupt enable_pwm3_interrupt enable_pwm4_interrupt enable_pwm5 _interrupt enable_pwm6_interrupt Syntax Parameters Returns Function Availability Requires 170 enable_pwm1_interrupt interrupt enable_pwm2_interrupt interrupt enable_pwm3_interrupt interrupt enable_pwm
129. H DATA_EEPROM EEPROM_ADDRESS READ_PROGRAM ADC_CHANNELS ADC_RESOLUTION ICD SPI USB CAN 12C_SLAVE 12C_ MASTER Returns 1 if fuse fffff is enabled Returns 1 if fuse fffff is valid Returns the device ID set by ID Returns the device name string like PIC16C74 Returns the MPU FOSC Returns the compiler version as a float Returns the compiler version as a string Returns the size of memory for code in words Returns the stack size Returns the start of the compiler scratch area Returns the number of bytes of data EEPROM Returns the address of the start of EEPROM 0 if not supported by the device Returns a 1 if the code memory can be read Returns the number of A D channels Returns the number of bits returned from READ_ADC Returns a 1 if this is being compiled for a ICD Returns a 1 if the device has SPI Returns a 1 if the device has USB Returns a 1 if the device has CAN Returns a 1 if the device has 12C slave H W Returns a 1 if the device has I2C master H W PSP COMP VREF LCD UART AUART CCPx TIMERx FLASH_WRITE_SIZE FLASH_ERASE_SIZE BYTES_PER_ADDRESS BITS_PER_INSTRUCTION RAM SFR name BIT name SFR_VALID name Built in Functions Returns a 1 if the device has PSP Returns a 1 if the device has a comparator Returns a 1 if the device has a voltage reference Returns a 1 if the device has direct LCD H W Returns the number of HWW UARTs Returns 1 if
130. I DMA Slave Select pin_xx is the CCS provided pin definition For example PIN_C7 PIN_BO PIN_DS3 etc When using PPS chips a PIN_SELECT must be appear before these peripherals can be used or referenced pin_select U1TX PIN C6 pin_select U1RX PIN_ C7 pin_select INT1 PIN_ BO PreProcessor Example None Files Also See pin select pcb Syntax _ PCB __ Elements None Purpose The PCB compiler defines this pre processor identifier It may be used to determine if the PCB compiler is doing the compilation Examples ifdef _ pcb __ device PIC16c54 endif Example ex_Sqw c Files Also See PCM PCH pcm Syntax _ PCM __ Elements None Purpose The PCM compiler defines this pre processor identifier lt may be used to determine if the PCM compiler is doing the compilation Examples ifdef _ pcm __ device PIC16c71 endif Example ex_sqw c Files Also See PCBA IRCH 105 CCS C 10082015 _pch__ Syntax __ PCH __ Elements None Purpose The PCH compiler defines this pre processor identifier It may be used to determine if the PCH compiler is doing the compilation Examples ifdef _ _ PCH _ device PIC18C452 endif Example ex_Sqw c Files Also See PCB PCM pragma Syntax PRAGMA cmd Elements cmd is any valid preprocessor directive Purpose This directive is used to maintain compatibility between C compilers This compiler will accept this directive before any other pre proces
131. IED_TO_CURRENT_LIMIT_INPUT delay 16 bit constant or variable to specify the leading edge blanking time undefined Sets up the Leading Edge Blanking and leading edge blanking time of the High Speed PWM Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None setup_hspwm blanking HSPWM RE PWMH TRIGGERS LE BLANKING 10 None 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_hspwm_unit Syntax Parameters setup_hspwm_unit unit mode dead_time alt_dead_time set_hspwm_duty unit primary secondary unit The High Speed PWM unit to set 299 CCS C 10082015 Returns Function Availability Requires Examples Example Files 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 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 th
132. LED None setup power pwm set power pwm_override set power pwmX_duty setup_psp option address_mask Syntax Parameters setup_psp options address_mask setup_psp options 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 IIncrement 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 PMAO PMA15 or 32 address lines PMAO PMA31 EPMP only 311 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See Undefined 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 Only the devices with a built in Parallel Port module or Enhanced Pa
133. LIB H must be included Examples long result char str 9 123hello char ptr result strtoul str amp ptr 10 result is 123 and ptr is hello Example Files None Also See strtol strtod swap Syntax swap value Parameters Ivalue is a byte variable Returns undefined WARNING this function does not return the result Function Swaps the upper nibble with the lower nibble of the specified byte This is the same as byte byte lt lt 4 byte gt gt 4 Availability All devices Requires Nothing Examples x 0x45 swap x x now is 0x54 Example Files None Also See rotate right rotate _left tolower toupper Syntax result tolower cvalue result toupper cva ue Parameters cvalue is a character 339 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See An 8 bit character 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 All devices Nothing switch toupper getc case R read cmd break case W write cmd break case Q done TRUE break ex_str c None touchpad_getc Syntax Parameters Returns Function Availability Requires Examples 340 inp
134. L_MEMORY mode mode is one or more constants from the device header file OR ed together undefined Sets the mode of the external memory bus Only devices that allow external memory Constants are defined in the device h file setup external memory EXTMEM WORD WRITE EXTMEM WAIT 0 setup external memory EXTMEM DISABLE None WRITE PROGRAM EEPROM WRITE PROGRAM MEMORY External Memory Overview 295 CCS C 10082015 setup _high_speed_adc Syntax setup_high_speed_adc 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 PIC is idle Returns Undefined 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 Only on dsPIC33FUxxGSxxx devices Requires Constants are define in the device 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 Example Files None Also
135. N module and clears all the filters and masks so thathat all messages can be received from any ID can_set_baud void Initializes the baud rate of the CAN bus to125kHz if using a 20 MHz clock and the default CAN BRG defines it is called inside the can_init 41 CCS C 10082015 can_set_mode CAN_OP_MODE mode can_set_functional_mode CAN_FUN_OP_MODE mode can_set_id int addr int32 id int1 ext can_get_id int addr int1 ext can_putd int32 id int data int len int priority int1 ext int1 rtr can_getd int32 amp id int data int amp len struct rx_stat amp stat can_enable_rtr PROG_BUFFER b can_disable_rtr PROG_BUFFER b can_load_rtr PROG_BUFFER b int data int len can_enable_filter long filter can_disable_filter long filter can_associate_filter_to_buffer CAN_FILTER_ASSOCIATION_BUFF ERS buffer CAN_FILTER_ASSOCIATION filter can_associate_filter_to_mask CAN_MASK_FILTER_ASSOCIATE mask CAN_FILTER_ASSOCIATION filter can_fifo_getd int32 amp id int data int amp len struct rx_stat amp stat Relevant Preprocessor None Relevant Interrupts int_canirx 42 function so there is no need to call it Allows the mode of the CAN module to be changed to configuration mode listen mode loop back mode disabled mode or normal mode Allows the functional mode of ECAN modules to be changed to legacy mode enhanced legacy mode or first in firstou
136. ND CLC_GATE_NOR CLC_GATE_OR CLC_GATE_CLEAR CLC_GATE_SET Undefined Sets the logic function performed on the inputs for the specified data gate On devices with a CLC module Undefined Example Files Also See clc1_setup_input clc3_setup_input Syntax Parameters Returns Function Availability Retu rns Examples Example Files Built in Functions clc1_setup_gate 2 CLC GATE NAND clcl_setup_gate 3 CLC_GATE CLEAR clcl_setup_gate 4 CLC_GATE SET None setup clcx clex setup input clc2_setup_input clc4 setup_input clc1_setup_input input selection clc2_setup_input input selection clc3_setup_input input selection clc4_setup_input input selection input selects which input of the Configurable Logic Cell CLC module to setup value can be 1 to 4 selection the actual input for the specified input that is actually connected to the data gates of the CLC module The options are CLC_INPUT_O CLC_INPUT_1 CLC_INPUT_2 CLC_INPUT_3 CLC_INPUT_4 CLC_INPUT_5 CLC_INPUT_6 CLC_INPUT_7 Undefined Sets the input for the specified input number that is actually connected to all four data gates of the CLC module Please refer to the table CLCx DATA INPUT SELECTION in the device s datasheet to determine which of the above selections corresponds to actual input pin or peripheral of the device On devices with a CLC module Undefined clcl_setup_input 1 CLC_I
137. NE li 18 lp int unused 2 int data Lp ja jor 81 CCS C 10082015 byte a_port 5 a port cl 15 Example ex_glint c Files Also See bit locate reserve word Named Registers Type Specifiers Type Qualifiers Enumerated Types Structures amp Unions Typedef case Syntax CASE Elements None Purpose Will cause the compiler to be case sensitive By default the compiler is case insensitive When linking multiple compilation units this directive must appear exactly the same in each compilation unit Warning Not all the CCS example programs headers and drivers have been tested with case sensitivity turned on Examples case in EES TATUS vord funci A int status STATUS status Copy local status to global Example ex_cust c Files Also See None _date_ Syntax _ DATE _ Elements None Purpose This pre processor identifier is replaced at compile time with the date of the compile in the form 31 JAN 03 Examples printf Software was compiled on printf _ DATE Example None 82 Files Also See define Syntax Elements Purpose Examples Example Files PreProcessor None define id text or define d x y text id is a preprocessor identifier text is any text x y is a list of local preprocessor identifiers and in this form there may be one or more identifiers separated by commas Used to provide a simple string replacement of the I
138. NPUT_0 2 CLC_INPUT_ 1 3 CLC_INPUT 2 4 CLC_INPUT 3 clcl_setup_input clcl_setup_input clcl_setup_input None 159 CCS C 10082015 Also See setup clcx clcx setup gate clear_interrupt Syntax clear_interrupt eve Parameters level a constant defined in the devices h file Returns undefined Function Clears the interrupt flag for the given level This function is designed for use with a specific interrupt thus eliminating the GLOBAL level as a possible parameter Some chips that have interrupt on change for individual pins allow the pin to be specified like INT_RA1 Availability All devices Requires Nothing Examples clear interrupt int _timerl Example Files None Also See enable interrupts INT Interrupts Overview disable interrupts interrupt actvie clear_pwm1_interrupt clear_pwm2_interrupt clear_pwm3_interrupt clear_pwm4_interrupt clear_pwm5_interrupt clear_pwm6_interrupt Syntax clear_pwm1_interrupt interrupt clear_pwm2_interrupt interrupt clear_pwm3_interrupt interrupt clear_pwm4_interrupt interrupt clear_pwm5_ interrupt interrupt clear_pwm6_interrupt interrupt Parameters interrupt 8 bit constant or variable Constants are defined in the device s header file as e PWM_PERIOD_INTERRUPT e PWM_DUTY_INTERRUPT e PWM_PHASE_INTERRUPT e PWM_OFFSET_INTERRUPT 160 Built in Functions Returns undefined Function
139. OPA PEE EAEE E E theta cane hier Mee duced fae coat bead OE E eet nage tee 205 O O 206 MakeoB ici As lees Gein tet eee i ee es 206 Make Maia ao aio ae a a 207 Makes 2 Mis diia at E ath cat oe lo le vat he E etek wh ae tanta Duane E ghey ves cea tee 207 MaAlOC sz cid ida 208 memcpy MeMMOVE 2c cesteceeh cts eee a A do de eee 208 memset iia cta o aa Ee ea ee ee ed 209 Moda Me ed teins iced it ete cs LS es ee 210 A cen wee aa cocebetean dele oleate ces pene a a aA de catia trea setae sin Ga seule deg heey ree cetera 210 MAGS NO 211 offsetof OfSELOIDITG A 212 OUTPUT asista ara a 213 QUIputDI lutitas dll de letal dd cl alada cated miata oens 213 A O O E 214 oO iroli Lanni Coren O EE E Aaa rdn ini obinna 215 OUTPUT ION iia vie ee Devi ea a E eve iv Se ied i at 215 OUTPUTS lO W usaras aaa 216 O tp t toggle ivi da ti A te e A di ba Mihi da dc 217 PONTONG R EA EA A A EE T 217 Pid DUSY side tose eh heist a tates ieee ls ees sen eae de E E ee 218 pid get Tesult o ete toed iene a edie eves avid pt es 218 PIC MOAN MEEA A E cae eter aa te iio setetee 219 A A eutes os E A ve tees A E oe eben E E einai teres ee Te cal ys teens eter 220 PIL MOCKED I C EEA EEE ATA AAA ET 221 port x pulllpS Chica E E E E A A Ee eee IES 221 POW PWI ices E E a ee 222 printf APU Satis Sante theese EE E E A A aide Sieh E 223 profilegut ici E E E E E signees Saihabisesventanssetes 224 Table of Contents psmeblanking iticiebise Mh hehe ee
140. P 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 Availability This function is only available on devices with CCP hardware Requires Constants are defined in the devices h file Examples setup_ccpl CCP_CAPTURE_RE Example Files ex _pwm c ex ccpmp c ex _ccp1s c Also See 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 i setup_clc3 mode setup_clc4 mode 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 Undefined 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 289 CCS C 10082015 Availability Returns Examples Example Files Also See On
141. PDC registers override value determine the PWM output Relevant Preprocessor None Relevant Interrupts INT_PWMTB PWM Timebase Interrupt Only available on PIC18XX31 Relevant getenv Parameters None Example Code long duty_cycle period Configures PWM pins to be ON OFF or in Complimentary mode setup_power_pwm_pins PWM_COMPLEMENTARY PWM_OFF PWM_OFF PWM_OFF Sets up PWM clock postscale and period Here period is used to set the PWM Frequency as follows Frequency Fosc 4 period 1 postscale setup_power_pwm PWM_CLOCK_DIV_4 PWM_FREE_RUN 1 0 period 0 1 0 set_power_pwm0_duty duty_c Sets the duty cycle of the PWM 0 1 in ycle Complementary mode Program Eeprom The Flash program memory is readable and writable in some chips and is just readable in some These options lets the user read and write to the Flash program memory These functions are only available in flash chips Relevant Functions read_program_eeprom addres Reads the program memory location 16 bit or 32 bit depending on the 55 CCS C 10082015 s write_program_eeprom addres s value erase _program_eeprom addre ss write_program_memory addre ss dataptr count read_program_memory addres s dataptr count Relevant Preprocessor ROM address list DEVICE WRITE_EEPROM AS YNC Relevant Interrupts INT_EEPROM Relevant Include Files None all functions built in Relevant getenv parameters PROGRAM
142. P_CAPTURE DIV_16 Capture after 16 pulses Set CCP to compare mode CCP_COMPARE_SET_ON_MATCH Output high on compare CCP_COMPARE_CLR_ON_MATCH Output low on compare CCP_COMPARE_INT interrupt on compare CCP_COMPARE_RESET_TIMER Reset timer on compare Set CCP to PWM mode CCP_PWM Enable Pulse Width Modulator Constants used for ECCP modules are as follows CCP_PWM_H CCP_PWM_H CCP_PWM_L CCP_PWM_L CCP_PWM_FULL_BRIDGE CCP_PWM_FULL_BRIDGE_REV CCP_PWM_HALF_BRIDGE CCP_SHUTDOWN_ON_COMP1 shutdown on Comparator 1 change CCP_SHUTDOWN_ON_COMP2 shutdown on Comparator 2 change CCP_SHUTDOWN_ON_COMP Either Comp 1 or 2 change CCP_SHUTDOWN_ON_INTO VIL on INT pin CCP_SHUTDOWN_ON_COMP1_INTO VIL on INT pin or Comparator 1 change CCP_SHUTDOWN_ON_COMP2_INTO VIL on INT pin or Comparator 2 change CCP_SHUTDOWN_ON_COMP_INTO VIL on INT pin or Comparator 1 or 2 change CCP_SHUTDOWN_A Drive pins A and C high CL CCP_SHUTDOWN_AC _H Drive pins A and C low CCP_SHUTDOWN_AC F Drive pins A and C tri state CCP_SHUTDOWN_BD _L Drive pins B and D high CCP_SHUTDOWN_BD_H Drive pins B and D low 288 Built in Functions CCP_SHUTDOWN_BD F Drive pins B and D tri state CCP_SHUTDOWN_RESTART the device restart after a shutdown event CCP_DELAY use the dead band 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 Returns Undefined Function Initialize the CC
143. Parameters Returns Function Availability Requires Examples Example Files Also See write_configuration_memory offset dataptr count dataptr pointer to one or more bytes count a 8 bit integer offset is an optional parameter specifying the offset into configuration memory to start writing to offset defaults to zero if not used undefined For PIC18 devices Erases all fuses and writes count bytes from the dataptr to the configuration memory For Enhanced16 devices erases and write User ID memory All PIC18 Flash and Enhanced16 devices Nothing int data 6 write configuration memory data 6 None WRITE_PROGRAM_MEMORY Configuration Memory Overview write_eeprom Syntax Parameters write_eeprom address value address is a 8 bit or 16 bit depending on the part int the range is device dependent value is an 8 bit int 347 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See undefined Write a byte to the specified data EEPROM address This function may take several milliseconds to execute This works only on devices with EEPROM built into the core of the device For devices with external EEPROM or with a separate EEPROM in the same package like the 12CE671 see EX_EXTEE c with CE51X c CE61X c or CE67X c In order to allow interrupts to occur while using the write operation use the DEVICE option WRITE_
144. Put in Serial number Place string serial number at EEPROM address 0 reserving 2 bytes serialize dataee 0 string 2 next AB prompt Put in Serial number None None task PreProcessor The RTOS is only included with the PCW PCWH and PCWHD software packages Each RTOS task is specified as a function that has no parameters and no return The TASK directive is needed just before each RTOS task to enable the compiler to tell which functions are RTOS tasks An RTOS task cannot be called directly like a regular function can Syntax Elements Purpose Examples Also See TASK options options are separated by comma and may be rate time Where time is a number followed by s ms us or ns This specifies how often the task will execute max time Where time is a number followed by s ms us or ns This specifies the budgeted time for this task queue bytes Specifies how many bytes to allocate for this task s incoming messages The default value is 0 enabled value Specifies whether a task is enabled or disabled by rtos_run True for enabled false for disabled The default value is enabled This directive tells the compiler that the following function is an RTOS task The rate option is used to specify how often the task should execute This must be a multiple of the minor_cycle option if one is specified in the USE RTOS directive The max option is used to specify how much processor ti
145. R FULL RCV BUFFER BYTES GET PUTC PRINTF SETUP _UART PUTC_SEND 343 CCS C 10082015 tx_buffer_full Syntax Parameters Returns Function Availability Requires Examples Example Files Also See va_arg Syntax Parameters Returns Function Availability Requires Examples 344 value tx_buffer_full stream stream optional parameter specifying the stream defined in USE RS232 TRUE if transmit buffer is full FALSE otherwise Function to determine if there is room in transmit buffer for another character All devices USE RS232 USE_RS232 UART1 BAUD 9600 TRANSMIT_BUFFER 50 void main void char c if tx_buffer_full putc c None USE _RS232 RCV BUFFER FULL TX BUFFER FULL RCV BUFFER BYTES GETC PUTC PRINTF SETUP_UART PUTC_SEND va_arg argptr type argptr is a special argument pointer of type va_list type This is data type like int or char The first call to va_arg after va_start return the value of the parameters after that specified by the last parameter Successive invocations return the values of the remaining arguments in succession The function will return the next argument every time it is called All devices INCLUDE lt stdarg h gt int foo int num int sum 0 int i va_list argptr create special argument pointer va_start argptr num initialize argptr for i 0 i lt
146. R options USE TIMER TIMER 1 TICK 1ms BITS 16 NOISR void main void unsigned int16 value 0x1000 set_ticks value None USE TIMER get ticks setup _sd_adc_calibration Syntax Parameters Returns Function 280 setup_sd_adc_calibration model 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 1 SDADC_START_CALIBRATION_MODE 2 SDADC_END_CALIBRATION_MODE Nothing 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 Examples Example Files Also See Built in Functions Only devices with a SD ADC module 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 None setup sd adc read sd adc set sd adc channel set_sd_adc_channel Syntax Parameters Returns Function Availability Examples Example Files Also See set _timerA Syntax Parameters setup_sd_adc channel channel sets the SD ADC channel to read Channel can be 0 to read the difference between CHO and CHO 1 to read the difference between CH1 and CH1
147. Requires Examples Example Files Also See i2c_start Syntax Parameters Returns Function Availability 192 i2c_speed baud i2c_speed stream baud baud is the number of bits per second stream specify the stream defined in USE 12C Nothing This function changes the l2c bit rate at run time This only works if the hardware 12C module is being used All devices USE 12C I2C_Speed 400000 none i2c poll i2c start i2c_ stop i2c_slaveaddr i2c isr state i2c write i2c read USE 12C l2C Overview i2c_start i2c_start stream i2c_start stream restart stream specify the stream defined in USE 12C 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 12C_START and no l2C_STOP undefined Issues a start condition when in the 12C master mode After the start condition the clock is held low until 12C_WRITE is called If another 12C_start is called in the same function before an i2c_stop is called then a special restart condition is issued Note that specific 12C protocol depends on the slave device The l12C_ 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 12C_START as a restart If no parameter is passed a 2 is used only if the compiler compiled a 12C_ START last with no 12
148. Right Operators on the same line are equal in precedence 24 DATA DEFINITIONS Data Definitions This section describes what the basic data types and specifiers are and how variables can be declared using those types In C all the variables should be declared before they are used They can be defined inside a function local or outside all functions global This will affect the visibility and life of the variables A declaration consists of a type qualifier and a type specifier and is followed by a list of one or more variables of that type For example int a b c d mybit e f mybyte g 3 2 char h colors J struct data_record data 10 static int i extern long j Variables can also be declared along with the definitions of the special types For example enum colors red green 2 blue i j k colors is the enum type and i j k are variables of that type SEE ALSO Type Specifiers Basic Types Type Qualifiers Enumerated Types Structures amp Unions typedef Named Registers Type Specifiers Basic Types Type Specifier Range Size Unsigned Signed Digits int1 1 bit number 0 to 1 N A 1 2 int8 8 bit number 0 to 255 128 to 127 2 3 int16 16 bit number 0 to 65535 32768 to 32767 4 5 25 CCS C 10082015 int32 32 bit number 0 to 4294967295 2147483648 to 2147483647 9 10 float32 32 bit float 1 5x10 to 3 4x 10 7 8 C Standard Type Default Type short inti char unsigned int8 int int8 long int16
149. SBN9603 USBN9604 external USB peripheral You can use this external peripheral to add USB to any microcontroller Common definitions and prototypes used by the USB driver 69 CCS C 10082015 usb c The USB stack which handles the USB interrupt and USB Setup Requests on Endpoint 0 usb_cdc h A driver that takes the previous include files to make a CDC USB device which emulates an RS232 legacy device and shows up as a COM port in the MS Windows device manager Relevant getenv Parameters USB Returns TRUE if the PICmicro controller has an integrated internal USB peripheral Example Code Due to the complexity of USB example code will not fit here But you can find the following examples installed with your CCS C Compiler ex_usb_hid c A simple HID device ex_usb_mouse c A HID Mouse when connected to your PC the mouse cursor will go in circles ex_usb_kbmouse c An example of how to create a USB device with multiple interfaces by creating a keyboard and mouse in one device ex_usb_kbmouse2 c An example of how to use multiple HID report Ids to transmit more than one type of HID packet as demonstrated by a keyboard and mouse on one device ex_usb_scope c A vendor specific class using bulk transfers is demonstrated ex_usb_serial c The CDC virtual RS232 library is demonstrated with this RS232 lt gt USB example ex_usb_serial2 c Another CDC virtual RS232 library example this time a port of the ex_intee c example to u
150. SMC_SHUTDOWN_OFF PSMC_SHUTDOWN_NORMAL PSMC_SHUTDOWN_AUTO_RESTART command may be one of the following PSMC_SHUTDOWN_RESTART PSMC_SHUTDOWN_FORCE PSMC_SHUTDOWN_CHECK source may be any of the following or ed together PSMC_SHUTDOWN_C10UT PSMC_SHUTDOWN_C20UT PSMC_SHUTDOWN_C30UT PSMC_SHUTDOWN_C40UT PSMC_SHUTDOWN_IN_PIN pins_high is any combination of the following or ed together PSMC_A PSMC_B PSMC_C PSMC_D PSMC_E PSMC_F Non zero if the unit is now in shutdown This function implements a shutdown capability when any of the listed events activate the PSMC unit will shutdown and the output pins are driver low unless they are listed in the pins that will be driven high The auto restart option will restart when the condition goes inactive otherwise a call with the restart command must be used Software can force a shutdown with the force command All devices equipped with PSMC module 231 CCS C 10082015 Requires Examples Example Files Also See None setup psmc psmc_deadband psmc_sync psmc_blanking psmc modulation psmc_duty psmc freq adjust psmc_pins psmc_sync Syntax Parameters Returns Function Availability Requires Examples Example Files 232 psmc_sync s ave_unit master_unit options slave_unit is the PSMC unit number 1 4 to be controlled master_unit is the PSMC unit number 1 4 to be synchronized to Op
151. SO MO A e ee eee eet 123 O O TN 124 HUSO SINO IEN ORE site casas seats cadet shade E E dh shenss E E 125 FUSE TIMED foie 20s NN 126 FUSE touchpad isc al ee ten 127 EWAN a dad tied tae cats ce 128 A O E 129 O A 130 Built in FUNCIONS iii A A len indian eee oa 131 BUILTIN EUNCTIONS lt td a 131 felora D E A E E Seas craseestadte gh eer ccatte teach a cctv wudte E E A E TA 137 sin cos tan asin acos atan sinh cosh tanh atan2 oooccnnnncccnnnancncnnnonnnonanononnnornncnnnancnnnann nos 137 ade de iii A A Se OL eee eee eee 138 A iu beeen havi Ge eee oe i ee ee 139 LOO is O A A Lerche ie ob Geert ilar losses Sea in ri nas ed Satan diri ci 140 aora td la atacada ld trees 140 O O aA AER EE EEr aapa Ei 141 atoi atol Jato Mii Gene e iteraa Aa ere a ea eae 142 at Clear MIEU ISO a Leche seed baina 142 at disable interrupts ictericia E r e A cae ae a a aaa e 143 at nable Interrupts O uterina dir init 144 Table of Contents at get captura diia edict eed ad eee eh a Mee ee 145 t get missing pulse delay Jurista tern hats cdi eve a eee eet bene ede 145 A O 146 AOS phase COUNT pees tinue E E EON 147 at get resolution Jour iii 147 at get Set POINT iaa dt hate A 148 SN A Sbachaaesaacaueenaesdeeashsaagacpyscidesabsctsasyaatageastseehasvteai 148 NS O 149 Ay interrupt active di AA o OEA el epee daa 150 at set compare mef arsan naer aaaea a ta a ai 151 at set missing pulse delay Juicio cia ea 151 O O ssri raan aaa aa
152. Secondary duty cycle is only used in Independent PWM mode Not available on all devices refer to device datasheet for availability undefined Sets up the specified High Soeed PWM unit Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices Constants are defined in the device s h file set_hspwm_ duty 0x7FFF sets the High Speed PWM master duty cycle set_hspwm_duty 1 0x3FFF sets unit 1 s primary duty cycle None 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_event set_hspwm_event_secondary Syntax Parameters set_hspwm_event settings compare_time set_shwpm_event_secondary settings compare_time if available 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 269 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See compare_time the compare time for the special event to occur undefined Sets up the specified High Soeed PWM unit Only on devices with a built in
153. TODETECT_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 Returns Function Availability Requires Examples Example Files Also See Built in Functions UART_WAKEUP_ON_RDA Wakes PIC up out of sleep when RCV goes from high to low clock l specified this is the clock rate this function should assume The default comes from the USE DELAY undefined Very 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 This function is only available on devices with a built in UART USE RS232 setup_uart 9600 setup_uart 9600 rsOut None USE RS232 putc getc RS232 1 O Overview setup_vref Syntax Parameters Also See setup_vref mode value mode may be one of the following constants FALSE off VREF_LOW for VDD VALUE 24 e VREF_HIGH for VDD VALUE 32 VDD 4 e any may be or ed with VREF_A2 value is an int 0 15 Voltage Reference Overview setup_wdt Syntax Parameters setup_wdt mode Constants like WDT_18MS WDT_36MS WDT_72MS WDT_144MS WDT_288MS WDT_576MS WDT_1152MS WDT_2304MS For some parts WDT_ON WDT_OFF 319 CCS C 10082015 Warning On older PIC16 devices set up of the prescaler may
154. USB_HW_CCS PIC18F455 include lt 18F4550 h gt fuses HSPLL NOWDT NOPROTECT NOLVP nones Peug a use delay clock 48000000 sl S e Y GQ leds ordered from bottom to top ROM Data EE Breaks Stack DEFINE LED1 PIN_AS green er Peripherals Eval Monitor nen Log RTOS Tasks Debug Configure ANA Icb use Debugging Windows Compile Reload Mouse over eval True Debugger control is done in the debugging windows These Timeout Mouse over Tos windows allow you set breakpoints single step watch variables and i more Mouse over radix Default Userstream enabled False Echo on Monitor True Monitor Font Size 9 ICD FAW CCS 2 96 When TRUE the target will be reloaded after every Apply Pc 0001 W 00 CCS C 10082015 Status Bar The status bar gives the user helpful information like the cursor position project open and file being edited 12 10 kset Modfed Pi DG S OCSC Projects EFSSK22 300 po DG 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 SS Overview PROGRAM SYNTAX Overall Structure A program is made up of the following four elements in a file Comment Pre Processor Directive Data Definition Function Definition Statements Expressions Every C program must contain a main function which is the starti
155. _CANTX1 CAN Transmit buffer 0 has completed transmission INT_CANWAKE Bus Activity wake up has occurred on the CAN bus INT_CCP2 Capture or Compare on unit 2 INT_CCP4 Capture or Compare on unit 4 INT_COMP Comparator detect INT_COMP1 Comparator 1 detect INT_CR Cryptographic activity complete INT_ETH Ethernet module interrupt INT_EXT1 External interrupt 1 INT_EXT3 External interrupt 3 INT_IC1 Input Capture 1 CCS C 10082015 IC3DR Input Capture 3 Direction Change Interrupt INT_LOWVOLT Low voltage detected INT_L INT_OSC_FAIL System oscillator failed INT_PMP Parallel Master Port interrupt INT_PWMTB PWM Time Base INT_RA INT_RB Port B any change on B4 B7 INT_RDA RS232 receive data available INT_RDA1 RS232 receive data available in buffer 1 INT_RTCC Timer 0 RTCC overflow INT_SSP SPI or 12C activity HINT _SSP2 INT_TBE RS232 transmit buffer empty INT_TBE1 RS232 transmit buffer 1 empty INT_TIMERO Timer 0 RTCC overflow INT_TIMER2 Timer 2 overflow INT_TIMER4 Timer 4 overflow I TIN INT_ULPWU Ultra low power wake up interrupt Note many more INT_ options are available on specific chips Check the devices h file for a full list for a given chip Elements None Purpose These directives specify the following function is an interrupt function Interrupt functions may not have any parameters Not all direct
156. _MEMORY READ PROGRAM FLASH_WRITE_SIZE FLASH_ERASE_ SIZE Example Code device Writes value to program memory location address Erases FLASH_ERASE_SIZE bytes in program memory Writes count bytes to program memory from dataptr to address When address is a mutiple of FLASH_ERASE_SIZE an erase is also performed Read count bytes from program memory at address to dataptr Can be used to put program memory data into the hex file Can be used with DEVICE to prevent the write function from hanging When this is used make sure the eeprom is not written both inside and outside the ISR Interrupt fires when eeprom write is complete Size of program memory Returns 1 if program memory can be read Smallest number of bytes written in flash Smallest number of bytes erased in flash For 18F452 where the write size is 8 bytes and erase size is 64 bytes rom 0xa00 1 2 3 4 5 erase_program_eeprom 0x100 0 write_program_eeprom 0x1000 50x1234 value read_program_eeprom 0x1000 write_program_memory 0x100 0 data 8 read_program_memory 0x1000 Value 8 erase_program_eeprom 0x100 0 write_program_memory 0x101 0 data 8 56 inserts this data into the hex file lerases 64 bytes strting at 0x1000 writes 0x1234 to 0x1000 reads 0x1000 returns 0x1234 erases 64 bytes starting at 0x1000 as 0x1000 is a multiple of 64 and writes 8 bytes from data to 0x1000 reads 8 bytes to value from 0x1000 ler
157. _disable_interrupts Syntax Parameters at_disable_interrupts interrupts interrupts an 8 bit constant specifying which AT interrupts to disable The constants are defined in the device s header file as 143 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See AT_PHASE_INTERRUPT AT_MISSING_PULSE_INTERRUPT AT_PERIOD_INTERRUPT AT_CC3_INTERRUPT AT_CC2_INTERRUPT AT_CC1_INTERRUPT Nothing To disable the Angular Timer interrupts More than one interrupt can be disabled at a time by or ing multiple constants together in a single call or calling function multiple times for eadch interrupt to be disabled All devices with an AT module Constants defined in the device s header file at_disable interrupts AT_PHASE INTERRUPT at_disable interrupts AT PERIOD INTERRUPT AT CCl INTERRUPT None 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_clear_interrupts at interrupt active at setup cc at set compare time at get capture at get status setup at at_enable_interrupts Syntax Parameters Returns Function 144 at_enable_interrupts interrupts interrupts an 8 bit constant specifying which AT interrupts to enable The constants are
158. a 278 SOL OPEN O 278 set_rtcc set_timer0 set _timert set_timer2 set_timer3 set_timer4 set_timer5 279 SOL TICKS cos Sct ON 280 setup sd ade calibration Ja a Se ae 280 setsa ade channel Jetta oe libritos dle is wu 281 SOU O A OS 281 A A 282 A a 283 SOL UISEX lira da A tad E dia det 283 A A e 284 SOM usina A A A ee E 285 setupadc Mode iii A ee lA aa 285 Setup adc POMS liar A a a 286 setup ade reference G rrisnin dell cie Erea EAE Eaa aAA a opa Aa Eada neue tenes Cita 286 LIAU o Me L D EEEE AE T 287 setup_ccp1 setup_ccp2 setup_ccp3 setup_ccp4 setup_ccp5 setup_CCOpBl ooccccccccnnccnccc 287 setup_clc1 setup _clc2 setup_clc3 setup_clc4 ooccoonnnccccccnnncccnooncccncnnnconnnnnoncccnnncnnnnnrnnccnnnnnannnnnnccnnnnnns 289 setup coMparator amino en eben wicauievise tain Dalebiey etna ees aude 290 SOLUP COUNTOFS E E ET ek Gaal sadsdnsnie cok Gdpes sStuesnaeaabesessescepapsicesiasen saatecsevigecaj E 291 TN s des eslievie E ee eevee eevee as aver a ee teeta ial nea 291 setup Cc O PEE st A a E E 292 SOLUPCWO stack E Sich ela tok Aenea edie api 293 O O 294 setup dedicated adicta cea Bact E E E ET 294 setup external Me Yi ia ria 295 setup high Speed adC e at A ete ate ve ean Ata 296 Setup high speed ade Pal ridad lada oes 296 setup shspwm blanking Jesss aaa ei aaa a aai a A e setaccavasddteskieagiseuseddeasbactecsuyacdasusueapdsaeies 297 setup hspwm Chop Clock ac
159. a E ENE ai 295 AM cl AP O O E 296 SOU hah SCS ade PA ut 296 setup OSI Dania a e ea 297 SON SUIT CON ER la oi ope ea 298 QUA TSE CEM cuota piel atar lila 299 O O E E dusieadTachaset A EES 299 setup hspwm solup Hepwm SECONDARY lona 300 setup hspwm unit chop lock hno dnde 301 SEE IN E E E A E A E E E EA TE 302 A e A TE 303 A NICE D E ai sessed eves E E E E eg A A A S 303 setup_opampi setup opamp2 setup OPAMp3 cccocconnonccnnnccnnnnncnncnnnnon nn rancia 304 St eeel eIn Dual 305 LNA e E OIEA CO A deepens E T E 305 A A ch gc E E AE EEE EAE A E TE AE E ETE 306 sep pmplopion Address MASK iari ced egiseseaede cece la pu Eae ea eE E giaa aA E Eee EE AREE nE EREE 307 setu SUNN eee cae E PA E E E ES E AE E A EE E EE A A O E E A E 308 A E E UTIL A E A E 309 SEO OWEN ITN SE oes oa EEE E E 311 setip psp opion address MaSK oi 311 setup pwmi setup pwm2 setup pwm3 SL NoE E iaa 312 SSUES IME E E E T E E E T 313 NA a 313 SE R E a EA 314 USO AO Dia iia E E E E a 314 eL EE 8 AAN E T E AE 315 AAE ESQUEL EE 316 Se E O E E E E E E A E A A E E AE 316 A E E E E E E E E EE E EE 317 SUN AMET vos cues seed sna steed E dd E A 318 Ae A UU A E E 318 Hee A E N o 319 GUM ANG A See alg Reach oe cn E E A E E A E A A E ES E N EAT 319 UNS eaa NN 320 Sna A E E E E E E T E A O 320 E E E L E E E E E E 321 A EE EEE EE E E E A EE E A AA EE EA E E P TA E A E TT 322 AR E E E E A E T 322 SIDO erto l ici ia 324 A E A E A A E E 324 UNT 325 A A A TE un O 3
160. a change and clock change LSB is sent first MSB is sent first default Specify a stream name for this protocol Use the hardware pins for SPI Port 1 Use the hardware pins for SPI Port 2 Use the pic hardware SPI Don t initialize the hardware SPI Port The SPI library contains functions to implement an SPI bus After setting all of the proper parameters in USE SPI the spi_xfer function can be used to both transfer and receive data on the SPI bus The SPI1 and SPI2 options will use the SPI hardware onboard the PIC The most common pins present on hardware SPI are DI DO and CLK These pins don t need to be assigned values through the options the compiler will automatically assign hardware specific values to these pins Consult your PIC s data sheet as to where the pins for hardware SPI are If hardware SPI is not used then software SPI will be used Software SPI is much slower than hardware SPI but software SPI can use any pins to transfer and receive data other than just the pins tied to the PIC s hardware SPI pins The MODE option is more or less a quick way to specify how the stream is going to sample data MODE O sets IDLE 0 and SAMPLE_RISE MODE 1 sets IDLE 0 and SAMPLE_FALL MODE 2 sets IDLE 1 and SAMPLE_FALL MODE 3 sets IDLE 1 and SAMPLE_RISE There are only these 4 MODEs SPI cannot use the same pins for DI and DO If needed specify two streams one to send data and another to receive data The pins must b
161. a character from separator string s2 which can be different from call to call and returns pointer to it First call starts at beginning of s1 searching for the first character NOT contained in s2 and returns null if there is none are found If none are found it is the start of first token return value Function then searches from there for a character contained in s2 If none are found current token extends to the end of s1 and subsequent searches for a token will return null If one is found it is overwritten by 0 which terminates current token Function saves pointer to following character from which next search will start Each subsequent call with 0 as first argument starts searching from the saved pointer All devices INCLUDE lt string h gt char string 30 term 3 ptr strcpy string one two three strcpy term ptr strtok string term while ptr 0 puts ptr ptr strtok 0 term Prints one two three ex Stre strxxxx strcpy 337 CCS C 10082015 strtol Syntax Parameters Returns Function Availability Requires Examples Example Files Also See strtoul Syntax Parameters Returns Function 338 result strtol npir amp endptr base nptr and endptr are strings and base is an integer result is a signed long int returns the converted value in result if any If no conversion could be performed zero is
162. a non standard C feature to implement a constant array of variable length strings The syntax is const char id n string string Where n is optional and id is the table identifier For example const char colors Red Green Blue ROM directive Another method is to use rom to assign data to program memory The syntax is rom address data data data For example Places 1 2 3 4 to ROM addresses starting at 0x1000 rom 0x1000 1 2 3 4 Places null terminated string in ROM rom 0x1000 hello This method can only be used to initialize the program memory Built in Functions The compiler also provides built in functions to place data in program memory they are e write program _eeprom address data Writes data to program memory e write program memory address dataptr count Writes count bytes of data from dataptr to address in program memory Please refer to the help of these functions to get more details on their usage and limitations regarding erase procedures These functions can be used only on chips that allow writes to program memory The compiler uses the flash memory erase and write routines to implement the functionality The data placed in program memory using the methods listed above can be read from width the following functions e read program memory address dataptr count Reads count bytes from program memory at address to RAM at dataptr These functi
163. aE EA a Eaa ASEE 144 Eo AcE I oir iO ia 145 al get missing pulse delay Y i nikasi o ie ea 145 a oe Oria r rA Pa e EE Ea EEEa E ENET 146 al ST E a O E T E 147 ER eE E E E ere E E E etree errr cere 147 eO E DU odia 148 at get set poini CUO eee ea ae cado eaa rE ae ea aae Tra cade Arae aa Aa Ea raa Aaa E AE A a ENE E a A AAEE AE Eaa 148 EE e EE E E E AS 149 A ea E EAE E E A NO 150 al Set compare MNE socia ln pi 151 al set missing pulse Gela ea epi 151 pal Bat RENIN O 152 AN A E fale ce heh gnc a E EE eat cute E O E E A T 152 SOU EE eee he a e e a eres a antenna 153 DA A idos 154 A A E 154 e a 155 BAUME ROM OTIS E ia ici 156 A PO O eses 4Febeeagecs esa ndveee sand deevereddivee dienes seeeivtaneddeees 156 A O sbacsv nei asensgunaPeaysadianak A 157 25 1 JU O sc ss sa a E A PEE ets haces EEN A E E E A EA S 157 clc1 setup gate _clc2 setup gate clc3 setup gate clc4 setup gatel ccooncccnnnnncicnonenccnnnnnonnnnnnnonannnos 158 clc1_setup input clc2 setup input clc3 setup input clc4 setup input cccccccccccccccnonononononononononononons 159 PEAR WARSI E E E E A E E sive sien aad anata E E E E 160 clear pwm1_interrupt clear pwm2 interrupt clear pwm3_interrupt clear pwm4 interrupt clear pwmb5 interrupt clear pwm6_interrupt cccccccccconnnccnnncnccononononnnnnononocononnnnnononoronnnnnonononoronnnnnncononrennnnnnnns 160 A ss cnc d 2a shat dacs naan Qe vais ace nate teh nade tauis naan desk rean dashes deed shdaddenpang d
164. able uart use first hardware UART on PIC use rs232 uart1 baud 9600 print a string printf enter a character get a character if kbhit c getc RTOS check if a character has been received read character from UART These functions control the operation of the CCS Real Time Operating System RTOS This operating system is cooperatively multitasking and allows for tasks to be scheduled to run at specified time intervals Because the RTOS does not use interrupts the user must be careful to make use of the rtos_yield function in every task so that no one task is allowed to run forever Relevant Functions rtos_run rtos_terminate rtos_enable task rtos_disable task 60 Begins the operation of the RTOS All task management tasks are implemented by this function This function terminates the operation of the RTOS and returns operation to the original program Works as a return from the rtos_run function Enables one of the RTOS tasks Once a task is enabled the rtos_run function will call the task when its time occurs The parameter to this function is the name of task to be enabled Disables one of the RTOS tasks Once a task is disabled the rtos_run function will not call this task until it is enabled using rtos_enable The parameter to this function is the name of the task to be disabled Functional Overview rtos_msg_poll Returns true if there is data in the ta
165. ace Same as x0b Question Mark Same as x3f Single Quote Same as x22 Double Quote Same as x22 W A Single Backslash Same as x5c String null is added to the end 21 CCS C 10082015 identifiers ABCDE ID X ID X X ID ID ID gt ID Operators 22 Up to 32 characters beginning with a non numeric Valid characters are A Z 0 9 and _ underscore By default not case sensitive Use CASE to turn on Single Subscript Multiple Subscripts Structure or union reference Structure or union reference Addition Operator Addition assignment operator x y is the same as x x y Array subscrip operator Bitwise and assignment operator x amp y is the same as x x amp y Address operator Bitwise and operator Bitwise exclusive or assignment operator x y is the same as X x y Bitwise exclusive or operator Bitwise inclusive or assignment operator xl y is the same as x Xly Bitwise inclusive or operator Conditional Expression operator Decrement Division assignment operator x y is the same as x x y Division operator Equality Greater than operator Greater than or equal to operator Increment Indirection operator lt lt lt lt lt amp amp sizeof Expressions Inequality Left shift assignment operator x lt lt y is the same as x x lt lt y Less than operator Left Shift operator Less than or equal to operator Logical AND operator Logical negation operato
166. acs sna cdbaapaisandiagsdeabanptaendinedaaaeasedaeaaiasdbeaianeures 161 OE TOTAL a a rss 162 cie cale J cre caleg cre CAMA ui e asas 162 A SoeieTyecs sedaasasieisied wbatrendsddeavaestestenesadeieeced 163 a 163 A o dak nncadts nadag A E E aenciaeaeeageaedeaiseapiaes 164 AG Will loa cd eeas 164 TE A D E E E E LL sie ARR 165 131 CCS C 10082015 Hi Mi an 165 RN 166 ls O EEA 167 disable pwm1 interrupt disable pwm2_interrupt disable pwm3_interrupt disable pwm4 interrupt disable pwm5 interrupt disable pwm6_interrupt eee eeeeeeneeeeeneeeeeeneeereeaees 168 A RT 169 A EEEE A E A AA AET A E AET 169 enable pwm1 interrupt enable pwm2_interrupt enable pwm3_interrupt enable pwm4_interrupt enable pwm5_interrupt enable pwm6_interrupt cccccccncccncccccncncnnnnncneninininininininss 170 ADO E A E E E E annette 171 SASS EEE A LoL E E E E A 171 AE o E E EE T E EAE E AEN E sands nae E ET 172 MT 173 A E A E E E E AE EEE E A A EE EE E EE se acees conevaine seen canssussueeesepateenconaceentus 173 getc geteh qeterart Y Mel Loc Ea doi 174 NT 175 A e casi AE E A E S 175 A ae A eee Oa E E E E E EE 176 iEn 2 Jee E EE E E N E sae sine sdusgwvantaad aagnasulaece lldnaadbsaunlostaauunayauuenaeegs 176 AO 177 CA A 177 gat Espe Me asusta lo o is is 178 get CIN e A aa A AE Eaa E EAA REE 178 JET ASI BADIA Loi E E E E E 179 Eo 91001 LL E 1 0 A E E 180 A A opt easazauatsdtesdnuanaiansecdiags 180 A etselis
167. air 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 ANO 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 245 CCS C 10082015 Returns Function Availability Requires Examples 246 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 Undefined 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 lp Determine which ADC pairs are set for GLOBAL_SOFTWARE_TRIGGER 2 Clear the corresponding ready flags if doing a start 3 Set th
168. al Refer to the help for more advanced options Checks the condition and if false prints the file name and line to STDERR Will not generate code if DEFINE NODEBUG is used Prints the message and the last system error to STDERR When using transmit buffer used to transmit data from buffer See function description for more detail on when needed When using receive buffer returns the number of bytes in buffer that still need to be retrieved When using transmit buffer returns the number of bytes in buffer that still need to be sent When using transmit buffer returns TRUE if transmit buffer is full When using receive buffer returns TRUE if receive buffer is full Configures the compiler to support RS232 to specifications Interrupt fires when the receive data available Interrupt fires when the transmit data empty Some chips have more than one hardware uart and hence more interrupts 59 CCS C 10082015 Relevant Include Files None all functions built in Relevant getenv parameters UART AUART UART_RX UART_TX UART2_RX UART2_TX Example Code Returns the number of UARTs on this PIC Returns true if this UART is an advanced UART Returns the receive pin for the first UART on this PIC see PIN_XX Returns the transmit pin for the first UART on this PIC Returns the receive pin for the second UART on this PIC TX Returns the transmit pin for the second UART on this PIC configure and en
169. also provides interrupt on overflow The options available are listed in the device s header file Relevant Functions setup_timer_B mode set_timerB value value get_timerB Relevant Preprocessor None Relevant Interrupts INT_TIMERB Relevant Include Files Relevant getenv parameters TIMERB Example Code setup_timer_B TB_OFF or setup_timer_B TB_INTERNAL TB_DIV_8 set_timerB 0 time get_timerB Disable or sets the source and prescale for timerB Initializes the timerB clock counter Returns the value of the timerB clock counter Interrupt fires when timerB overflows None all functions built in Returns 1 if the device has timerB disable timerB sets the internal clock as source and prescale as 8 At 20MHz timerB will increment levery 1 6us in this setup and overflows every 409 6us this sets timerB register to 0 this will read the timerB register value 67 CCS C 10082015 USB Universal Serial Bus or USB is used as a method for peripheral devices to connect to and talk to a personal computer CCS provides libraries for interfacing a PIC to PC using USB by using a PIC with an internal USB peripheral like the PIC16C765 or the PIC18F4550 family or by using any PIC with an external USB peripheral the National USBN9603 family Relevant Functions usb_init usb_init_cs usb_task Initializes the USB hardware Will then wait in an infinite loop for the USB
170. am optional parameter specifying the stream defined in USE RS232 Number of bytes that can still be put into transmit buffer Function to determine the number of bytes that can still be put into transmit buffer before it Availability Requires Examples Example Files Also See Built in Functions 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 All devices USE RS232 USE_RS232 UART1 BAUD 9600 TRANSMIT BUFFER 50 void main void unsigned int8 Count 0 while TRUE if tx buffer available gt 13 printf r nCount 33u Count None USE _RS232 rcv TX BUFFER FULL RCV BUFFER BYTES GET PUTC PRINTF SETUP _UART PUTC SEND tx_buffer_bytes Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value tx_buffer_bytes stream stream optional parameter specifying the stream defined in USE RS232 Number of bytes in transmit buffer that still need to be sent Function to determine the number of bytes in transmit buffer that still need to be sent All devices USE RS232 USE_RS232 UART1 BAUD 9600 TRANSMIT_BUFFER 50 void main void char string Hello if tx_buffer_bytes lt 45 printf s string None USE _RS232 RCV BUFFER FULL TX BUFFE
171. are and PWM The source in capture compare mode can be timer1 or timer3 and in PWM can be timer2 or timer4 The options available are different for different devices and are listed in the device header file In capture mode the value of the timer is copied to the CCP_X register when the input pin event occurs In compare mode it will trigger an action when timer and CCP_x values are equal and in PWM mode it will generate a square wave Relevant Functions setup_ccp1 mode set_pwm1_duty value Relevant Preprocessor None Relevant Interrupts Sets the mode to capture compare or PWM For capture The value is written to the pwm1 to set the duty 43 CCS C 10082015 INT_CCP1 Interrupt fires when capture or compare on CCP1 Relevant Include Files None all functions built in Relevant getenv parameters CCP1 Returns 1 if the device has CCP1 Example Code int_ccp1 void sr rise CCP_1 CCP_1 is the time the pulse went high fall CCP_2 CCP_2 is the time the pulse went low pulse_width fall rise pulse width setup_ccp1 CCP_CAPTURE_RE Configure CCP1 to capture rise setup_ccp2 CCP_CAPTURE_FE Configure CCP2 to capture fall setup_timer_1 T1_INTERNAL Start timer 1 Some chips also have fuses which allows to multiplex the ccp pwm on different pins So check the fuses to see which pin is set by default Also fuses to enable disable pwm outputs Code Profile Profile a program while it is run
172. as and may be PWMx or CCPx Selects the CCP to use x being the module number to use OUTPUT PIN_xx Selects the PWM pin to use pin must be one of the CCP pins If device has remappable pins compiler will assign specified pin to specified CCP module If CCP module not specified it will assign remappable pin to 119 CCS C 10082015 TIMER x FREQUENCY x PERIOD x BITS x DUTY x PWM_ON PWM_OFF STREAM id first available module Selects timer to use with PWM module default if not specified is timer 2 Sets the period of PWM based off specified value should not be used if PERIOD is already specified If frequency can t be achieved exactly compiler will generate a message specifying the exact frequency and period of PWM If neither FREQUENCY or PERIOD is specified the period defaults to maximum possible period with maximum resolution and compiler will generate a message specifying the frequency and period of PWM or if using same timer as previous stream instead of setting to maximum possible it will be set to the same as previous stream If using same timer as previous stream and frequency is different compiler will generate an error Sets the period of PWM should not be used if FREQUENCY is already specified If period can t be achieved exactly compiler will generate a message specifying the exact period and frequency of PWM If neither PERIOD or FREQUENCY is specified the period defaults to maximum possible period with maximum
173. ases 64 bytes starting at 0x1000 writes 8 bytes from data to 0x1000 read_program_memory 0x100 0 value 8 Functional Overview reads 8 bytes to value from 0x1000 For chips where getenv FLASH_ERASE_ SIZE gt getenv FLASH_WRITE_SIZE WRITE_PROGRAM_EEPRO M Writes 2 bytes does not erase use ERASE_PROGRAM_EEPROM WRITE_PROGRAM_MEMOR Writes any number of bytes will erase a block whenever the first lowest byte Y ERASE_PROGRAM_EEPRO M in a block is written to If the first address is not the start of a block that block is not erased Will erase a block The lowest address bits are not used For chips where getenv FLASH_ERASE_SIZE getenv FLASH_WRITE_SIZE WRITE_PROGRAM_EEPROM WRITE_PROGRAM_MEMORY ERASE_PROGRAM_EEPROM PSP Writes 2 bytes no erase is needed Writes any number of bytes bytes outside the range of the write block are not changed No erase is needed Not available These options let to configure and use the Parallel Slave Port on the supported devices Relevant Functions setup_psp mode psp_output_full psp_input_full psp_overflow Relevant Preprocessor None Relevant Interrupts INT_PSP Relevant Include Files None all functions built in Relevant getenv parameters PSP Example Code while psp_output_full psp_data command while input_buffer_full if psp_overflow error true else data psp_data Enables disables the psp port on
174. assed as well Before processing can begin the function creates a special argument pointer of type va_list All devices INCLUDE lt stdarg h gt int foo int num int sum 0 int i va_list argptr create special argument pointer va_start argptr num initialize argptr for i 0 i lt num i sum sum va_arg argptr int va_end argptr end variable processing return sum 211 CCS C 10082015 Example Files Also See offsetof value offsetof stype field Syntax Parameters stype is a structure type name Returns Function Availability Requires Examples Example Files 212 void main int total total foo 2 4 6 9 10 2 None va_start va_end va_arg offsetofbit value offsetofbit stype field Field is a field from the above structure An 8 bit byte These functions return an offset into a structure for the indicated field offsetof returns the offset in bytes and offsetofbit returns the offset in bits All devices INCLUDE lt stddef h gt struct time structure int hour min sec int zone 4 intl daylight savings x offsetof time structure sec x will be 2 x offsetofbit time structure sec x will be 16 x offsetof time structure daylight_savings x will be 3 x offsetofbit time structure daylight_savings x will be 28 None Also See output_x Syntax
175. ate 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 Requires Examples Example Files Also See Built in Functions All devices Pin constants are defined in the devices h file while input PIN Bl waits for Bl to go high if input PIN AO printf A0 is now high r n int16 i PIN Bl while i waits for Bl to go high ex_pulse c input_x output _low output high USE FIXED_lO USE FAST 10 USE STANDARD 10 General Purpose I O input_change_x Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value input_change_a value input_change_b value input_change_c value input_change_d value input_change_e value input_change_1 value input_change_g value input_change_h value input_change_ value input_change_k None An 8 bit or 16 bit int representing the changes on the port 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 All devices None pin check input _change b None input input x output x USE FIXED 10 USE FAST 10
176. ax local variable declaration printf Sampling printf function included in the RS232 library setup port _a ALL ANALOG A D setup functions built in setup adc ADC CLOCK INTERNAL Internal clock always works set_adc channel 0 Set channel to ANO do forever statement min 255 max 0 for i 0 1 lt 30 1 Take 30 samples delay ms 100 Wait for a tenth of a second value read_adc A D read functions built in if value lt min Find smallest sample min value if value gt max Find largest sample max value printf n rMin 2X Max 2X n r min max while TRUE 14 do STATEMENTS Statements STATEMENT Example if expr stmt else stmt LE x 25 x 0 else xX x 1 while expr stmt while get _rtcc 0 do stmt while expr for expr1 expr2 expr3 stmt switch expr case cexpr stmt one or more case default stmt ah return expr goto label label stmt break continue expr stmt Zero or more declaration Note Items in are optional pute n do putc c getc while c 0 for i 1 i lt 10 i printf Su r n i switch cmd case 0 printf cmd 0 break case le joresliaicic enel 1 break default printf bad cmd break return 5 goto loop loop i break continue i l la 1 all py int 1 15 CCS C 10082
177. ay include asserts in your code for testing and quickly eliminate them from the final program All devices assert h and USE RS232 assert number of entries lt TABLE SIZE 139 CCS C 10082015 Example Files Also See atoe Syntax Parameters Returns Function Availability Requires Examples Example Files Also See atof Syntax Parameters Returns Function 140 If number of entries is gt TABLE SIZE then the following is output at the RS232 Assertion failed file myfile c line 56 None USE RS232 RS232 I O Overview atoe string string is a pointer to a null terminated string of characters Result is a floating point number Converts the string passed to the function into a floating point representation If the result cannot be represented the behavior is undefined This function also handles E format numbers All devices INCLUDE lt stdlib h gt char string 10 float32 x 12E3 x atoe string x is now 12000 00 strcpy string None atoi atol atoi32 atof printf result atof string string is a pointer to a null terminated string of characters Result is a floating point number Converts the string passed to the function into a floating point representation If the result cannot be represented the behavior is undefined Availability Requires Examples Example Files Also See Built in F
178. buffer without waiting for transfer to be completed Can be used in conjunction with spi_xfer with no parameters to transfer more then 8 bits for PCM and PCH device or more then 8 bits or 16 bits XFER16 option for PCD Function is useful when using the SSP or SSP2 interrupt service routines for PCM and PCH device or the SPIx interrupt service routines for PCD device Availability This function is only available on devices with SPI hardware Requires USE SPI and the option SLAVE is used in USE SPI to setup PIC as a SPI slave device Examples spi_prewrite data_out Example Files ex_spi_slave c Also See USE SPI spi_xfer spi_xfer_in spi _init spi_speed spi_read spi_read2 Syntax value spi_read data value spi_read2 data Parameters data optional parameter and if included is an 8 bit int Returns An 8 bit int 328 Function Availability Requires Examples Example Files Also See Built in Functions Return a value read by the SPI If a value is passed to the spi_read the data will be clocked out and the data received will be returned If no data is ready spi_read will wait for the data is a SLAVE or return the last DATA clocked in from spi_write If this device is the MASTER then either do a spi_write data followed by a spi_read or do a spi_read data These both do the same thing and will generate a clock If there is no data to send just do a spi_read 0 to
179. called cooperative multi tasking Syntax Elements Purpose Examples Also See use spi Syntax Elements 124 USE RTOS options options are separated by comma and may be timer X Where x is 0 4 specifying the timer used by the RTOS minor_cycle time Where time is a number followed by s ms us ns This is the longest time any task will run Each task s execution rate must be a multiple of this time The compiler can calculate this if it is not specified statistics Maintain min max and total time used by each task This directive tells the compiler which timer on the PIC to use for monitoring and when to grant control to a task Changes to the specified timer s prescaler will effect the rate at which tasks are executed This directive can also be used to specify the longest time that a task will ever take to execute with the minor_cycle option This simply forces all task execution rates to be a multiple of the minor_cycle before the project will compile successfully If the this option is not specified the compiler will use a minor_cycle value that is the smallest possible factor of the execution rates of the RTOS tasks If the statistics option is specified then the compiler will keep track of the minimum processor time taken by one execution of each task the maximum processor time taken by one execution of each task and the total processor time used by each task When linking multiple compilation units t
180. cccnncnocccinnccnononennncnnnnnconnnnnnnnnnnncnnnnnnnnnnnncennnnnnnnnnnncenannnnns 245 read ihigh speed Jurista aa A A eee diese ced lated 245 SAA FOM_IMeEMOFY eri A ee SR A Ai ay 247 read sd ado ui av ai an 247 a tener ger ih ealpe cee epee 248 A A O 249 reset oCpU iii Sees Sees ITA e E E A ee a 249 restart Causa a er ee 250 restartaWdtJat ll illa decd Ear E teed bad E T tess 250 FOtate A O paaastensesechecnavces O 251 rotate TOM aria A a ee sce en E e a ae ee 252 rcv alarma dis iia tt A a ti 252 rie alarm WrltO ita ii oa 253 IC anti a a a esau hve a a a A a Uae celeron pile EAA 254 IEC WISE E E E E E A TET 254 A A e e E eo eet Actin E E E eee as 255 ftos disable Joen egiren ta eara A e aan 255 nos enable rreak rasne renn maaa cs e aaea ld Ora DESENES ETETEN ltd ARa Ni 256 nI ane MN Poll EAE AE A AE A EAEE 256 MOS AKES BR KETE e l O E E E E TET 257 ntos msgsend Jirsrsn iota tien A ein A E ae ed a eee 257 MOS OVOMTUN Desi ai rada Saba teen ee ee ee 258 TOS AUN tatiana tad ett dr tenets dc dd td y ltda 258 MMOS SIMA iia tii 259 Os Stalin ic Rote De en ee eee eae de eid 259 rtos terminale uan opt ed 260 OS Wan ld Eto Sic tee deo eva uae id la 260 A A renee Sete T E TE 261 Set RR O EA AERE ENES EE r TERESE 262 s t a nalog PINS iaa ree aea Ae ieee Piece eae de bs oe A Ee ee ER 262 ere la i O EE E E E E ed ees ee A ee A ee ed 263 set cog planking e era r ae a r a aa aa a a a Sr e teat eae e eve a a E es 265 set c09 dead Dada
181. ce s h file setup hspwm HSPWM ENABLED HSPWM CLOCK DIV_BY4 0x8000 None 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 setup_hspwm_unit_chop_clock Syntax Parameters Returns Function Availability Requires Examples setup_hspwm_unit_chop_clock unit settings unit the High Speed PWM unit chop clock to setup 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 Undefined Setup and High Speed PWM unit s Chop Clock Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None setup_hspwm_unit chop _clock 1 HSPWM PWMH CHOPPING ENABLED HSPWM PWML CHOPPIJNG ENABLED 301 CCS C 10082015 Example Files Also See HSPWM CLOP CLK SOURCE PWM2H None setup hspwm_ unit set_hspwm_phase set hspwm_duty set_hspwm_event setup hspwm_ blanking setup hspwm trigger s
182. ceive buffer spi_read may be used to read the buffer Availability This function is only available on devices with SPI hardware 330 Requires Examples Example Files Also See spi_xfer Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions Nothing spi_write data_out data_in spi_read eX_spi c spi read spi data is in SPI Overview spi write 16 spi read 16 spi_xfer data spi_xfer stream data spi_xfer stream data bits result spi_xfer data result spi_xfer stream data result spi_xfer stream data bits data is the variable or constant to transfer via SPI The pin used to transfer data is defined in the DO pin option in use spi stream is the SPI stream to use as defined in the STREAM name option in USE SPI bits is how many bits of data will be transferred The data read in from the SPI The pin used to transfer result is defined in the DI pin option in USE SPI Transfers data to and reads data from an SPI device All devices with SPI support USE SPI int i 34 spi_xfer i transfers the number 34 via SPI int trans 34 res res spi_xfer trans transfers the number 34 via SPI also reads the number coming in from SPI None USE SPI 331 CCS C 10082015 SPI_XFER_IN Syntax Parameters Returns Function Availability Requires Examp
183. characters that doesn t overlap the destination and source objects Then the n characters from the temporary array are copied to destination All devices Nothing memcpy amp structA amp structB sizeof structA memcpy arrayA arrayB sizeof arrayA memcpy amp StructA amp databyte 1 char a 20 hello memmove a a 2 5 a is now llo None strcpy memset memset destination value n destination is a pointer to memory value is a 8 bit int nis a 16 bit int On PCB and PCM parts n can only be 1 255 undefined Sets n number of bytes starting at destination to value Be aware that array names are pointers where other variable names and structure names are not and therefore need a amp before them 209 CCS C 10082015 Availability Requires Examples Example Files Also See modf Syntax Parameters Returns Function Availability Requires Examples Example Files Also See _mul Syntax Parameters Returns 210 All devices Nothing memset arrayA 0 sizeof arrayA memset arrayB sizeof arrayB memset structA OxFF sizeof structA None memcpy result modf value 8 integral value is a float integral is a float result is a float The modf function breaks the argument value into integral and fractional parts each of which has the same sign as the argument It stores the integral part as a float in
184. counter rolled over one or more times 1 counter rolled over at least once 0 value returned is valid To get Angular Timer Measured Period All devices with an AT module Nothing result at_get period None at set resolution at get resolution at set missing pulse delay at get missing pulse delay 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_at Built in Functions at_get_phase_counter Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result at_get_phase_counter None A 16 bit integer To get the Angular Timer Phase Counter All devices with an AT module Nothing result at_get phase counter None at set resolution at get resolution at set missing pulse delay at get missing pulse delay at get period 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_at at_get_resolution Syntax Parameters Returns Function Availability Requires Examples result at_get_r
185. cro controller For example if bit O of symbol is set then segment_b0 is set and if segment_b0 is 15 then SEG15 would be set Writes length bytes of data from pointer directly to the LCD segment memory starting with offset Passing a value of 0 7 will change the contrast of the LCD segments 0 being the minimum 7 being the maximum LCD frame is complete all pixels displayed None all functions built in to the compiler Returns TRUE if the device has an Internal LCD Driver Module How each segment of the LCD is set on or off for the ASCII digits 0 to 9 byte CONST DIGIT_MAP 10 OxFC 0x60 OxDA OxF2 0x66 0xB6 OxBE OxE0 OxFE OxE6 Define the segment information for the first digit of the LCD define DIGIT1 COM1 20 COM1 18 COM2 18 COM3 20 COM2 28 COM1 28 COM2 20 COM3 18 1 Displays the digits 0 to 9 on the first digit of the LCD 50 Functional Overview for i 0 i lt 9 i Icd_symbol DIGIT_MAP i DIGIT1 delay_ms 1000 Internal Oscillator Many chips have internal oscillator There are different ways to configure the internal oscillator Some chips have a constant 4 Mhz factory calibrated internal oscillator The value is stored in some location mostly the highest program memory and the compiler moves it to the osccal register on startup The programmers save and restore this value but if this is lost they need to be programmed before the oscillator is functioning properly Som
186. cters differs from the string the function fails and exits If a white space character precedes the ordinary non white space characters then white space 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 All Devices USE RS232 char name 2 unsigned int8 number signed int32 time if scanf Suss ld amp number name amp time printf r nName s Number u Time None RS232 1 O Overview getc putc printf set_cog_blanking Syntax ld name number time set_cog_blanking falling_time rising_time Parameters Returns Function falling time sets the falling edge blanking time rising time sets the rising edge blanking time Nothing 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 265 CCS C 10082015 Availability All devices with a COG module Examples set_cog blanking 10 10 Example Files None Also See setup cog set cog phase set cog dead band cog status cog restart set_cog_dead_band Syntax set_cog dead band falling time rising time
187. ctions A O E ehazaweceds 206 PPP PP A 206 ESARET E OEA A AE AA E AEE A A AN es se ec NE cess esas tenes she eet E ETE 207 ECEE E EET An ON 207 AL E A A eo A 208 memcpy ae o E E E S E E E E EEAS 208 IAEI E EE EE E EEE TE A E EAE T E E 209 O 210 BUM APA A ON 210 A AAA A AT 211 of setof GASOIL icon illo tienen ida 212 A A ono cals che dda na ta cued onde dakdnncsiadslapdeaadicaeasaadu nae iaathaeesanshanecasataeareadeaaacanteaginas 213 TNE NT 22 E lene Noted Wot cde shed A E tad E E be letersi E tedasd 213 A ORR Vs odd face E hed Gd ELLER Spade ec td ddd pode dpc eee ede able lees 214 DUOC OAE ccc cs a E 215 CU O ERPE E E E E EEE e E E E A E AEE 215 A TEE ATE A 216 A E E E E E EE E E E A 217 iea esac E E E E teenage onemmepsenemeneccausinenye 217 A O E E E E 218 A E E EEE AI AE AE E E E E A TE E EATE 218 DO MEA Ti E E E E S E E A E cides Re aethoneeteks 219 Jee ai 220 PUNO Yi a ete Lad aa 221 O e E A 221 ow O E 222 printf _ O O 223 A ei deg lade head eus gucnb E lachevecca tiles sanybste lau ltnnn cha E dadlecduaansd pace E E 224 A A ee saacsiedtaceas eeaceascagaxginsggas2icetsasgasiangeeiscaeanginazesiesa 225 PSNI CUR A A ET E E EA T 226 e ee oc Ad aed etl eae 227 pome weg ASU eio nei died aE E E EEEE E pi ede eh E E eee 228 SEOS O O 228 A NS 230 SEREA MeN EE E E A E EAA E E E E O E 231 EEE os e a ale 232 psp output full psp input full psp overtlow ooocooinnccicoccnrc reci 233 putc_send UIC La a o rana
188. d in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires rtos_msg_send task byte 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 None 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 All devices USE RTOS 257 CCS C 10082015 Examples if kbhit rtos msg send echo getc Also See 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 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 statistics Examples rtos overrun Also See None rtos_run The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax rtos_run Parameters None Returns None Function This function begins the execution of all enabled RTOS tasks This function controls the execution of the RTOS tasks at the allocated rate
189. dc channel read_sd adc set_sd_adc calibration setup_smtx Syntax Parameters setup_smt1 mode period setup_smt2 mode period mode The setup of the SMT module See the device s h file for all aoptions Some typical options include SMT_ENABLED SMT_MODE_TIMER 315 CCS C 10082015 Returns Function Availability Examples Example Files Also See 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 Nothing Configures the Signal Measurement Timer SMT module Only devices with a built in SMT module setup _smt1l SMT_ ENABLED SMT MODE PERIOD DUTY CYCLE ACQ SMT REPEAT DATA ACQ MODE SMT CLK FOSC None smtx_status stmx_start smtx_stop smtx_update smtx reset timer smtx_read smtx write setup_spi setup_spi2 Syntax Parameters Returns Function Also See setup _timer_A Syntax Parameters 316 setup_spi mode setup_spi2 mode mode may be undefined Initializes the Serial Port Interface SPI This is used for 2 or 3 wire serial devices that follow a SPI_MASTER SPI_SLAVE SPI_SS_DISABLED 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 Constants from each group may be or ed together with comm
190. dded automatically Matches an unsigned decimal integer The corresponding argument shall be a pointer to an unsigned integer Matches a long unsigned decimal integer The corresponding argument shall be a pointer to a long unsigned integer Matches a signed decimal integer The corresponding argument shall be a pointer to a signed integer Matches a long signed decimal integer The corresponding argument shall be a pointer to a long signed integer Matches a signed or unsigned octal integer The corresponding argument shall be a pointer to a signed or unsigned integer Matches a long signed or unsigned octal integer The corresponding argument shall be a pointer to a long signed or unsigned integer Matches a hexadecimal integer The corresponding argument shall be a pointer to a signed or unsigned integer Matches a long hexadecimal integer The corresponding argument shall be a pointer to a long signed or unsigned integer Matches a signed or unsigned integer The corresponding argument shall be a pointer to a signed or unsigned integer Matches a long signed or unsigned integer The corresponding argument shall be a pointer to a long signed or unsigned integer 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
191. de 60 O 62 TUM ONO al le A E A 63 A eesti eee ees ees E Eee ate ene ee ogee dene ee ewe eae dee seen rhe ea sees ad ae ee eee 64 TUMOR se E E seeds e ld acaba A platen E E sn 09 2005 Mig A Soe Sepa cesta 1s Nie ea nen bee A Dies 64 A A dre E A E A EAE N E E EEE E ESE E A tea eeee ey 65 E E EA E A EA E E AAEE E E AA 65 Aae E iis E E e a E E AE EA 65 TimerA sn ae ee ee eh es ees s 66 A od cates en ee eee eee lee Dewees deen Ponape by cp a dg od aug ca ned og eden pean teas Uae E ere ey 67 USD od did di dt E AA Ai ia ld ac 68 E A 70 WDT or Watch Dog TimMer ccoo cian A a eats be a Ea cds 71 Interrupt Enabled EE E ca a ended id 72 SIGTE LLAN Din a E La a ra 73 PrePrOCeSsS ON cd nic stds t encneieanteast 75 PRE PROGESSOR DIRECTORY sirine eine een Aids 75 lt VAOOIESS ita a A eee 77 attribute a nd ea sE 77 ASM HENGASM HSM ASIS cnica tas e a ale ias 78 A A o alah A O OIR can 80 DUI CUNA A A aie eens a o eee ees 80 PPG 35 eevee cu fetes och seed ae lau Gece cn duedet ba secs eu EA EE bos Be cae coe eu tae Seven es re athe etek ek ieee T 80 A O 81 O O E E A E 82 PES F 1e E PE E E E E TE 82 HAM A e earn ie erties ae enrol hei E e elie lee 83 defined nt ti A nie da 84 FEC OVICO capt fe se EAE IA E EE lat S AN tt de Marian 84 MOCVICES dao ie eb e E Edo e 86 it expr Helse elif Hed coo da id di at 87 O qt aid 87 HOXDOMT OPTIONS M E E icons al 88 A i E E EA EE E E A EEE A vers secbedes A obec ean ees eevee AA eda ete eet 89 A E A E
192. 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 will be driven to its active state 0 pin will be inactive All devices equipped with PWM None 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 None setup power pwm setu ower pwm pins set power pwmX dut set _power_pwmx_duty Syntax set_power_pwmX_duty duty Parameters Xis 0 2 4 or 6 Returns Function Availability Duty is an integer between 0 and 16383 undefined 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 All devices equipped with PWM None Requires 273 CCS C 10082015 Examples Example Files Also See set_power pwmx duty 4000 None setup power pwm setup power pwm pins set power pwm override set_pulldown Syntax Parameters Returns Function Availability Requires Examples Example Files Also See set_pullup Syntax Parameters 274 set_Pulldown state pin Pins are defined in t
193. do something else sleep_ulpwu 10 cap will be charged for 10us then goto sleep Example Files None Also See USE DELAY 323 CCS C 10082015 smtx_read Syntax Parameters Returns Function Availability Examples Example Files Also See value_smt1_read which value_smt2_read which which Specifies which SMT registers to read The following defines have been made in the device s header file to select which registers are read SMT_CAPTURED_PERIOD_REG SMT_CAPTURED_PULSE_WIDTH_REG SMT_TMR_REG SMT_PERIOD_REG 32 bit value To read the Capture Period Registers Capture Pulse Width Registers Timer Registers or Period Registers of the Signal Measurement Timer module Only devices with a built in SMT module unsigned int32 Period Period smtl_read SMT CAPTURED PERIOD REG None smtx_status stmx_start smtx_stop smtx update smtx_reset_timer setup SMTx smtx_write smtx_reset_timer Syntax Parameters Returns Function Availability Examples Example Files Also See 324 smt1_reset_timer smt2_reset_timer None Nothing To manually reset the Timer Register of the Signal Measurement Timer module Only devices with a built in SMT module Site Myre s Creme umes iy None setup smtx stmx_start smtx_stop smtx_update smtx_status smtx_read smtx_write Built in Functions smtx_start Syntax
194. e Nothing resultl at_get_capture 1 result2 at_get_capture 2 None setup_at at_set_resolution at_get_resolution at_set_missing_pulse_delay at_get_missing_pulse_delay at_get_phase_counter at_set_set_point at_get_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_status at_get_missing_pulse_delay 145 CCS C 10082015 Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result at_get_missing_pulse_delay None A 16 bit integer To setup the Angular Timer Missing Pulse Delay All devices with an AT module Nothing result at get missing pulse delay None at set resolution at_get resolution at set 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 at at_get_period Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 146 result at_get_period None A 16 bit integer The MSB of the returned value specifies whether the period
195. e setup nco set nco inc value get nco inc value get_nco_inc_value Syntax Parameters Returns Availability Examples Example Files Also See 180 value get_nco_inc_value None current value set in increment registers On devices with a NCO module value get_nco inc value None setup_nco set nco inc value get nco accumulator Built in Functions get_ticks Syntax value get_ticks stream Parameters stream optional parameter specifying the stream defined in USE TIMER Returns a 8 16 or 32 bit integer int8 int16 or int32 Function Returns the current tick value of the tick timer The size returned 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 current_tick current tick get_ticks Example Files None Also See USE TIMER set_ticks get_timerA Syntax value get_timerA Parameters none Returns The current value of the timer as an int8 Function Returns the current value of the timer All timers count up When a timer reaches the maximum value it will flip over to O and continue counting 254 255 0 1 2 Availability This function is only available on devices with Timer A hardware Requires Nothing Examples set_timerA 0 while timerA lt 200 Example Files
196. e 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 in an include file included by all units When a unit is compiled it will output a relocatable object file 0 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 AAA AAA AAA AAA AAA AAA AAA AAA AAA III 1111 This program displays the min and max of 30 comments that explains what the program does and A D samples over the RS 232 interface AAA AAA AAA AAA AAA AAA TTA U ATA ATA TTT AS include lt 16F887 h gt ff preprocessor directive that selects the chip PIC16F887 13 CCS C 10082015 fuses NOPROTECT Code protection turned off use delay crystal 20mhz Lele preprocessor directive that specifies the clock type and speed use rs232 baud 9600 xmit PIN C6 rcv PIN C7 preprocessor directive that includes the rs232 libraries void main main function int i value min m
197. e SCI pins are specified the SCI will be used If a baud rate cannot be achieved within 3 of the desired value using the current clock rate an error will be generated The definition of the RS232_ERRORS is as follows No UART e Bit 7 is 9th bit for 9 bit data mode get and put e Bit 6 set to one indicates a put failed in float high mode With a UART e Used only by get e Copy of RCSTA register except e Bit O is used to indicate a parity error Warning The PIC UART will shut down on overflow 3 characters received by the hardware with a GETC call The ERRORS option prevents the shutdown by detecting the condition and resetting the UART use rs232 baud 9600 xmit PIN_A2 rcv PIN_A3 ex cust c getc putc printf setup uart RS2332 I O overview use rtos The RTOS is only included with the PCW and PCWH packages The CCS Real Time Operating System RTOS allows a PIC micro controller to run regularly scheduled tasks without the need for interrupts This is accomplished by a function RTOS _RUN that acts as a dispatcher When a task is scheduled to run the dispatch function gives control of the processor to that task When the task is done 123 CCS C 10082015 executing or does not need the processor anymore control of the processor is returned to the dispatch function which then will give control of the processor to the next task that is scheduled to execute at the appropriate time This process is
198. e chips have factory calibrated internal oscillator that offers software selectable frequency range from 31Kz to 8 Mhz and they have a default value and can be switched to a higher lower value in software They are also software tunable Some chips also provide the PLL option for the internal oscillator Relevant Functions setup_oscillator mode Sets the value of the internal oscillator and also tunes it The options vary finetune depending on the chip and are listed in the device header files Relevant Preprocessor None Relevant Interrupts INT_OSC_FAIL or INT_OSCF Interrupt fires when the system oscillator fails and the processor switches to the internal oscillator Relevant Include Files None all functions built in Relevant getenv parameters None Example Code For PIC18F8722 setup_oscillator OSC_32MHZ sets the internal oscillator to 32MHz PLL enabled If the internal oscillator fuse option are specified in the fuses and a valid clock is specified in the use delay clock xxx directive the compiler automatically sets up the oscillator The use delay statements should be used to tell the compiler about the oscillator speed Interrupts The following functions allow for the control of the interrupt subsystem of the microcontroller With these functions interrupts can be enabled disabled and cleared With the preprocessor directives a default function can be called for any interrupt that does not have an associa
199. e control this function returns TRUE if the start bit of a character is being sent on the RS232 RCV pin If the RS232 is hardware this function returns TRUE if a character has been received and is waiting in the hardware buffer for getc to read This function may be used to poll for data without stopping and waiting for the data to appear Note that in the case of software RS232 this function should be called at least 10 times the bit rate to ensure incoming data is not lost Availability All devices Requires USE RS232 Examples char timed_getc 200 Built in Functions long timeout timeout_error FALSE timeout 0 while kbhit amp amp timeout lt 50000 1 2 second delay _us 10 if kbhit return getc else timeout_error TRUE return 0 Example Files ex_tgetc c Also See getc USE RS232 RS232 I O Overview label_address Syntax value label_address abe Parameters label is a C label anywhere in the function Returns A 16 bit int in PCB PCM and a 32 bit int for PCH PCD Function This function obtains the address in ROM of the next instruction after the label This is not a normally used function except in very special situations Availability All devices Requires Nothing Examples start a btc lt lt 2 end printf It takes lu ROM locations r n label_address end label_address start Example Files setimp h Also See goto address 201
200. e do rE 15 DA A Se rT oP Pr BD PT TT E 16 While dad talado edo ea are 16 O setamoaGs dave Sagi Sean ET 17 A tte sti seta ct hc thst SS fats Aint sth ee Reno s NS emake ohs8 obo od zt tle tli oeooa ak cc 2 he tesa Patel cell cd Wes ket aca a Ea 17 SWITCH O 17 A ee ee ee eee 18 COLO a ee Seay ie acd eases eng Sa sgn aS at ita 18 elole AEEA se dey EEA E A O EE E aitulau nee E E T dda Tata de adavianaeian 18 IEEE EAE AEA AEEA TAE EEA A EA la a TER Ter errr eerT 19 COMUNUG EE AE E E EE E AEE AE EEE E P EE OEE A E A EEE 19 O DEANE E E EE E EEE E E E A Sa EA E E A E Sade N E T ET 19 A A A EE E E A E E E E TE E 20 SUMS ons E S a ld 20 EXPIOSSIONS AEEA T A E T 21 CONSTA AS A A E E A A ee A 21 dentro a a a ae 22 O A 22 Operator PrecedenCe cita Anna Adonis 23 Data DEN SAC acia ai 25 Data DEIAN iO AEA E E O E EA TEE E a 25 Type SPECIES nienn aeaea A Guage eth ete 25 Type Qualifiers A AA TAA E A E A ATE 26 Enumerated POS ui E E E 27 Str ct res and Oi a OS Tao od 28 A fesse shech E ocent Ritebed ee betas Metre teen tbeell hide devtatecnatetee A eee ta viene ee 29 Non RAM Data DePiNItlOn Siisicccccs cccvesavscacccudesseeiveactdecacscasesaatcusdsacscecetvedsvaveidiaihuaussartiandi nedaeads vandaag ida dd 29 Using Program Memory for Data ita 30 NamediRegisters 2 i1 ccna ie dl hoes i ecb eect de yee ed E ce ee 33 FUNCION DETIMITOM es aiiis PE e ee Ee O net a MON OO Le 35 FUNCION DEMI A ds addaedvesdacoadna N sat 35 Overloaded FUNCION ii dad
201. e 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 Examples CCSC FM C PICSTUFF TEST C CCSC FM P T TEST C PCW Overview 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 gt PCW in the compiler Many of these windows can be re arranged and docked into different positions CCS C 10082015 Fait Search Optom Compile View Took Debug Document User toothar ra Unendert ep from Nie Selerti n by suert Eseeran P Sofie Seiecton Format Source Indent ex utb souse c An example of cresting e USI mouse Uses your operati system s MID drivers which on most systees should siresdy installed 3f everything is working the aduen cursor will eovr in circle when comectel to e PC FP This file is part of CCS s PIC USS driver code See USS Ij for more docurentetion end e list of examples MOTE ABOUT ENDPOINT BUFFER SIZE Although tits application sends 4 bytes tu the PC thle demo 1211 defines USE _EP1_TX_ SIZE to amp to allucate bytes for this Pit ex usb mouse o 300 ex Lab uab moue c Line 13811 31 More rio Tenet 1 Teese Gpabled during call lo prevert re ertrency ueb Menu All
202. e global software trigger if doing a start 4 Read the corresponding ADC pairs in order from lowest to highest if doing a read 5 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 Only on dsPIC33FJxxGSxxx devices Constants are define in the device h file 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 ANO 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 ANO AN1 AN8 and AN9 and stores result in result 0 result 1 result 2 Example Files Also See Built in Functions and result 3 None setup high speed adc setup high speed adc pair high speed adc done read_rom_memory Syntax Parameters Returns Function Availability Requires Examples Example Files Also See READ_ROM_MEMORY address dataptr count address is 32 bits The least significant bit should always be 0 dataptr is a pointer to one or more bytes c
203. e is a 32 bit int i8base is a 8 bit int string is a pointer to a null terminated string of characters string is a pointer to a null terminated string of characters Converts the signed int32 to a string according to the provided base and returns the converted value if any If the result cannot be represented the function will return 0 All devices INCLUDE lt stdlib h gt int32 x 1234 char string 5 itoa x 10 string string is now 1234 None None 199 CCS C 10082015 jump_to_isr Syntax jump_to_isr address Parameters address is a valid program memory address Returns No value Function The jump_to_isr function is used when the location of the interrupt service routines are not at the default location in program memory When an interrupt occurs program execution will jump to the default location and then jump to the specified address Availability All devices Requires Nothing Examples int_global void global_isr void jump_to_isr isr_address Example Files Also See ex_bootloader c BUILD kbhit Syntax value kbhit value kbhit stream Parameters stream is the stream id assigned to an available RS232 port If the stream parameter is not included the function uses the primary stream used by getc Returns 0 or FALSE if getc will need to wait for a character to come in 1 or TRUE if a character is ready for getc Function If the RS232 is under softwar
204. e specified with DI DO CLK or SPIx all other options are defaulted as indicated above use spi DI PIN B1 uses software SPI DO PIN BO CLK PIN B2 ENABLE PIN B4 BITS 16 use spi FORCE_ HW BITS 16 stream SPI_STREAM uses hardware SPI and gives this stream the name SPI_STREAM None spi_xfer use standard_io Syntax USE STANDARD 10 port 125 CCS C 10082015 Elements Purpose Examples Example Files Also See portis A B C D E F G H J or ALL This directive affects how the compiler will generate code for input and output instructions that follow This directive takes effect until another USE XXX_IO directive is encountered The standard method of doing I O will cause the compiler to generate code to make an O pin either input or output every time it is used On the 5X processors this requires one byte of RAM for every port set to standard 1 0 Standard_io is the default I O method for all ports When linking multiple compilation units be aware this directive only applies to the current compilation unit use standard io A ex_cust c USE FAST 10 USE FIXED IO General Purpose I O use timer Syntax Elements 126 USE TIMER options TIMER x Sets the timer to use as the tick timer x is a valid timer that the PIC has Default value is 1 for Timer il TICK xx Sets the desired time for 1 tick xx can be used with ns nanoseconds us microseconds ms
205. eak break The break statement is used to exit out of a control loop It provides an early exit from while for do and switch The syntax is break It causes the innermost enclosing loop or switch to be exited immediately Example break Also See Statements continue The continue statement causes the next iteration of the enclosing loop While For Do to begin The syntax is continue It causes the test part to be executed immediately in case of do and while and the control passes the re initialization step in case of for Example continue Also See Statements expr The syntax is expr Example i 1 Also See Statements 19 CCS C 10082015 Statement Example ta Also See Statements stmt Zero or more semi colon separated The syntax is stmt Example a 1 b 1 Also See Statements 20 EXPRESSIONS Constants 123 123L 123LL 0123 0x123 0b010010 123 456 123F 123 4E 5 x 010 AxAS c abcdef Decimal Forces type to amp long UL also allowed Forces type to amp int32 Octal Hex Binary Floating Point Floating Point FL also allowed Floating Point in scientific notation Character Octal Character Hex Character Special Character Where c is one of in Line Feed Same as x0a W Return Feed Same as x0d t TAB Same as x09 W Backspace Same as x08 f Form Feed Same as x0c a Bell Same as x07 v Vertical Sp
206. eceived over the SPI Availability This function is only available on devices with SPI hardware Requires Nothing Examples Ispi data is in amp amp input PIN_B2 if spi data is in data spi_read Example Files None Also See spi read spi write SPI Overview Syntax spi_init baud spi_init stream baud Parameters stream is the SPI stream to use as defined in the STREAM name option in USE SPI band the band rate to initialize the SP module to If FALSE it will disable the SPI module if TRUE it will enable the SPI module to the band rate specified in use SPI Returns Nothing 327 CCS C 10082015 Function Initializes the SPI module to the settings specified in USE SPI Availability This function is only available on devices with SPI hardware Requires USE SPI Examples use spi MATER SPI1 baud 1000000 mode 0 stream SPI1 MODEO spi_init SPI1_MODEO TRUE initialize and enable SPI1 to setting in USE SPI spi_init FALSE disable SPI1 spi_init 250000 initialize and enable SPI1 to a baud rate of 250K Example Files None Also See USE SPI spi_xfer spi_xfer_in spi_prewrite spi_speed spi_prewrite data Syntax spi_prewrite data spi_prewrite stream data Parameters stream is the SPI stream to use as defined in the STREAM name option in USE SPI data the variable or constant to transfer via SPI Returns Nothing Function Writes data into the SPI
207. ed default to timer 1 for PCM and PCH compilers and timer 3 for PCD compiler TICK x The tick time to setup the timer to If not specified it will be set to fastest as possible or if same timer was already setup by a previous stream it will be set to that tick time If using same timer as previous stream and different tick time an error will be generated FASTEST Use instead of TICK x to set tick time to fastest as possible PreProcessor SLOWEST Use instead of TICK x to set tick time to slowest as possible CAPTURE_RISING Specifies the edge that timer value is captured on Defaults to CAPTURE_RISING CAPTURE_FALLING Specifies the edge that timer value is captured on Defaults to CAPTURE_RISING CAPTURE_BOTH PCD only Specifies the edge that timer value is captured on Defaults to CAPTURE_RISING PRE x Specifies number of rising edges before capture event occurs Valid options are 1 4 and 16 default to 1 if not specified Options 4 and 16 are only valid when using CAPTURE_RISING will generate an error is used with CAPTURE_FALLING or CAPTURE_BOTH ISR x STREAM id Associates a stream identifier with the capture module The identifier may be used in functions like get_capture_time DEFINE id Creates a define named id which specifies the number of capture per second Default define name if not specified is CAPTURES_PER_SECOND Define name must start with an ASCII letter A to Z an ASCII letter a to z or an ASCII
208. ed when the system clock is set to run from the internal oscillator delay ms delay us use dynamic_memory Syntax Elements Purpose Examples Example Files Also See 116 USE DYNAMIC_MEMORY None This pre processor directive instructs the compiler to create the _DYNAMIC_HEAD object _DYNAMIC_HEAD is the location where the first free space is allocated USE DYNAMIC MEMORY void main ex_malloc c None PreProcessor use fast_io Syntax Elements Purpose Examples Example Files Also See USE FAST 10 port portis A B C D E F G H J or ALL Affects how the compiler will generate code for input and output instructions that follow This directive takes effect until another use xxxx_lO directive is encountered The fast method of doing I O will cause the compiler to perform I O without programming of the direction register The compiler s default operation is the opposite of this command the direction I O will be set cleared on each I O operation The user must ensure the direction register is set correctly via set_tris_X When linking multiple compilation units be aware this directive only applies to the current compilation unit tuse fast_io A ex_cust c USE FIXED lO USE STANDARD 10 set tris X General Purpose I O use fixed_io Syntax Elements Purpose Examples Example Files Also See use i2c Syntax USE FIXED_lO po
209. ent 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 Only the devices with a built in Parallel Master Port module Requires Constants are defined in the device s h file Examples setup _psp PAR ENABLE Sets up Master mode with address PAR MASTER MODE 1 PAR lines PMAO PMA7 STOP_IN_IDLE Ox00FF Example Files None Also See 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 307 CCS C 10082015 pmp_overflow See header file for device selected setup _psmc Syntax Parameters 308 setup_psmc unit mode period period_time rising_edge rise_time falling_edge fall_time unit is the PSMC unit number 1 4 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 or bar and 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
210. ers None Returns TRUE if PID module is busy or FALSE is PID module is not busy Function To check if the PID module is busy with a calculation Availability All devices with a PID module Requires Nothing Examples pid__get_result PID START ONLY ADCResult while pid_busy pid_get_result PID READ ONLY amp PIDResult Example Files None Also See setup pid pid write pid get result pid read pid_get_result Syntax pid_get_result set_point input amp output Start and Read pid_get_result mode set_point input Start Only pid_get_result mode amp output Read Only pid_get_result mode set_point input amp output Parameters mode constant parameter specifying whether to only start the calculation only read the result or start the calculation and read the result The options are defined in the device s header file as PID_START_READ PID_READ_ONLY PID_START_ONLY set_point a 16 bit variable or constant representing the set point of the control system the value the input from the control system is compared against to determine the error in 218 Returns Function Availability Requires Examples Example Files Also See pid_read Syntax Parameters Returns Built in Functions the system input a 16 bit variable or constant representing the input from the control system output a structure that the output of the PID module will be saved to Eithe
211. erviced during the delay The time spent in the ISR does not count toward the delay time All devices USE DELAY tuse delay clock 20000000 do output_high PIN BO delay _us duty output _low PIN BO delay us period duty while TRUE X_SQw c delay _ms delay cycles USE DELAY disable_interrupts Syntax Parameters Returns Function Availability Requires Examples disable_interrupts evel level a constant defined in the devices h file undefined Disables the interrupt at the given level The GLOBAL level will not disable any of the specific interrupts but will prevent any of the specific interrupts previously enabled to be active Valid specific levels are the same as are used in INT_xxx and are listed in the devices h file GLOBAL will also disable the peripheral interrupts on devices that have it Note that it is not necessary to disable interrupts inside an interrupt service routine since interrupts are automatically disabled Some chips that have interrupt on change for individual pins allow the pin to be specified like INT_RA1 Device with interrupts PCM and PCH Should have a INT_xxxx constants are defined in the devices h file disable interrupts GLOBAL all interrupts OFF disable interrupts INT_RDA RS232 OFF enable interrupts ADC_DONE enable interrupts RB_ CHANGE these enable the interrupts but since the GLOBAL is disabled they
212. es Requires Examples Example Files Also See Built in Functions Timer 3 5 and 7 Some PIC18 and Enhanced PIC16 devices Timer 4 6 8 10 and 12 Some PIC18 and Enhanced PIC16 devices Nothing set_timer0 0 while get_timer0 lt 200 ex_stwt c set_timerx TimerO Overview Timer1 Overview Timer2 Overview Timer5 Overview get_tris_x Syntax Parameters Returns Function Availability Requires Examples Example Files Also See getenv Syntax value get_tris_A value get_tris_B value get_tris_C value get_tris_D value get_tris_E value get_tris_F value get_tris_G value get_tris_H value get_tris_J value get_tris_K None int16 the value of TRIS register Returns the value of the TRIS register of port A B C D E F G H J or K All devices Nothing tris a GET TRIS A None input output _low output _high value getenv cstring 183 CCS C 10082015 Parameters Returns Function 184 cstring is a constant string with a recognized keyword A constant number a constant string or 0 This function obtains information about the execution environment The following are recognized keywords This function returns a constant 0 if the keyword is not understood FUSE_SET fffff FUSE_VALID fffff ID DEVICE CLOCK VERSION VERSION_STRING PROGRAM_MEMORY STACK SCRATC
213. esolution None A 16 bit integer To setup the Angular Timer Resolution All devices with an AT module Nothing result at_get_resolution 147 CCS C 10082015 Example Files None Also See at_set 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_at at_get_set_point Syntax result at_get_set_point Parameters None Returns A 16 bit integer Function To get the Angular Timer Set Point Availability All devices with an AT module Requires Nothing Examples result at_get_set_point Example Files None Also See 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_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 at at_get_set_point_error Syntax result at_get_set_point_error Parameters None Returns A 16 bit integer Function To get the Angular Timer Set Point Error the error of the measured period value compared
214. esult as strcoll s1 s2 Compare m1 to m2 n bytes Find c in first n characters of m1 and return amp m1 i Maps the error number in errnum to an error message string The parameters errnum is an unsigned 8 bit int Returns a pointer to the string s1 and s2 are pointers to an array of characters or the name of an array Note that s1 and s2 MAY NOT BE A CONSTANT like hi Built in Functions nis a count of the maximum number of character to operate on cis a 8 bit character m1 and m2 are pointers to memory Returns ptr is a copy of the s1 pointer iresult is an 8 bit int result is 1 less than O equal or 1 greater than res is an integer Function Functions are identified above Availability All devices Requires include lt string h gt Examples char stringl 10 string2 10 strcpy stringl hi strcpy string2 there strcat stringl string2 printf Length is Sulrin strlen stringl Will print 8 Example Files ex_str c Also See strcpy strtok strcpy strcopy Syntax strcpy dest src strcopy dest src Parameters dest is a pointer to a RAM array of characters src may be either a pointer to a RAM array of characters or it may be a constant string Returns undefined Function Copies a constant or RAM string to a RAM string Strings are terminated with a 0 Availability All devices Requires Nothing 335 CCS C 10082015 Examples char string 10 string2 1
215. et hspwm_override get hspwm_capture setup hspwm_ chop clock setup hspwm setup hspwm_ secondary setup _Icd Syntax Parameters Returns Function Availability Requires Examples 302 setup_lcd mode prescale segmentsO_31 segments32_47 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 See the devices h file for other device specific options 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 SEGO0_4 SEG5_8 SEG9_11 SEG12_15 SEG16_19 SEG20_26 SEG27_28 SEG29_31 ALL_LCD_PINS When using the PIC16F LF1 xxx 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 O corresponds to segment 32 and bit 15 corresponds to segment 47 undefined This function is used to initialize the LCD Driver Module on the PIC16C92X and PIC16F LF193X series of chips Only on devices with built in LCD Driver Module hardware Constants are defined in the devices h file setup _lcd LCD MUX1
216. et_pwml_ phase phase setup pwm set pwm_duty set pwm period clear pwm_ interrupt set pwm_offset enable pwm_interrupt disable pwm_interrupt pwm_interrupt active set_open_drain_x set_open_drain_a value Syntax Parameters set_open_drain_b value set_open_drain_v value set_open_drain_d value 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 value is an 16 bit int with each bit representing a bit of the I O port Returns Function undefined These functions allow the I O port Open Drain Control ODC registers to be set Each bit 278 Availability Requires Examples Example Files Also See set_rtcc Built in Functions 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 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 Nothing set_open_drain_a 0x0001 makes PIN AO an open drain output None output high output low output bit output _x General Purpose I O set_timer0 set_timer1 set_timer2 set_timer3 set_timer4 set_timer5 Syntax Parameters Returns Function Availability Requires Examples Example Files set_timer0
217. etbvay a aks Dll dni atari 182 GOES iii 183 O A 183 goto address Dusan ratd 187 high speedisadc done y muito ati it e a 188 O EAE OE 188 PAS al iii 189 ER erei a ieee cas even ane ee eee oes eee eed ee ete eee eed ae ene eee ea 190 AA A O 190 A A TO 191 HAS gach cesdiee te A EAE ddetstseesgentaetaassheaaseentned 192 IG sStart E steele E E E en he ee ee 192 126 StOP scieseades echt ele itv ET E el aden dened bce i a ee ee Ge EL 193 ICE WING iare etice vtec cae Stats ae cee As Sites cn ten a te teu tuce ches a Ya cee Ty daw deed Venta teGee E N 193 O ear E EE E E E chet ec vanvuats rx ded A E ene da rwueauas siabage A E 194 Nut Change lt ia 195 INpUt State iii inne leet a Roi a ele A ee ee 196 IU XC sccsecctncehghernits gen 196 Memup a E zen teres eetzs Sethe choca lope ecevenenee tail lio 197 isalnum char isalpha char iscntrl x isdigit char isgraph x islower char isspace char isupper char isxdigit char isprint x iSPUNCT X oooonnocccononccnnononcccnnnoncncnnnnnnnn nono nn naar cnn rar n nn nn rn rr rre n rre rn rn rn nrnnns 197 isamong h oeenn a SA eee eee ean eae ea ead taal ade ede ias 198 OAC i hia ia eile de e e a a AO et 199 JUNTA 10 SEG eos cc ae ca tot ae e ea cvs ee avi a E eae E a ante EA 200 KIWI Beaters cat calcein hlen ave O O O 200 label address italien aa N AA AE aaa da eS 201 A ONO 202 ICA COMAS tirada tr taa 202 e O 203 ICA SY MboOlC toun A A ee le ee 203 AP A A A E ee 204 A NO 204 Kero RKO
218. eturns Nothing Function To change the frequency of the PWM signal Warning this may change the resolution of the PWM signal Availability All devices Requires USE PWM Examples USE PWM OUTPUT PIN C2 FREQUENCY 10kHz DUTY 25 pwm_set_frequency 1000 set PWM frequency to 1kHz Example Files None Also See ttuse pwm pwm on pwm_off owm set duty percent pwm set duty 236 Built in Functions pwm1_interrupt_active pwm2_interrupt_active pwm3_interrupt_active pwm4_interrupt_active pwm5_interrupt_active pwm6_interrupt_active Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result_pwm1_interrupt_active interrupt result_pwm2_interrupt_active interrupt result_pwm3_interrupt_active interrupt result_pwm4_interrupt_active interrupt result_pwm5_interrupt_active interrupt result_pwm6_interrupt_active interrupt interrupt 8 bit constant or variable Constants are defined in the device s header file as PWM_PERIOD_INTERRUPT PWM_DUTY_INTERRUPT PWM_PHASE_INTERRUPT PWM_OFFSET_INTERRUPT TRUE if interrupt is active FALSE if interrupt is not active Tests to see if one of the above PWM interrupts is active interrupt flag is set Devices with a 16 bit PWM module Nothing if pwml_interrupt active PWM_PERIOD INTERRUPT clear _pwml_interrupt PWM_PERIOD_INTERRUPT setup pwm set pwm _duty set pwm pha
219. exactly one DEVICE with a chip When linking multiple compilation units this directive must appear exactly the same in each compilation unit Compilation mode selection The compilation mode selection allows existing code to be compiled without encountering errors created by compiler compliance As CCS discovers discrepancies in the way expressions are evaluated according to ANSI the change will generally be made only to the ANSI mode and the next major CCS release Chip Options device PIC16C74 device PIC16C67 16 device 16 ICD TRUE device PIC16F877 16 ADC 10 device f Primes ek a aaa jane io saw touts as Elisa cris de vaddi jine 0 3 Compilation mode selection device CCS2 This will set the ADC to the resolution of the part ex mxram c ex icd c 16c74 h read _adc _ device _ Syntax Elements Purpose Examples Example Files Also See 86 DEVICE None This pre processor identifier is defined by the compiler with the base number of the current device from a DEVICE The base number is usually the number after the C in the part number For example the PIC16C622 has a base number of 622 iE Gevics 7i SETUP ADC PORTS ALL DIGITAL endif None DEVICE PreProcessor if expr else elif endif if expr 2 Syntax Elements code elif expr Optional any number may be used code else Optional code endif expr is an expression with constants s
220. f utilizing 127 CCS C 10082015 Purpose Examples Example Files Also See multiple touch pads each pad will use xx milliseconds to scan for one key press Default is 32ms PiN char If a valid key press is determined on PIN the software will return the character char in the function touchpad_getc Example PIN_B0 A SOURCETIME xxus CTMU only xx is thenumber of microseconds each pin is sampled for by ADC during each scan time period Default is 10us This directive will tell the compiler to initialize and activate the Capacitive Sensing Module CSM or Charge Time Measurement Unit CTMU on the microcontroller The compiler requires use of the TIMERO and TIMER1 modules for CSM and Timer1 ADC modules for CTMU and global interrupts must still be activated in the main program in order for the CSM or CTMU to begin normal operation For most applications a higher RANGE lower THRESHOLD and higher SCANTIME will result better key press detection Multiple PIN s may be declared in options but they must be valid pins used by the CSM or CTMU The user may also generate a TIMERO ISR with TIMERO s interrupt occuring every SCANTIME milliseconds In this case the CSM s or CTMU s ISR will be executed first USE TOUCHPAD THRESHOLD 5 BIN DS 5 PONEROS TCI void main void charte enable interrupts GLOBAL while 1 c TOUCHPAD GETC will wait until a pin is detected if PIN BO is pressed
221. f variables and functions as in the standard C methodology MODULE does add some benefits in that pre processor DEFINE can be given scope which cannot normally be done in standard C methodology Examples int GetCount void 100 Example Files See Also nolist Syntax Elements Purpose Examples Example Files Also See 0CS Syntax Elements Purpose Examples PreProcessor void SetCount int newCount MODULE ale Gj Corbina define G COUNT MAX 100 int GetCount void return g_count void SetCount int newCount if newCount gt G_COUNT MAX newCount G COUNT MAX g_count newCount the functions GetCount and SetCount have global scope but the variable g_ count and the define G COUNT MAX only has scope to this file Sy None EXPORT Invoking the Command Line Compiler Multiple Compilation Unit NOLIST None Stops inserting source lines into the LST file until a LIST NOLIST f f Won e e lutter 0 Tas liste wails include lt cdriver h gt LIST 16c74 h HLIST HOCS x x is the clock s speed and can be 1 Hz to 100 MHz Used instead of the use delay clock x include lt 18F4520 h gt device ICD TRUE OCS 20 MHz fuse rs232 debugger 101 CCS C 10082015 Example Files Also See opt Syntax Elements Purpose Examples Example Files Also See org Syntax Elements Purpose 102 void main No
222. file for all options Some typical options include AT_ENABLED AT_DISABLED AT_MULTI_PULSE_MODE AT_SINGLE_PULSE_MODE Returns Nothing Function To setup the Angular Timer AT module Availability All devices with an AT module Requires Constants defined in the device s h file Examples setup _at AT ENABLED AT MULTI PULSE MODE AT INPUT ATIN Example Files None Also See 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_ccp1 setup_ccp2 setup_ccp3 setup_ccp4 setup_ccp5 setup_ccp6 Syntax setup_ccp1 mode or setup_ccp1 mode pwm 287 CCS C 10082015 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 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_OFF Set CCP to capture mode CCP_CAPTURE_FE Capture on falling edge CCP_CAPTURE_RE Capture on rising edge CCP_CAPTURE_DIV_4 Capture after 4 pulses CC
223. finitions typedef type qualifier type specifier declarator For example mybyte can be used in declaration to specify the int type mybyte can be used in declaration to specify the int type typedef int mybyte typedef short mybit typedef enum red colors can be used to declare green 2 blue colors variable of this enum type SEE ALSO Declarations Type Specifiers Type Qualifiers Structures amp Unions Enumerated Types Named Registers Non RAM Data Definitions CCS C compiler also provides a custom qualifier addressmod which can be used to define a memory region that can be RAM program eeprom data eeprom or external memory Addressmod replaces the older typemod with a different syntax The usage is addressmod name read_function write function start_address end address share Where the read_function and write_function should be blank for RAM or for other memory should be the following prototype read procedure for reading n bytes from the memory starting at location addr void read function int32 addr int8 ram int nbytes write procedure for writing n bytes to the memory starting at location addr void write function int32 addr int8 ram int nbytes For RAM the share argument may be true if unused RAM in this area can be used by the compiler for standard variables Example 29 CCS C 10082015 void DataEE Read int32 addr int8 ram i
224. g I O The user will be responsible for setting the port direction register using the set_tris_x function This directive set particular pins to be used an input or output and the compiler will perform this setup every time this pin is used Returns a 1 if bit b on port p is on this part 49 CCS C 10082015 set_tris b Tris value output_high PIN_B7 If input PIN_BO output_high PIN_B7 Internal LCD Sets B0 B3 as input and B4 B7 as output Set the pin B7 to High Read the value on pin BO set B7 to low if pin BO is high Some families of PIC microcontrollers can drive a glass segment LCD directly without the need of an LCD controller For example the PIC16C92X PIC16F91X and PIC16F193X series of chips have an internal LCD driver module Relevant Functions setup_Icd mode prescale segmenis Icd_symbol symbol segment_b7 segment_b0 Icd_load ptr offset length Icd_contrast contrast Relevant Preprocessor None Relevant Interrupts int_Icd Relevant Inicude Files Relevant getenv Parameters LCD Example Program Configures the LCD Driver Module to use the specified mode timer prescaler and segments For more information on valid modes and settings see the setup_lcd manual page and the h header file for the PIC micro controller being used The specified symbol is placed on the desired segments where segment_b7 to segment_b0 represent SEGXX pins on the PIC mi
225. ger configuration Note for devices with dual SPI interfaces a second function setup_spi2 is provided to configure the second interface spi_data_is_in spi_data_is_in2 spi_write value spi_write2 value spi_read value spi_read2 value Relevant Preprocessor None Relevant Interrupts int_ssp int_ssp2 Relevant getenv Parameters SPI 62 Returns TRUE if the SPI receive buffer has a byte of data Transmits the value over the SPI interface This will cause the data to be clocked out on the SDO pin Performs an SPI transaction where the value is clocked out on the SDO pin and data clocked in on the SDI pin is returned If you just want to clock in data then you can use spi_read without a parameter Transaction read or write has completed on the indicated peripheral Returns TRUE if the device has an SPI peripheral Example Code Functional Overview configure the device to be a master data transmitted on H to L clock transition setup_spi SPI_MASTER SPI_H_TO_L SPI_CLK_DIV_16 spi_write 0x80 value spi_read value spi_read 0x80 Timer0 write 0x80 to SPI device read a value from the SPI device write 0x80 to SPI device the same time you are reading a value These options lets the user configure and use timero It is available on all devices and is always enabled The clock counter is 8 bit on pic16s and 8 or 16 bit on pic18s lt counts up and also provides interrupt on overf
226. gits in the floating point significant LDBL_DIG Number of decimal digits q such that any floating point number with q decimal digits can be rounded into a floating point number with p radix b digits and back again without change to the q decimal digits 351 CCS C 10082015 LDBL_MIN_EXP LDBL_MIN_10_ EXP LDBL_MAX_EXP LDBL_MAX_10_EXP LDBL_MAX LDBL_EPSILON LDBL_MIN limits h limits h CHAR_BIT SCHAR_MIN SCHAR_MAX UCHAR_MAX CHAR_MIN CHAR_MAX MB_LEN MAX SHRT_MIN SHRT_MAX USHRT_MAX INT_MIN INT_MAX UINT_MAX LONG_MIN LONG_MAX ULONG_MAX locale h locale h locale h Iconv SETLOCALE LOCALCONV setjmp h setimp h jmp_buf setjmp longjmp 352 Minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized floating point number Minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers Maximum negative integer such that FLT_RADIX raised to that power minus 1 is a representable finite floating point number Maximum negative integer such that 10 raised to that power is in the range of representable finite floating point numbers Maximum representable finite floating point number The difference between 1 and the least value greater than 1 that is representable in the given floating point type Minimum normalized positive floating point number Number of bits for the smallest object that is n
227. h an AT module Nothing at_set missing pulse delay pulse delay 151 CCS C 10082015 Example Files Also See None at set resolution at get resolution 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 at at_set_resolution Syntax Parameters Returns Function Availability Requires Examples Example Files Also See at_set_resolution resolution resolution a 16 bit constant or variable to set the resolution Nothing To setup the Angular Timer Resolution All devices with an AT module Nothing at_set_resolution resolution None 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_at at_set_set_point Syntax Parameters Returns 152 at_set_set_point set_point set_point a 16 bit constant or variable to set the set point The set point determines the threshold setting tha
228. hat the option XFER16 be used in use SPI data_in spi_read_16 out_data 329 CCS C 10082015 Example Files None Also See spi_read spi_write spi_write_16 spi_data_is_in SPI Overview spi_speed Syntax spi_speed baud spi_speed stream baud spi_speed stream baud clock Parameters stream is the SPI stream to use as defined in the STREAM name option in USE SPI band the band rate to set the SPI module to clock the current clock rate to calculate the band rate with If not specified it uses the value specified in use delay Returns Nothing Function Sets the SPI module s baud rate to the specified value Availability This function is only available on devices with SPI hardware Requires USE SPI Examples spi_speed 250000 spi_speed SPI1_MODEO 250000 spi_speed SPI1_MODEO 125000 8000000 Example Files None Also See USE SPI spi_xfer spi_xfer_in spi_prewrite spi_init spi_write spi_write2 Syntax spi_write wait va ue spi_write2 wait value Parameters value is an 8 bit int wait an optional parameter specifying whether the function will wait for the SPI transfer to complete before exiting Default is TRUE if not specified Returns Nothing Function Sends a byte out the SPI interface This will cause 8 clocks to be generated This function will write the value out to the SPI At the same time data is clocked out data is clocked in and stored in a re
229. he DSM can generate the following types of key modulation schemes e Frequency Shift Keying FSK Phase Shift Keying PSK e On Off Keying OOK Relevant Functions setup_dsm mode source carrier setup_dsm TRUE setup_dsm FALSE Relevant Preprocessor Relevant Interrupts Relevant Include Files Relevant getenv parameters Example Code setup_dsm DSM_ENABLED DSM_OUTPUT_ENABLED DSM_SOURCE_UART1 DSM_CARRIER_HIGH_VSS DSM_CARRIER_LOW_OC1 if input PIN_BO setup_dsm FALSE else setup_dsm TRUE 48 8 bit or 16 bit depending on the device Configures the DSM module and selects the source signal and carrier signals Enables the DSM module Disables the DSM module None None None all functions built in None Enables DSM module with the output enabled and selects UART1 as the source signal and VSS as the high carrier signal and OC1 s PWM output as the low carrier signal Disable DSM module Enable DSM module External Memory Functional Overview Some PIC18 devices have the external memory functionality where the external memory can be mapped to external memory devices like Flash EPROM or RAM These functions are available only on devices that support external memory bus General Purpose I O These options let the user configure and use the I O pins on the device These functions will affect the pins that are listed in the device header file Relevant Functions o
230. he 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 Devices with a 16 bit PWM module Nothing set_pwml_period 0x8000 set_pwml_period period setup pwm set pwm _duty set pwm phase clear pwm_interrupt set pwm_offset enable pwm_interrupt disable pwm_interrupt pwm_interrupt active 277 CCS C 10082015 set_pwm1_phase set_pwm2_phase set_pwm3_phase set_pwm4_phase set_pwm5_phase set_pwm6_phase set_pwm1_phase value Syntax Parameters set_pwm2_phase value set_pwm3_phase value set_pwm4_phase value set_pwm5_phase value set_pwm6_phase value value 16 bit constant or variable Returns Function Availability Requires Examples Example Files Also See undefined 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 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 Devices with a 16 bit PWM module Nothing set_pwml_ phase 0 s
231. he compiler None include lt 18F4520 h gt use delay crystal 10MHz clock 40MHz profile functions parameters void main void int adc setup_adc ADC_CLOCK_INTERNAL set_adc_channel 0 for adc read_adc profileout adc delay_ms 250 Configuration Memory On all PIC18 Family of chips the configuration memory is readable and writable This functionality is not available on the PIC16 Family of devices Relevant Functions write_configuration_memory ramaddress count or write_configuration_memory offset ramaddress count read_configuration_memory ramaddress count Relevant Preprocessor None Relevant Include Files None all functions built in Writes count bytes no erase needed Writes count bytes no erase needed starting at byte address offset Read count bytes of configuration memory 45 CCS C 10082015 Relevant getenv parameters None Example Code For PIC18f452 int16 data 0xc32 write_configuration_memory data writes 2 bytes to the configuration memory 2 DAC These options let the user configure and use the digital to analog converter module They are only available on devices with the DAC hardware The options for the functions and directives vary depending on the chip and are listed in the device header file Relevant Functions setup_dac divisor Sets up the DAC e g Reference voltages dac_write value Writes the 8 bit value to the DAC module
232. he 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 undefined 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 All devices that have pull down hardware Pin constants are defined in the devices h file set_pulldown true PIN BO Sets pin BO s pull down state to true set _pullup false Sets all pin s pull down state to false None None set_Pullup state pin 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 Returns Function Availability Requires Examples Example Files Also See Built in Functions 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 State is either true or false undefined 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
233. his directive must appear exactly the same in each compilation unit use rtos timer 0 minor cycle 20ms TASK USE SPI options Options are separated by commas and may be MASTER Set the device as the master default SLAVE Set the device as the slave BAUD n Target bits per second default is as fast as possible CLOCK_HIGH n High time of clock in us not needed if BAUD is used default 0 CLOCK_LOW n Low time of clock in us not needed if BAUD is used default 0 Dl pin Optional pin for incoming data DO pin Optional pin for outgoing data CLK pin Clock pin MODE n The mode to put the SPI bus ENABLE pin Optional pin to be active during data transfer LOAD pin Optional pin to be pulsed active after data is transferred Purpose Examples Example Files Also See DIAGNOSTIC pin SAMPLE_RISE SAMPLE_FALL BITS n SAMPLE_COUNT n LOAD_ACTIVE n ENABLE_ACTIVE n IDLE n ENABLE_DELAY n DATA_HOLD n LSB_FIRST MSB_FIRST STREAM id SPI SPI2 FORCE_HW NOINIT PreProcessor Optional pin to the set high when data is sampled Sample on rising edge Sample on falling edge default Max number of bits in a transfer default 32 Number of samples to take uses majority vote default 1 Active state for LOAD pin 0 1 Active state for ENABLE pin 0 1 default 0 Inactive state for CLK pin 0 1 default 0 Time in us to delay after ENABLE is activated default 0 Time between dat
234. his 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 undefined Initializes and configures the motor control Pulse Width Modulation PWM module All devices equipped with motor control or power PWM module None setup power pwm PWM CLOCK DIV 4 PWM FREE RUN PWM DEAD CLOCK DIV 4 1 10000 1000 0 1 0 None set power pwm override setup power pwm pins set power pwmX_duty Built in Functions setup _power_pwm_pins Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_power_pwm_pins module0 module1 module2 module3 For each module two pins specify PWM_PINS_DISABLED PWM_ODD_ON PWM_BOTH_ON PWM_COMPLEMENTARY undefined Configures the pins of the Pulse Width Modulation PWM device All devices equipped with a power control PWM None 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 DISAB
235. ia a A E 167 disable_pwm1_interrupt disable _pwm2_interrupt disable_pwm3_interrupt disable_pwm4_interrupt disable_pwm5_interrupt disable_pwm6_interrupt ccceeceeeeeeeeeeeeeeeeeeeeeeees 168 Giv ildIV AN 169 enable interrupts cier sa ias e See eee 169 enable_pwm1_interrupt enable_pwm2_interrupt enable_pwm3_interrupt enable_pwm4_interrupt enable_pwm5_interrupt enable_pwm6_interrupt oooooooccconnciccncnococinoconincaanaccnanonans 170 ACER O OS 171 erase PODIAMOS 171 Plinio ata aaa 172 A Te 173 O OE 173 getc geten lt geteMar TQete sess s35 sake eid cca Ses iat eee eal etch E id nia rad nados 174 TlOOr Ashik Ea eis Seeded Peon E 175 TIMIOG vedeecdentvs ddtvtea ecg tl dateend vbr dete masta E Bianca Seeievevead Dh Sateen ie 175 MOO O EE ET E EA E A E eahleseceanutns cove lage veyedth Manage E Magadan ntees 176 O ATEA E A A A A E T E AE T 176 get capture ici ii a er E E E e eels 177 get Capture event ici a a eee ee 177 get Caplute UTS teas iO eed E Ae ee te eae E E 178 Get Capture lidia tdt dede oe ah eters eboney ee eA elas tei eee 178 get hspwmCapture O aA aeaa EE Eerie ai 179 get neo accumulator iii Snel ee teehee Bese e a ae oleo ee EL eee at 180 GeL2NCOs INc Value sheciees E cca ent tea ded end in dr dan 180 GetrtickS i EEE NN 181 O OS 181 CCS C 10082015 vi get IMAP unta had abhi hatin ide MU Lee ee ee a ERA 182 germinal illa a a a fe
236. if MAXSIZE lt 100 undef MAXSIZE define MAXSIZE 100 tendif Example None Files Also See DEFINE _unicode Syntax __unicode constant string Elements Unicode format string Purpose This macro will convert a standard ASCII string to a Unicode format string by inserting a 1000 after each character and removing the normal C string terminator For example _unicode ABCD 113 CCS C 10082015 Examples Example Files will return A OOB OOOC O00D 8 bytes total with the terminator Since the normal C terminator is not used for these strings you need to do one of the following for variable length strings string _unicode KEYWORD 0001000 OR string _unicode KEYWORD string_size sizeof _unicode KEYWORD define USB_DESC_STRING TYPE 3 define USB STRING x sizeof _unicode x 2 USB DESC STRING TYPE unicode x define USB ENGLISH STRING 4 USB DESC STRING TYPE 0x09 0x04 Microsoft Defined for US English char const USB STRING DESC USB ENGLISH STRING USB STRING CCS USB_STRING CCS HID DEMO e usb_desc_hid h use capture Syntax Elements 114 USE CAPTURE options ICx CCPx Which CCP Input Capture module to us INPUT PIN_xx Specifies which pin to use Useful for device with remappable pins this will cause compiler to automatically assign pin to peripheral TIMER x Specifies the timer to use with capture unit If not specifi
237. ilability Requires setup_hspwm_blanking unit settings delay 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 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 Not available on all devices see the device datasheet for availability undefined Sets up the High Speed PWM Trigger event Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None 297 CCS C 10082015 Examples Example Files Also See setup_hspwm trigger 1 10 1 0x2000 None 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_chop clock Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 298 set
238. ility Requires Examples Example Files Also See rand Syntax Parameters Returns Function Availability Requires Examples Built in Functions None Performs the shell metzner sort not the quick sort algorithm The contents of the array are sorted into ascending order according to a comparison function pointed to by compare All devices INCLUDE lt stdlib h gt int nums 5 2 3 1 5 4 int compar void argl void arg2 void main asort nums 5 sizeof int compar int compar void argl void arg2 if int argl lt int arg2 return 1 else if int argl int arg2 return 0 else return 1 ex_qsort c bsearch re rand None A pseudo random integer The rand function returns a sequence of pseudo random integers in the range of 0 to RAND_MAX All devices INCLUDE lt STDLIB H gt int Iz I rand 239 CCS C 10082015 Example Files Also See None srand rcv_buffer_bytes Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value rcv_buffer_bytes stream stream optional parameter specifying the stream defined in USE RS232 Number of bytes in receive buffer that still need to be retrieved Function to determine the number of bytes in receive buffer that still need to be retrieved All devices USE RS232 USE_RS232 UART1 BAUD 960
239. imerB set_timerB TimerB Overview 317 CCS C 10082015 setup_timer_0 Syntax Parameters Returns Function Warning Availability Requires Examples Example Files Also See setup_timer_0 mode mode may be one or two of the constants defined in the devices h file RTCC_INTERNAL RTCC_EXT_L_TO Hor RTCC_EXT_H TO L RTCC_DIV_2 RTCC_DIV_4 RTCC_DIV_8 RTCC_DIV_16 RTCC_DIV_32 RTCC_DIV_64 RTCC_DIV_128 RTCC_DIV_256 PIC18XXX only RTCC_OFF RTCC_8_ BIT One constant may be used from each group or ed together with the operator undefined Sets up the timer 0 aka RTCC On older PIC16 devices set up of the prescaler may undo the WDT prescaler All devices Constants are defined in the devices h file ssuto calmaie 0 RMCE IDI AMOO an 1 MO 1 e get timer0 set timer0 setup counters setup_uart Syntax Parameters 318 setup_uart baud stream setup_uart baua setup_uart baud stream clock 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_AU
240. imer_2 T2_DIV_BY_4 0xc0 2 sets the prescale as 4 period as OxcO and postscales as 2 At 20Mhz timer2 will increment every 8us in this setup overflows every 154 4us and interrupt every 308 2us set_timer2 0 Ithis sets timer2 register to 0 time get_timer2 this will read the timer1 register value Timer3 Timer3 is very similar to timer1 So please refer to the Timer1 section for more details Timer4 Timer4 is very similar to Timer2 So please refer to the Timer2 section for more details Timer5 These options lets the user configure and use timer5 The clock counter is 16 bit and is available only on 18Fxx31 devices lt counts up and also provides interrupt on overflow The options available differ and are listed in the device header file Relevant Functions setup_timer_5 mode Disables or sets the source and prescale for imer5 set_timer5 value Initializes the timer5 clock counter value get_timer5 Returns the value of the timer51 clock counter 65 CCS C 10082015 Relevant Preprocessor None Relevant Interrupts INT_TIMER5 Relevant Include Files Relevant getenv parameters TIMER5 Example Code For PIC18F4431 setup_timer_5 T5_DISABLED or setup_timer_5 T5_INTERNAL T5_DI V_BY_1 set_timer5 0 time get_timer5 TimerA Interrupt fires when timer5 overflows None all functions built in Returns 1 if the device has timer5 disables timer5 sets the internal clock as sou
241. imum negative integer such that 10 raised to that power is in the range representable finite floating point numbers FLT_MAX Maximum representable finite floating point number FLT_EPSILON The difference between 1 and the least value greater than 1 that is representable in the given floating point type FLT_MIN Minimum normalized positive floating point number DBL_MANT_DIG Number of base digits in the floating point significant DBL_DIG Number of decimal digits q such that any floating point number with q decimal digits can be rounded into a floating point number with p radix b digits and back again without change to the q decimal digits DBL_MIN_EXP Minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized floating point number DBL_MIN_10_EXP Minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers DBL_MAX_EXP Maximum negative integer such that FLT_RADIX raised to that power minus 1 is a representable finite floating point number DBL_MAX_10_EXP Maximum negative integer such that 10 raised to that power is in the range of representable finite floating point numbers DBL_MAX Maximum representable finite floating point number DBL_EPSILON The difference between 1 and the least value greater than 1 that is representable in the given floating point type DBL_MIN Minimum normalized positive floating point number LDBL_MANT_DIG Number of base di
242. 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 22 22 22 27 a 22 lt 221 gt 22 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 12 Program Syntax main c include lt device header file gt include lt x c gt include lt y c gt include lt z c gt X C include lt x h gt y c include lt y h gt z c include lt z h gt 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 Multipl
243. in functions such as set_pwm_duty_percent set_pwm_frequency set_pwm_period pwm_on and pwm_off Examples None Also See use rs232 Syntax USE RS232 options Elements Options are separated by commas and may be STREAM id Associates a stream identifier with this RS232 port The 120 identifier may then be used in functions like fputc BAUD x XMIT pin RCV pin FORCE_SW BRGH10K ENABLE pin DEBUGGER RESTART_WDT INVERT PARITY X BITS X FLOAT_HIGH ERRORS SAMPLE_EARLY RETURN pin MULTI_MASTER LONG_DATA DISABLE_INTS STOP X PreProcessor Set baud rate to x Set transmit pin Set receive pin Will generate software serial I O routines even when the UART pins are specified Allow bad baud rates on chips that have baud rate problems The specified pin will be high during transmit This may be used to enable 485 transmit Indicates this stream is used to send receive data through a CCS ICD unit The default pin used is B3 use XMIT and RCV to change the pin used Both should be the same pin Will cause GETC to clear the WDT as it waits for a character Invert the polarity of the serial pins normally not needed when level converter such as the MAX232 May not be used with the internal UART Where xis N E or O Where x is 5 9 5 7 may not be used with the SCI The line is not driven high This is used for open collector outputs Bit 6 in RS232_ERRORS is set if
244. in state All devices Pin constants are defined in the devices h file set_pullup true PIN BO Sets pin BO s pull up state to true set_pullup false Sets all pin s pull up state to false None None set_pwm1_duty set_pwm2_duty set_pwm3_duty set_pwm4_duty set_pwm5_duty Syntax Parameters Returns Function set_pwm1_duty value set_pwm2_duty value set_pwm3_duty value set_pwm4_duty value set_pwm5_duty value value may be an 8 or 16 bit constant or variable undefined 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 275 CCS C 10082015 Availability Requires Examples Example Files Also See duty cycle value 4 PR2 1 f 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 This function is only available on devices with CCP PWM hardware None 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 long duty duty 408 408 4 200 1 0 5 50 set_pwml_ duty duty ex_pwm c setup _ccpX set_ccpX_compare_time set_timer_period_ccpX set_
245. ing point number into a normalized fraction and an integral power of 2 It stores the integer in the signed int object exp The result is in the interval 1 2 to1 or zero such that value is result times 2 raised to power exp If value is zero then both parts are zero All devices INCLUDE lt math h gt Examples Example Files Also See Built in Functions float result signed int exp result frexp 5 amp exp result is 5 and exp is 0 None Idexp exp log log10 modf get_capture Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value get_capture x x defines which ccp module to read from A 16 bit timer value This function obtains the last capture time from the indicated CCP module Only available on devices with Input Capture modules None ex ccpmp c setup ccpx get_capture_event Syntax Parameters Returns Function Availability result get_capture_event stream stream optional parameter specifying the stream defined in USE CAPTURE TRUE if a capture event occurred FALSE otherwise To determine if a capture event occurred All devices 177 CCS C 10082015 Requires Examples Example Files Also See USE CAPTURE USE CAPTURE INPUT PIN_C2 CAPTURE_RISING TIMER 1 FASTEST if get_capture_event result get_capture_time None use capture get
246. is PWM unit default to 0 if not specified undefined Sets up the specified High Soeed PWM unit Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices Constants are defined in the device s h file setup_hspwm_unit 1 HSPWM ENABLE SHPWM COMPLEMENTARY 100 100 None Also See 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 setup_hspwm_secondary Syntax setup_hspwm mode value setup_hspwm_secondary mode value lif 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 undefined 300 Function Availability Requires Examples Example Files Also See Built in Functions To enable the High Speed PWM module and set up the Primary and Secondary Time base of the module Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices Constants are defined in the devi
247. is function waits for a character to come in over the RS232 RCV pin and returns the character If you do not want to hang forever waiting for an incoming character use kbhit to test for a character available If a built in USART is used the hardware can buffer 3 characters otherwise GETC must be active while the character is being received by the PIC If fgetc is used then the specified stream is used where getc defaults to STDIN the last USE RS232 Availability All devices Requires USE RS232 Examples printf Continue Y N do answer getch while answer Y amp amp answer N use rs232 baud 9600 xmit pin_c6 rcev pin_c7 stream HOSTPC use rs232 baud 1200 xmit pin bl rcv pin_b0 stream GPS use rs232 baud 9600 xmit pin_b3 stream DEBUG while TRUE c fgetc GPS fputc c HOSTPC if c 13 fprintf DEBUG Got a CR r n Example Files ex _stwt c Also See putc kbhit printf USE RS232 input c RS232 I O Overview 174 Built in Functions floor Syntax result floor value Parameters value is a float Returns result is a float Function Computes the greatest integer value not greater than the argument Floor 12 67 is 12 00 Availability All devices Requires INCLUDE lt math h gt Examples Find the fractional part of a value frac value floor value Example Files None Also See ceil fmod Syntax result fmod va 1 val
248. isters are double buffered so the new value won t be applied until the accumulator rolls over On devices with a NCO module set_nco inc value inc value sets the new increment value None setup _nco get nco accumulator get nco inc value set_open_drain Syntax Parameters Returns Function Availability Examples Example Files 272 set_open_drain_a value set_open_drain_b value set_open_drain_c value set_open_drain_d value 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 value is a bitmap corresponding to the pins of the port Setting a bit causes the corresponding pin to act as an open drain output Nothing Enables Disables open drain output capability on port pins Not all ports or port pins have open drain capability refer to devices datasheet for port and pin availability On device that have open drain capability set_open_drain_b 0x0001 enables open drain output on PIN_BO disable on all other port B pins None Built in Functions set_power_pwm_override Syntax set_power_pwm_override pwm override value Parameters pwm is a constant between 0 and 7 Returns Function Availability Requires Examples Example Files Also See Override is true or false Value is 0 or 1 undefined pwm selects which module will be affected Override
249. its active state it will clock out the next data byte All devices USE RS232 USE_RS232 UART1 BAUD 9600 TRANSMIT_BUFFER 50 NOTXISR printf Testing Transmit Buffer while TRUE putc_send None USE _RS232 RCV BUFFER FULL TX BUFFER FULL TX BUFFER BYTES GET PUTC RINTF SETUP _UART PUTC SEND pwm_off stream stream optional parameter specifying the stream defined in USE PWM Nothing To turn off the PWM signal All devices USE PWM USE PWM OUTPUT PIN_C2 FREQUENCY 10kHz DUTY 25 while TRUE if kbhit c getc Example Files Also See pwm_on Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions if c F pwm_off None use_ pwm pwm on pwm set duty percent pwm_ set duty pwm_ set frequency pwm_on stream stream optional parameter specifying the stream defined in USE PWM Nothing To turn on the PWM signal All devices USE PWM USE PWM OUTPUT PIN C2 FREQUENCY 10kHz DUTY 25 while TRUE if kbhit c getc if c 0 pwm_on None ttuse pwm pwm off pwm set duty percent pwm set duty pwm set frequency pwm_set_duty Syntax Parameters Returns Function Availability Requires pwm_set_duty stream duty stream optional parameter specifying the stream defined in USE PWM duty
250. ives may be used with all parts See the devices h file for all valid interrupts for the part or in PCW use the pull down VIEW Valid Ints The compiler will generate code to jump to the function when the interrupt is detected It will generate code to save and restore the machine state and will clear the interrupt flag To prevent the flag from 96 Examples Example Files Also See PreProcessor being cleared add NOCLEAR after the INT_xxxx The application program must call ENABLE_INTERRUPTS INT_xxxx to initially activate the interrupt along with the ENABLE_INTERRUPTS GLOBAL to enable interrupts The keywords HIGH and FAST may be used with the PCH compiler to mark an interrupt as high priority A high priority interrupt can interrupt another interrupt handler An interrupt marked FAST is performed without saving or restoring any registers You should do as little as possible and save any registers that need to be saved on your own Interrupts marked HIGH can be used normally See DEVICE for information on building with high priority interrupts A summary of the different kinds of PIC18 interrupts INT_Xxxxx Normal low priority interrupt Compiler saves restores key registers This interrupt will not interrupt any interrupt in progress INT_xxxx FAST High priority interrupt Compiler DOES NOT save restore key registers This interrupt will interrupt any normal interrupt in progress Only one is allowed in a program INT_
251. l Overview the device hat a 10bit ADC module value will range between 0 3FF If DEVICE ADC 8 had been used instead the result will yield O FF If DEVICE ADC 16 had been used instead the result will yield 0 FFCO Analog Comparator These functions set up the analog comparator module Only available in some devices Relevant Functions setup_comparator mode Enables and sets the analog comparator module The options vary depending on the chip Refer to the header file for details Relevant Preprocessor None Relevant Interrupts INT_COMP Interrupt fires on comparator detect Some chips have more than one comparator unit and thus more interrupts Relevant Include Files None all functions built in Relevant getenv Parameters Returns 1 if the device has a COMP comparator Example Code setup_comparator A4_A5 NC_NC if C10UT output_low PIN_DO else output_high PIN_D1 CAN Bus These functions allow easy access to the Controller Area Network CAN features included with the MCP2515 CAN interface chip and the PIC18 MCU These functions will only work with the MCP2515 CAN interface chip and PIC microcontroller units containing either a CAN or an ECAN module Some functions are only available for the ECAN module and are specified by the work ECAN at the end of the description The listed interrupts are no available to the MCP2515 interface chip Relevant Functions can_init void Initializes the CA
252. l does not change This function is only available on devices with A D hardware Nothing set_adc channel 2 delay us 10 value read _adc ex_admm c read_adc setup adc setup adc ports ADC Overview set_analog_pins Syntax Parameters Returns Function 262 set_analog_pins pin pin pin 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 undefined 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 Requires Examples Example Files Also See scanf Syntax Parameters Returns Function Built in Functions Refer to the setup adc ports page for documentation on how to use On all devices with an Analog to Digital Converter Nothing set_analog pins PIN A0 PIN Al PIN El PIN BO PIN B5 setup adc reference set adc channel read_adc setup adc setup adc ports ADC Overview scanf cstring scanf cstring values fscanf stream cstring values cstring is a constant string
253. les Example Files Also See sprintf Syntax Parameters Returns Function Availability Requires Examples 332 value spi_xfer_in value spi_xfer_in bits value spi_xfer_in stream bits stream is the SPI stream to use as defined in the STREAM name option in USE SPI bits is how many bits of data to be received The data read in from the SPI Reads data from the SPI without writing data into the transmit buffer first This function is only available on devices with SPI hardware USE SPI and the option SLAVE is used in USE SPI to setup PIC as a SPI slave device data_in spi_xfer_in ex_spi_slave c USE SPI spi_xfer spi_prewrite spi_init spi_speed sprintf string cstring values bytes sprintf string cstring values string is an array of characters cstring is a constant string or an array of characters null terminated Values are a list of variables separated by commas Note that format specifies do not work in ram band strings Bytes is the number of bytes written to string This function operates like printf except that the output is placed into the specified string The output string will be terminated with a null No checking is done to ensure the string is large enough for the data See printf for details on formatting All devices Nothing char mystring 20 long mylong mylong 1234 sprintf mystring lt lu gt mylong
254. lipsis Usually you will use this variable as a method for determining how many variables have been pushed onto the ellipsis Here is a function that calculates and returns the sum of all variables int Sum int count a pointer to the argument list va_list al int x sum 0 start the argument list count is the first variable before the ellipsis va_start al count while count get an int from the list x var_arg al int sum xX stop using the list va_end al return sum Some examples of using this new function x Sum 5 10 20 30 40 50 y Sum 3 a b c 37 FUNCTIONAL OVERVIEW 12C I2C is a popular two wire communication protocol developed by Phillips Many PIC microcontrollers support hardware based I2C CCS offers support for the hardware based I2C and a software based master I2C device For more information on the hardware based I2C module please consult the datasheet for you target device not all PICs support I2C Relevant Functions i2c_start i2c_write data i2c_read i2c_stop i2c_poll Relevant Preprocessor USE 12C Relevant Interrupts INT_SSP INT_BUSCOL INT_I2C INT_BUSCOL2 INT_SSP2 Relevant Include Files None all functions built in Relevant getenv Parameters 12C_ SLAVE 12C_MASTER Example Code define Device_SDA PIN_C3 define Device_SLC PIN_C4 use i2c master sda Device_SDA scl Device_SCL BYTE data i
255. ll deactivate Only 14 and 16 bit devices PCM and PCH Note use SETUP_COUNTERS on PCB parts Nothing port_a_pullups FALSE ex _Icdkb c kbd c input input x output float pow pwr Syntax Parameters Returns Function Availability 222 f pow x y f pwr x y x and y are of type float A float Calculates X to the Y power Note on error handling If errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Range error occurs in the following case e pow when the argument X is negative All Devices Requires Examples Example Files Also See printf Syntax Parameters Returns Function Built in Functions INCLUDE lt math h gt area pow size 3 0 None None fprintf printf string or printf cstring values or printf fname cstring values fprintf stream cstring values String is a constant string or an array of characters null terminated Values is a list of variables separated by commas fname is a function name to be used for outputting default is putc is none is specified Stream is a stream identifier a constant byte Note that format specifies do not work in ram band strings undefined Outputs a string of characters to either the standard RS 232 pins first
256. ll devices USE 12C USE Il2C MASTER I2C1 FAST NOINIT i2c_init TRUE initialize and enable 12C peripheral to baud rate specified in HUSE 12C i2c_init 500000 initialize and enable 12C peripheral to a baud rate of 500 KBPS None 12 POLL i2c_speed 12C SlaveAddr l2C ISR STATE _ 12C_WRITE 12 READ USE 12C l2C 2c_isr_state Syntax Parameters Returns Function Availability Requires Examples state i2c_isr_state state i2c_isr_state stream None state is an 8 bit int 0 Address match received with R W bit clear perform 2c_read to read the 12C 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 12C address and use i2c_write to pre load the transmit buffer for the next transaction next 12C read performed by master will read this byte 0x81 OxFF Transmission completed and acknowledged respond with i2c_write to pre load the transmit buffer for the next transation the next 12C read performed by master will read this byte Returns the state of I2C communications in 12C slave mode after an SSP interrupt The return value increments with each byte received or sent If 0x00 or 0x80 is returned an 2C_read needs to be performed to read the 12C address that was sent it will match the address configured by USE 12C so this value can be
257. ll then measure the time it takes until it sees the same profileout string where the START is replaced with STOP This measurement is then displayed in the Statistics screen of the code profile tool using string as the name without START or STOP Any device use profile used somewhere in the project source code send a simple string profileout This is a text string send a variable with a string identifier profileout RemoteSensor adc just send a variable profileout adc time how long a block of code takes to execute this will be displayed in the Statistics of the Code Profile tool profileout Start my algorithm code goes here profileout Stop my algorithm ex_profile c use profile profile Code Profile overview psmc_blanking Syntax Parameters psmc_blanking unit rising_edge rise_time falling _edge fall_time unit is the PSMC unit number 1 4 rising_edge are the events that are ignored after the signal activates rise_time is the time in ticks 0 255 that the above events are ignored falling_edge are the events that are ignored after the signal goes inactive fall_time is the time in ticks 0 255 that the above events are ignored Events PSMC_EVENT_C10UT 225 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See PSMC_EVENT_C20UT PSMC_EVENT_C30UT
258. ll wait for module to finish calculation before reading the specified register Availability All devices with a PID module Requires Constants are defined in the device s h file Examples pid_read PID ADDR _Z1 amp value 21 Example Files None Also See setup pid pid write pid get result pid busy pid_write Syntax pid_write register amp input Parameters register constant specifying which PID registers to write The registers that can be written are defined in the device s header file as PID ADDR_ACCUMULATOR PID_ADDR_OUTPUT PID_ADDR_Z1 PID_ADDR_Z2 PID_ADDR_Z3 PID_ADDR K1 PID_ADDR_K2 PID_ADDR_K3 input a 16 bit variable 32 bit variable or structure that contains the data to be written The size depends on the registers that are being written Either pass the address of the variable or structure as the parameter or a pointer to the variable or structure as the parameter Returns Nothing Function To write a new value for the Accumulator Output Z1 Z2 Set Point K1 K2 or K3 PID registers If the PID is busy with a calculation the function will wait for module to finish the calculation before writing the specified register Availability All devices with a PID module 220 Requires Examples Example Files Also See Built in Functions Constants are defined in the device s h file pid write PID_ADDR_Z1 value _z1 None setup pid pid read pid get result pid bus
259. low The options available differ and are listed in the device header file Relevant Functions setup_timer_0 mode set_timer0 value or set_rtcc value value get_timer0 Relevant Preprocessor Relevant Interrupts INT_TIMERO or INT_RTCC Relevant Include Files None all functions built in Relevant getenv parameters TIMERO Example Code For PIC18F452 setup_timer_0 RTCC_INTERNAL RTCC_DIV_2 RTCC_8 BIT set_timer0 0 time get_timer0 Sets the source prescale etc for timerO Initializes the timerO clock counter Value may be a 8 bit or 16 bit depending on the device Returns the value of the timer0 clock counter None Interrupt fires when timer0 overflows Returns 1 if the device has timerO sets the internal clock as source land prescale 2 At 20Mhz timerO will increment every 0 4us in this setup and overflows every 102 4us Ithis sets timerO register to 0 this will read the timerO register Ivalue 63 CCS C 10082015 Timer These options lets the user configure and use timer1 The clock counter is 16 bit on pic16s and pic18s It counts up and also provides interrupt on overflow The options available differ and are listed in the device header file Relevant Functions setup_timer_1 mode set_timer1 value value get_timer1 Relevant Preprocessor None Relevant Interrupts INT_TIMER1 Relevant Include Files None all functions built in Relevant getenv parameters
260. lowing line of input 2 line 7 hello c line number in the source file hello c and it sets the line 7 as current line and hello c as current file 99 CCS C 10082015 Example None Files Also See None locate Syntax LOCATE id x Elements id is a C variable xis a constant memory address Purpose LOCATE allocates a C variable to a specified address If the C variable was not previously defined it will be defined as an INT8 A special form of this directive may be used to locate all A functions local variables starting at a fixed location Use LOCATE Auto address This directive will place the indirected C variable at the requested address Examples This will locate the float variable at 50 53 and C will not use this memory for other variables automatically located Elost x locate x 0x 50 Example ex_glint c Files Also See byte bit reserve word Named Registers Type Specifiers Type Qualifiers Enumerated Types Structures amp Unions Typedef module Syntax MODULE Elements None Purpose All global symbols created from the MODULE to the end of the file will only be visible within that same block of code and files INCLUDE within that block This may be used to limit the scope of global variables and functions within include files This directive also applies to pre processor defines Note The extern and static data qualifiers can also be used to denote scope o
261. lue adc_done Parameters None channel is an optional parameter for specifying the channel to check if the conversion is done If not specified will use channel specified in the last call to set_adc_channel 138 Returns Function Availability Requires Examples Example Files Also See assert Syntax Parameters Returns Function Availability Requires Examples Built in Functions read_adc or adc_done Only available for dsPIC83EPxxGSxxx family A short int TRUE if the A D converter is done with conversion FALSE if it is still busy Can be polled to determine if the A D has valid data Only available on devices with built in analog to digital converters None int16 value setup _adc ports sANO sAN1 VSS VDD setup adc ADC CLOCK DIV 4 ADC TAD MUL 8 set_adc channel 0 read adc ADC START ONLY intl done ade done while done done adc_done value read_adc ADC_READ ONLY printf A C value LX n r value None setup adc set adc channel setup adc ports read _adc ADC Overview assert condition condition is any relational expression Nothing This function tests the condition and if FALSE will generate an error message on STDERR by default the first USE RS232 in the program The error message will include the file and line of the assert No code is generated for the assert if you define NODEBUG In this way you m
262. lues 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 void Writes the date and time to the alarm in the RTCC module as specified in the structure date time Devices that have the RTCC module Nothing rtc alarm write amp datetime None rtc_read rtc_alarm_read rtc_ alarm write setup rtc_alarm rtc_write setup_rtc 253 CCS C 10082015 rtc_read Syntax Parameters Returns Function Availability Requires Examples Example Files Also See rtc_write Syntax Parameters Returns Function Availability Requires Examples Example Files 254 rtc_read amp datetime 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 void Reads the current value of Time and Date from the RTCC module and stores the structure date time Devices that have the RTCC module Nothing rtc_read amp datetime eXxaniccic rtc_read rtc alarm read rtc_ alarm write setup rtc_alarm rtc_write setup rtc rtc_write amp datetime 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 void Writes the date and time
263. me a task will use in one execution of the task The time specified in max must be equal to or less than the time specified in the minor_cycle option of the USE RTOS directive before the project will compile successfully The compiler does not have a way to enforce this limit on processor time so a programmer must be careful with how much processor time a task uses for execution This option does not need to be specified The queue option is used to specify the number of bytes to be reserved for the task to receive messages from other tasks or functions The default queue value is 0 ftask rate 1s max 20ms queue 5 USE RTOS __time__ Syntax Elements TME None 111 CCS C 10082015 Purpose Examples Example Files Also See type Syntax Elements Purpose Examples 112 This pre processor identifier is replaced at compile time with the time of the compile in the form hh mm ss printf Software was compiled on opealueie MAME None None TYPE standard type size TYPE default area TYPE unsigned TYPE signed standard type is one of the C keywords short int long or default size is 1 8 16 or 32 area is a memory region defined before the TYPE using the addressmod directive By default the compiler treats SHORT as one bit INT as 8 bits and LONG as 16 bits The traditional C convention is to have INT defined as the most efficient size for the target processor This is wh
264. me typical options include DAC_OUTPUT Returns undefined Function Configures the DAC including reference voltage Availability Only the devices with built in digital to analog converter Requires Constants are defined in the devices h file Examples setup_dac DAC VDD DAC_OUTPUT dac write value Example Files None Also See dac write DAC Overview See header file for device selected 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 294 Returns Function Availability Requires Examples Example Files Also See Built in Functions ADC _DEDICATED_CLOCK_DIV_2 ADC _DEDICATED_CLOCK_DIV_6 ADC_DEDICATED_TAD_MUL_2 ADC _DEDICATED_TAD_MUL_3 Undefined Configures one of the dedicated ADC core s clock speed and sample time Function should be called after the setup_adc function On the dsPIC33EPxxGSxxx family of devices Nothing setup_dedicated_adc 0 ADC_DEDICATED_CLOCK_DIV_2 ADC_DEDICATED_TAD_MUL_1025 None setup adc setup adc ports set adc channel read adc adc done set dedicated adc channel ADC Overview setup_external_memory Syntax Parameters Returns Function Availability Requires Examples Example Files Also See SETUP_EXTERNA
265. milliseconds or s seconds If the desired tick time can t be achieved it will set the time to closest achievable time and will generate a warning specifying the exact tick time The default value is 1us BITS x Sets the variable size used by the get_ticks and set_ticks functions for returning and setting the tick time x can be 8 for 8 bits 16 for 16 bits or 32 for 32bits The default is 32 for 32 bits ISR Uses the timer s interrupt to increment the upper bits of the tick timer This mode requires the the global interrupt be enabled in the main program NOISR The get_ticks function increments the upper bits of the tick timer This requires that the get_ticks function be called more often then the timer s overflow rate NOISR is the default mode of operation STREAM id Associates a stream identifier with the tick timer The identifier may be used in functions like get_ticks DEFINE id Purpose Examples Example Files Also See PreProcessor Creates a define named id which specifies the number of ticks that will occur in one second Default define name if not specified is TICKS _PER_SECOND Define name must start with an ASCII letter A to Z an ASCII letter a to z or an ASCII underscore _ COUNTER or COUNTER x Sets up specified timer as a counter instead of timer x specifies the prescallar to setup counter with default is1 if x is not specified specified The function get_ticks will ret
266. mpting to dereference that pointer would cause an address fault Any attempts to read write b should be done in context of test so the compiler knows it is packed test b 5 aligned y By default the compiler will alocate a variable in the first free memory location The aligned attribute will force the compiler to allocate a location for the specified variable at a location that is modulus of the y parameter For example int8 array 256 _ attribute _ aligned 0x1000 This will tell the compiler to try to place array at either 0x0 0x1000 0x2000 0x3000 0x4000 etc To alter some specifics as to how the compiler operates 77 CCS C 10082015 struct __attribute__ packed Examples int8 a int8 b test int8 array 256 Example Files None asm endasm as ASM or ASM ASIS code ENDASM Syntax Elements code is a list of assembly language instructions Examples int find pa int coun tasm MOV 0x0 MOV WO CLR WO loop XOR B da data coun NZ 0x0 coun coun MOV WO endasm Example Files FFT c Also See None 12 Bit and 14 Bit ADDWF f d CLRF f COMF f d DECFSZ f d INCFSZ f d MOVF f d MOVPLW NOP RRF f d SWAPF f d 78 _ attribute aligned 0x1000 m asis rity int data t 8 WO count ta WO WO EE loop 1 WO0 t E WO ETURN_ Er RI ANDWF f d CLRW DECF f d INCF f d IORWF f d MOVPHW MOVWF f RLF f d SUBWF f d
267. n Availability Requires Examples Example Files Also See pwm_ off Syntax Parameters Returns Function Availability Requires Examples 234 Function used to transmit bytes loaded in transmit buffer over RS232 Depending on the options used in USE RS232 controls if function is available and how it works If using hardware UARTx with NOTXISR option it will check if currently transmitting If not transmitting it will then check for data in transmit buffer If there is data in transmit buffer it will load next byte from transmit buffer into the hardware TX buffer unless using CTS flow control option In that case it will first check to see if CTS line is at its active state before loading next byte from transmit buffer into the hardware TX buffer If using hardware UARTx with TXISR option function only available if using CTS flow control option it will test to see if the TBEx interrupt is enabled If not enabled it will then test for data in transmit buffer to send If there is data to send it will then test the CTS flow control line and if at its active state it will enable the TBEx interrupt When using the TXISR mode the TBEx interrupt takes care off moving data from the transmit buffer into the hardware TX buffer If using software RS232 only useful if using CTS flow control it will check if there is data in transmit buffer to send If there is data it will then check the CTS flow control line and if at
268. nd filters can be setup Devices that have the QE module Nothing setup _qei QEI MODE X2 QEI_ RESET WHEN MAXCOUNT QEI_ FILTER ENABLE _QEA QEI FILTER DIV_2 0x1000 None qei_set_count gei_ get count gei_status setup _rtc Syntax Parameters Returns Function setup_rtc options calibration 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 void Configures the Real Time Clock and Calendar module The module requires an external 313 CCS C 10082015 Availability Requires Examples Example Files Also See 32 768 kHz clock crystal for operation Devices that have the RTCC module Nothing setup _rtc RTC_ENABLE RTC_OUTPUT SECONDS 0x00 Enable RTCC module with seconds clock and no calibration None rtc_read rtc _ alarm read rtc_ alarm write setup rtc_alarm rtc_write setup rtc setup _rtc_alarm Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_rtc_alarm options mask repeat 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
269. ne USE DELAY OPT n All Devices nis the optimization level 1 11 or by using the word compress for PIC18 and Enhanced PIC16 families The optimization level is set with this directive This setting applies to the entire program and may appear anywhere in the file The PCW default is 9 for normal When Compress is specified the optimization is set to an extreme level that causes a very tight rom image the code is optimized for space not speed Debugging with this level my be more difficult opt 5 None None ORG start end or ORG segment or ORG start end or ORG start end auto 0 ORG start end DEFAULT or ORG DEFAULT start is the first ROM location word address to use end is the last ROM location segment is the start ROM location from a previous ORG This directive will fix the following function constant or ROM declaration into a specific ROM area End may be omitted if a segment was previously defined if you only want to add another function to the segment Follow the ORG with a to only reserve the area with nothing inserted by the compiler The RAM for a ORG d function may be reset to low memory so the local variables and scratch Examples Example Files Also See PreProcessor variables are placed in low memory This should only be used if the ORG d function will not return to the caller The RAM used will overlap the RAM of the main program Add a AUTO 0 at the end of the ORG line
270. ng 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
271. ning Unlike in circuit debugging this tool grabs information while the program is running and provides statistics logging and tracing of it s execution This is accomplished by using a simple communication method between the processor and the ICD with minimal side effects to the timing and execution of the program Another benefit of code profile versus in circuit debugging is that a program written with profile support enabled will run correctly even if there is no ICD connected In order to use Code Profiling several functions and pre processor statements need to be included in the project being compiled and profiled Doing this adds the proper code profile run time support on the microcontroller See the help file in the Code Profile tool for more help and usage examples Relevant Functions profileout Send a user specified message or variable to be displayed or logged by the code profile tool Relevant Pre Processor use profile Global configuration of the code profile run time on the microcontroller 44 profile Relevant Interrupts Relevant Include Files Relevant getenv Example Code Functional Overview Dynamically enable disable specific elements of the profiler The profiler can be configured to use a microcontroller s internal timer for more accurate timing of events over the clock on the PC This timer is configured using the profile pre processor command None all the functions are built into t
272. nput capture 1 OC1 output capture 1 INT1 External Interrupt 1 INT2 External Interrupt 2 INT3 External Interrupt 3 TOCK TimerO External Clock T3CK Timer3 External Clock CCP1 Input Capture 1 CCP2 Input Capture 2 T1G Timer1 Gate Input T3G Timer3 Gate Input U2RX EUSART2 Asynchronous Receive Synchronous Receive also named RX2 U2CK EUSART2 Asynchronous Clock Input SDI2 SPI2 Data Input SCK2IN SPI2 Clock Input SS2IN SPI2 Slave Select Input FLTO PWM Fault Input TOCKI TimerO External Clock Input T3CKI Timer3 External Clock Input RX2 EUSART2 Asynchronous Transmit Asynchronous Clock Output also named TX2 NULL NULL C1OUT Comparator 1 Output C20OUT Comparator 2 Output U2TX EUSART2 Asynchronous Transmit Asynchronous Clock Output also named TX2 U2DT EUSART2 Synchronous Transmit also named DT2 SDO2 SPI2 Data Output SCK20UT SPIC2 Clock Output SS20UT SPI2 Slave Select Output ULPOUT Ultra Low Power Wake Up Event P1A ECCP1 Compare or PWM Output Channel A P1B ECCP1 Enhanced PWM Output Channel B P1C ECCP1 Enhanced PWM Output Channel C P1D ECCP1 Enhanced PWM Output Channel D P2A ECCP2 Compare or PWM Output Channel A P2B ECCP2 Enhanced PWM Output Channel B P2C ECCP2 Enhanced PWM Output Channel C P2D ECCP1 Enhanced PWM Output Channel D TX2 EUSART2 Asynchronous Transmit Asynchronous Clock Output also named TX2 DT2 EUSART2 Synchronous Transmit also named U2DT SCK2 SPI2 Clock Output SSDMA SP
273. ns Function Availability Requires Examples Example Files Also See set_compare_time x ocr ocrs xis 1 16 and defines which output compare module to set time for ocris the compare time for the primary compare register ocrs is the optional compare time for the secondary register Used for dual compare mode None 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 Only available on devices with output compare modules Nothing Pin OC1 will be set when timer 2 is equal to 0xF000 setup _timer2 TMR_INTERNAL TIMER DIV BY 8 setup compare time 1 OxF000 setup_compare 1 COMPARE SET ON MATCH COMPARE TIMER2 None get_capture setup_compare Output Compare PWM Overview 267 CCS C 10082015 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_ANO ADC_CHANNEL_AN7 ADC_CHANNEL_PGA1 ADC_CHANNEL_ANOALT ADC_CHANNEL_AN1 O ADC_CHANNEL_AN18 ADC_CHANNEL_PGA2 ADC_CHANNEL_AN1ALT
274. ns ad ede ee ode ld MU ee ee 225 psme deadbannd 12 ie teeter iii tees te lb aera eee eles aa 226 PSIMG CULV sti id icndita e 227 psmetreq adjUs tunas iaa in aa ee ie a Eo eee eles 228 psme modulatiOn miii iria 228 PSMC PINS festes tidad A tte IA a dl iD bae Dc Gaede 230 PSIMNG SMUTAOWM A E 231 AS A 232 psp_output_full psp_input_full psp_Overflow oooooooocccnnnccnncccocccccncccncnnaonocononononnnnnncnnnncnnnnnnnnccnnnnnannnnnncnnn 233 putc_send IDU Si A oo 233 A NT 234 PWI ON PA EAA AETA ETT 235 PWMSStodUly lena ee eii o a a ee eee ee ee eee IE 235 pwmsetaduty percent soc sind a E E ar aa aaa aaa Ear aa ele a ia ee eed A Ea aLa a E 236 PWM Set TREQUCNGCY A EE E T A A eta colds 236 pwm1_interrupt_active pwm2_interrupt_active pwm3_interrupt_active pwm4_interrupt_active pwm5_interrupt_active pwm6_interrupt_active ccccceeeeeeeeeeeeeeeeeeeeeeeeeneeeeeeeees 237 Qei Get Count Tere heehee A A faa OL ed 237 GOl StatuS O aE E a at ee es 238 a O NO 238 o achstescusaterssie sevhancasagaasbenedicneaideasusanddhincasdaanstaactiapiagdeasse 239 rev E casts iis cere ie hie et Ae eis E A bla ee et 240 rev buffers full sra ara N aia aa 240 E O eR a 241 A a E a anes be a a cular ies 242 RA A O O fase stisestapiaadenetee 242 read configuration MEMO Dimas A A Ad Id dit 243 read BEpPro Maicao arar ia tan 244 read extended Talitas tr ria 244 read_program_memory read_external_MemMory cccc
275. nt bytes int de for i 0 i lt bytes i ram addr ram read_eeprom addr void DataEE Write int32 addr int8 ram int bytes ant 1 for i 0 i lt bytes i ram addr write eeprom addr ram addressmod DataEE DataEE read DataEE write 5 0xff would define a region called DataEE between 0x5 and Oxff in the chip data EEprom void main void int DataEE test int x y x 12 test x writes x to the Data EEPROM y test Reads the Data EEPROM Note If the area is defined in RAM then read and write functions are not required the variables assigned in the memory region defined by the addressmod can be treated as a regular variable in all valid expressions Any structure or data type can be used with an addressmod Pointers can also be made to an addressmod data type The type directive can be used to make this memory region as default for variable allocations The syntax is type default addressmodname all the variable declarations that follow will use this memory region type default goes back to the default mode For example Type default emi emi is the addressmod name defined char buffer 8192 include lt memoryhog h gt type default Using Program Memory for Data CCS C Compiler provides a few different ways to use program memory for data The different ways are discussed below Constant Data The const qualifier will place the variables into program memory
276. ntax psmc_pins unit pins_used pins_active_low Parameters unit is the PSMC unit number 1 4 used_pins is the any combination of the following or ed together PSMC_A PSMC_B PSMC_C PSMC_D PSMC_E PSMC_F A PSMC_ON_NEXT_PERIOD If the last constant is used all the changes made take effect on the next period as opposed to immediate pins_active_low is an optional parameter When used it lists the same pins from above as the pins that should have an inverted polarity Returns Undefined Function This function identified the pins allocated to the PSMC unit the polarity of those pins and it enables the PSMC unit The tri state register for each pin is set to the output state Availability All devices equipped with PSMC module Requires Examples Simple PWM 10khz out on pin CO assuming a 20mhz crystal Duty is initially set to 25 setup _psmc 1 PSMC SINGLE PSMC_EVENT_TIME PSMC_SOURCE_FOSC us 100 PSMC_EVENT TIME 0 PSMC_EVENT TIME us 25 psmc_pins 1 PSMC_A Example Files None Also See setup psmc psmc_deadband psmc_sync psmc_blanking psmc_modulation psmc_shutdown psmc_duty psmc_ freq adjust 230 Built in Functions psmc_shutdown Syntax Parameters Returns Function Availability psmc_shutdown unit options source pins_high psmc_shutdown unit command unit is the PSMC unit number 1 4 Options may be one of the following P
277. ntrol In both FLOW_CONTROL_MODE and SIMPLEX MODE this pin is sampled to see if it clear to send 122 Purpose Examples Example Files Also See PreProcessor data If pin is at active level and there is data to send it will send next data byte CTS_LEVEL x Specifies the active level of the CTS pin HIGH is active high and LOW is active low Default to LOW if not specified FLOW_CONTROL_MODE Specifies how the RTS pin is used For FLOW_CONTROL_MODE the RTS pin is driven to the active level when ready to receive data Defaults to FLOW_CONTROL_MODE when neither FLOW_CONTROL_MODE or SIMPLEX_MODE is specified If RTS pin isn t specified then this option is not used SIMPLEX_MODE Specifies how the RTS pin is used For SIMPLEX_MODE the RTS pin is driven to the active level when it has data to send Defaults to FLOW_CONTROL_MODE when neither FLOW_CONTROL_MODE or SIMPLEX_MODE is specified If RTS pin isn t specified then this option is not used This directive tells the compiler the baud rate and pins used for serial I O This directive takes effect until another RS232 directive is encountered The USE DELAY directive must appear before this directive can be used This directive enables use of built in functions such as GETC PUTC and PRINTF The functions created with this directive are exported when using multiple compilation units To access the correct function use the stream identifier When using parts with built in SCI and th
278. o See memepy Syntax 208 int32 x int y long z x make32 1 2 3 4 x is 0x01020304 y 0x12 z 0x4321 x make32 y z x is 0x00124321 x make32 y y z x is 0x12124321 ex_freqc c make8 make16 ptr malloc size size is an integer representing the number of byes to be allocated A pointer to the allocated memory if any Returns null otherwise The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate All devices INCLUDE lt stdlibm h gt int iptr iptr malloc 10 iptr will point to a block of memory of 10 bytes None realloc free calloc memmove memcpy destination source n memmove destination source n Parameters Returns Function Availability Requires Examples Example Files Also See memset Syntax Parameters Returns Function Built in Functions destination is a pointer to the destination memory source is a pointer to the source memory nis the number of bytes to transfer undefined Copies n bytes from source to destination in RAM Be aware that array names are pointers where other variable names and structure names are not and therefore need a amp before them Memmove performs a safe copy overlapping objects doesn t cause a problem Copying takes place as if the n characters from the source are first copied into a temporary array of n
279. o See FWARNING export options Syntax EXPORT options Elements FILE filname The filename which will be generated upon compile If not given the filname will be the name of the file you are compiling with a o or hex extension depending on output format ONL Y symbol symbol symbol Only the listed symbols will be visible to modules that import or link this relocatable object file If neither ONLY or EXCEPT is used all symbols are exported EXCEPT symbol symbol symbol All symbols except the listed symbols will be visible to modules that import or link this relocatable object file If neither ONLY or EXCEPT is used all symbols are exported RELOCATABLE CCS relocatable object file format Must be imported or linked before loading into a PIC This is the default format when the EXPORT is used HEX Intel HEX file format Ready to be loaded into a PIC This is the default format when no EXPORT is used RANGEzstart stop Only addresses in this range are included in the hex file OFFSET address Hex file address starts at this address 0 by default ODD Only odd bytes place in hex file EVEN Only even bytes placed in hex file Purpose This directive will tell the compiler to either generate a relocatable object file or a stand alone HEX binary A relocatable object file must be linked into your application while a stand alone HEX binary can be programmed directly into the PIC The command line c
280. 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 MN ait seo Options Compile View Tools Debug Document User toolbar Cut Unindent La Record FA Neu F gt Fog File Selection Ex i Copy J Load Undo Redo Paste To Fil y Indent E p O seleta P lo File Selection FormatSource Playback bed Save History Edit Indent Macro 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 Overview on the right closes the active file Right clicking on a tab gives a menu of useful actions for that file ex_usb_mouse c pex_usb_common h E h24F256GB206 h x 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 sald da spalo lt Sse ynUapl 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 if defined
281. oftware controlled Requires Nothing Examples brownout_enable TRUE Example Files None Also See restart_cause bsearch Syntax ip bsearch amp key base num width compare Parameters key Object to search for base Pointer to array of search data num Number of elements in search data width Width of elements in search data compare Function that compares two elements in search data Returns bsearch returns a pointer to an occurrence of key in the array pointed to by base If key is not found the function returns NULL If the array is not in order or contains duplicate records with identical keys the result is unpredictable Function Performs a binary search of a sorted array Availability All devices Requires INCLUDE lt stdlib h gt Examples int nums 5 1 2 3 4 5 int compar const void argl const void arg2 void main 156 Example Files Also See calloc Syntax Parameters Returns Function Availability Requires Examples Example Files Also See ceil Syntax Parameters Built in Functions int ip key key 3 ip bsearch 8key nums 5 sizeof int compar int compar const void argl const void arg2 if int argl lt int arg2 return 1 else if int argl int arg2 return 0 else return 1 None qsort ptr calloc nmem size nmem is an integer representing the number of member objects
282. om erase program eeprom Program Eeprom Overview write extended_ram Syntax Parameters Returns Function Availability Requires Examples Example Files Also See write_extended_ram page address data count page the page in extended RAM to write to address the address on the selected page to start writing to data pointer to the data to be written count the number of bytes to write 0 32768 undefined To write data to the extended RAM of the PIC On devices with more then 30K of RAM Nothing unsigned int8 data 8 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 write extended ram 1 0x0000 data 8 None read extended ram Extended RAM Overview write_program_eeprom Syntax Parameters Returns Function Availability write_program_eeprom address data address is 16 bits on PCM parts and 32 bits on PCH parts data is 16 bits The least significant bit should always be 0 in PCH undefined Writes to the specified program EEPROM area See our write_program_memory for more information on this function Only devices that allow writes to program memory 349 CCS C 10082015 Requires Examples Example Files Also See Nothing write program eeprom 0 0x2800 disables program ex _load c loader c read_program_eeprom read eeprom write eeprom write_program_memory erase program eeprom Program Eeprom Overview zdc_sta
283. om offset defaults to zero if not used undefined For PIC18 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 All PIC18 Flash and Enhanced16 devices Nothing int data 6 read configuration memory data 6 None write configuration memory read program memory Configuration Memory Overview 243 CCS C 10082015 read_eeprom Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value read_eeprom address address is an 8 bit or 16 bit int depending on the part An 8 bit int Reads a byte from the specified data EEPROM address The address begins at O and the range depends on the part This command is only for parts with built in EEPROMS Nothing define LAST VOLUME 10 volume read EEPROM LAST VOLUME None write_eeprom Data Eeprom Overview read _extended_ram Syntax Parameters Returns Function Availability Requires Examples Example Files 244 read_extended_ram page address data count 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 Undefined To read data from the extended RAM of the PIC On de
284. ompiler and the PCW IDE Project Manager can also be used to compile link build 88 PreProcessor modules and or projects Multiple EXPORT directives may be used to generate multiple hex files this may be used for 8722 like devices with external memory Examples EXPORT RELOCATABLE ONLY TimerTask void TimerFuncl void some code void TimerFunc2 void some code void TimerFunc3 void some code void TimerTask void TimerFuncl TimerFunc2 TimerFunc3 This source will be compiled into a relocatable object but the object this is being linked to can only see TimerTask E Example None Files See Also IMPORT MODULE Invoking the Command Line Compiler Multiple Compilation Unit file Syntax _ FILE __ Elements None Purpose The pre processor identifier is replaced at compile time with the file path and the filename of the file being compiled Examples if index gt MAX ENTRIES prints Too many entries source files mini ie a ie ott Example assert h Files Also See line _ filename _ Syntax _ FILENAME _ Elements None 89 CCS C 10082015 Purpose The pre processor identifier is replaced at compile time with the filename of the file being compiled Examples if index gt MAX ENTRIES prints Too many entries Source file O FILENAME at line TINE r n Example None Files Also See line fill_ rom Syntax fill_rom value Elements value is a con
285. on clock data protocol spi write spi read spi data is in SPI Overview setup_timer_A mode 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 Returns Function Availability Requires Examples Example Files Also See Built in Functions TA_DIV_64 TA _DIV_128 TA_DIV_256 constants from different groups may be or ed together with undefined sets up Timer A This function is only available on devices with Timer A hardware Constants are defined in the device s h file setup_timer A TA_OFF setup timer A TA_INTERNAL TA DIV_256 setup timer A TA EXT L TO H TA DIV 1 none get_timerA set_timerA TimerA Overview setup_timer_B Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_timer_B mode 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 undefined sets up Timer B This function is only available on devices with Timer B hardware Constants are defined in device s h file setup_timer B TB OFF setup timer B TB_ INTERNAL TB _DIV_256 setup timer B TA EXT L TO H TB DIV 1 none get_t
286. ons can be used only on chips that allow reads from program memory The compiler uses the flash memory read routines to implement the functionality 31 CCS C 10082015 32 Data Definitions Named Registers The CCS C Compiler supports the new syntax for filing a variable at the location of a processor register This syntax is being proposed as a C extension for embedded use The same functionality is provided with the non standard byte word bit and locate The syntax is register _name type id Or register constant type id name is a valid SFR name with an underscore before it Examples register _status int8 status_reg register _T1IF int8 timer_interrupt register 0x04 int16 file_select_register 33 FUNCTION DEFINITION Function Definition The format of a function definition is as follows qualifier id type specifier id stmt Optional See Below Zero or more comma separated Zero or more Semi colon See Data Types separated See Statements The qualifiers for a function are as follows e VOID e type specifier e separate e inline e int_ When one of the above are used and the function has a prototype forward declaration of the function before it is defined you must include the qualifier on both the prototype and function definition A non standard feature has been added to the compiler to help get around the problems created by the fact that pointers cannot be created to constant string
287. or EXCEPT is used all symbols are imported RELOCATABLE CCS relocatable object file format This is the default format when the IMPORT is used COFF COFF file format from MPASM C18 or C30 HEX Imported data is straight hex data RANGEzstart stop Only addresses in this range are read from the hex file LOCATION id The identifier is made a constant with the start address of the imported data SIZE id The identifier is made a constant with the size of the imported data This directive will tell the compiler to include link a relocatable object with this unit during compilation Normally all global symbols from the specified file will be linked but the EXCEPT and ONLY options can prevent certain symbols from being linked The command line compiler and the PCW IDE Project Manager can also be used to compile link build modules and or projects IMPORT FILE timer o ONLY TimerTask void main void while TRUE TimerTask timer o is linked with this compilation but only TimerTask is visible in scope ion tehis ele sti Y None 93 CCS C 10082015 94 Files See Also EXPORT MODULE Invoking the Command Line Compiler Multiple Compilation Unit include Syntax INCLUDE lt filename gt or INCLUDE filename Elements filename is a valid PC filename It may include normal drive and path information A file with the extension encrypted is a valid PC file The standard compiler INCLUDE
288. ork 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 215 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See undefined Sets a given pin to the high state The method of I O used is dependent on the last USE 10 directive All devices Pin constants are defined in the devices h file output _high PIN AO Int16 i PIN Al output _low PIN Al X_SQw c input output _low output _float output bit output_x USE FIXED 10 USE FAST IO USE STANDARD 1O General Purpose I O output_low Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 216 output_low p n 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 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 undefined Sets a given pin to the ground state The method of I O used is dependent on the last USE 10 directive
289. ot a bit_field Minimum value for an object of type signed char Maximum value for an object of type signed char Maximum value for an object of type unsigned char Minimum value for an object of type char unsigned Maximum value for an object of type char unsigned Maximum number of bytes in a multibyte character Minimum value for an object of type short int Maximum value for an object of type short int Maximum value for an object of type unsigned short int Minimum value for an object of type signed int Maximum value for an object of type signed int Maximum value for an object of type unsigned int Minimum value for an object of type signed long int Maximum value for an object of type signed long int Maximum value for an object of type unsigned long int Localization not supported localization structure returns null returns clocale An array used by the following functions Marks a return point for the next longjmp Jumps to the last marked point Standard C Include Files stddef h stddef h ptrdiff_t The basic type of a pointer size_t The type of the sizeof operator int wchar_t The type of the largest character set supported char 8 bits NULL A null pointer 0 stdio h stderr The standard error s stream USE RS232 specified as stream or the first USE RS232 stdout The standard output stream USE RS232 specified as stream last USE RS232 stdin The standard input s stream USE RS232 specified as stream last USE RS232
290. ota T 298 setip hspwm trigger iii e ieee 299 SEtuUP MSWMM UNIT sap dara ada 299 setup_hspwm Setup NspwmSeCOndary paii eseese indrani tether aera p iaai Pap epia ridae annia 300 setup hspwmi unit chop clock Ji srein aa aeia aanraai iaaa raaa i ean a A EE E Ke aiae paa Aapa SAE EE ieiet 301 set pded Jire et ai scant ee ec ee eee eld 302 setup low volt detect ccoo si pt aan 303 AO o Te 303 setup_opamp1 setup_opamp2 SetUP_OPAMP3 enoccccnnncccnononcninanoncnnonan cnn nono conca nn nn naar n nn nro nn nn nr rre nana rrnnnnnes 304 setup OSCIllatO lito leal Ito Oda ELA 305 A O errea eeni eraa a Ae a o aaea Bee aaa e tee EL eee iA iS 305 TALUT o PI Jaci a ee ee ew 306 setup pmploption address mask sterre eraa ea er ar er A e r E A aE e A e erario cid 307 SETUP S TAa O PE EE E E E E E E T 308 viii Table of Contents setup power WIN iia e e sande adh eee el 309 s tup power pwm PINS issseceesveden ss ethee ccsee cosh edcartvsteecee ele ideeep a a setae eet a a ae a esbeas a 311 setup psploption address mask 22 1 cesscccedesceceeaucccpsssucsneseseescnssersraeeslenescandedusdacesjaseapdenebecgeusascap esassasesiancapasaasds 311 setup_pwm1 setup_pwm2 setup_pwm3 Setup_pwIM4 ooccococcccnnoncccnnnoncnonanononononcnnnnnon cnn nannnnnnnannnenanos 312 SOTUP COM Js at aora 313 SOTUP LG A EEP E E E dei dci a des titi E 313 SAO A O 314 SOTUP SA Dri rinde caiin 314 SOU AAA e vives a A aaa daria 315 se
291. ough not necessary it is a good idea to lock the RPINRx and RPORx registers from writes after all pins have been mapped This option allows calling pin_select multiple times without performing a lock sequence each time Nothing On device with remappable peripheral pins Pin defines in device s header file pin_select U2TX PIN_BO Maps PIN_BO to U2TX peripheral pin performs unlock and lock sequences pin_select U2TX PIN_BO TRUE FALSE 141 CCS C 10082015 Example Files Also See atoi Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Maps PIN_BO to U2TX peripheral pin and performs unlock sequence pin_select U2RX PIN_B1 FALSE TRUE Maps PIN_B1 to U2RX peripheral pin and performs lock sequence None pin_select atol atoi32 ivalue atoi string or Ivalue atol string or i32value atoi32 string string is a pointer to a null terminated string of characters ivalue is an 8 bit int lvalue is a 16 bit int 32value is a 32 bit int Converts the string passed to the function into an int representation Accepts both decimal and hexadecimal argument If the result cannot be represented the behavior is undefined All devices INCLUDE lt stdlib h gt char string 10 int x strepy string 123 x atoi string x is now 123 input c printf at_clear_interrupts
292. ount is a 16 bit integer undefined Reads count bytes from program memory at address to dataptr Due to the 24 bit program instruction size on the PCD devices three bytes are read from each address location Only devices that allow reads from program memory Nothing char buffer 64 read program memory 0x40000 buffer 64 None write program eeprom write eeprom read eeprom Program eeprom overview read_sd_adc Syntax Parameters Returns Function value read_sd_adc None A signed 32 bit int To poll the SDRDY bit and if set return the signed 32 bit value stored in the SD1RESH and SD1RESL registers and clear the SDRDY bit The result returned depends on settings made with the setup_sd_adc function but will always be a signed int32 value with the most significant bits being meaningful Refer to Section 66 16 bit Sigma Delta A D Converter of the PIC24F Family Reference Manual for more information on the module and the result format 247 CCS C 10082015 Availability Examples Example Files Also See realloc Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 248 Only devices with a Sigma Delta Analog to Digital Converter SD ADC module value read_sd_adc None setup sd adc set sd adc calibration set sd adc channel realloc ptr size ptr is a null pointer or a pointer previously
293. p2510 c can 18xxx8 c can 18F4580 c Relevant getenv Parameters none Example Code can_init can_putd 0x300 data 8 3 TRUE FALS E can_getd ID data len stat CCP Functional Overview This interrupt is triggered when the PIC is woken up by activity on the CAN This interrupt is triggered when there is an error in the CAN module This interrupt is triggered when transmission from buffer 0 has completed This interrupt is triggered when transmission from buffer 1 has completed This interrupt is triggered when transmission from buffer 2 has completed This interrupt is triggered when a message is received in buffer 0 This interrupt is triggered when a message is received in buffer 1 Drivers for the MCP2510 and MCP2515 interface chips Drivers for the built in CAN module Drivers for the build in ECAN module initializes the CAN bus places a message on the CAN buss with 1D 0x300 and eight bytes of data pointed to by data the TRUE creates an extended ID the FALSE creates retrieves a message from the CAN bus storing the 1D in the ID variable the data at the array pointed to by data the number of data bytes in len and statistics about the data in the stat structure These options lets to configure and use the CCP module There might be multiple CCP modules for a device These functions are only available on devices with CCP hardware They operate in 3 modes capture comp
294. pamp2 OPAMP_DISABLED setup_opamp3 OPAMP_ENABLED OPAMP_1 TO OUTPUT None None Built in Functions setup_oscillator Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_oscillator mode finetune 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 The finetune only allowed on certain parts is a signed int with a range of 31 to 31 Some chips return a state such as OSC_STATE_STABLE to indicate the oscillator is stable 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 Only parts with a OSCCON register Constants are defined in the h file setup_oscillator OSC_2MHZ None FUSES Internal oscillator Overview setup_pga Syntax Parameters
295. passed to the longjmp 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 All devices INCLUDE lt setjmp h gt result setjmp jmpbuf None longimp setup_adc mode Syntax Parameters Returns Function Availability Requires Examples setup_adc mode setup_adc2 mode 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 e ADC_OFF e ADC_CLOCK_ INTERNAL e ADC_CLOCK_DIV_32 undefined Configures the analog to digital converter Only the devices with built in analog to digital converter Constants are defined in the devices h file setup_adc ports ALL ANALOG setup adc ADC CLOCK INTERNAL set_adc_channel 0 value read_adc setup_adc ADC OFF 285 CCS C 10082015 Example Files Also See ex_admm c setup adc ports set adc_channel read_adc DEVICE ADC Overview see header file for device selected setup_adc_ports Syntax Parameters Returns Function Also See setup_adc_ports value setup_adc_ports ports reference value a constant defined in the devices h file ports is a constant specifying the ADC pins to use reference is an optional constant specifying the ADC reference to use By default the reference
296. pdated by the ICD programmer It is assumed this is a file one serial number per line The programmer will read the first line then delete that line from the file next x The serial number X is used for the first load then the hex file is updated to increment x by one Other optional parameters prompt text If specified the user will be prompted for a serial number on each load If used with one of the above three options then the default value the user may use is picked according to the above rules log xxx A file may optionally be specified to keep a log of the date time hex file name and serial number each time the part is programmed If no id xxx is specified then this may be used as a simple log of all loads of the hex file Assists in making serial numbers easier to implement when working with CCS ICD units Comments are inserted into the hex file that the ICD software interprets Prompt user for serial number to be placed at address of serialNumA Default serial number 200int8int8 const serialNumA 100 serialize id serialNumA next 200 prompt Enter the serial number Adds serial number log in seriallog txt serialize id serialNumA next 200 prompt Enter the serial number log seriallog txt Retrieves serial number from serials txt serialize id serialNumA listfile serials txt Place serial number at EEPROM address 0 reserving 1 byte serialize dataee 0 binary 1 next 45 prompt
297. peripheral to be connected to bus but that doesn t mean it has been enumerated by the PC Will enable and use the USB interrupt The same as usb_init but does not wait for the device to be connected to the bus This is useful if your device is not bus powered and can operate without a USB connection If you use connection sense and the usb_init_cs for initialization then you must periodically call this function to keep an eye on the connection sense pin When the PIC is connected to the BUS this function will then perpare the USB peripheral When the PIC is disconnected from the BUS it will reset the USB stack and peripheral Will enable and use the USB interrupt Note In your application you must define USB_CON_SENSE PIN to the connection sense pin usb_detach usb_attach usb_attached usb_enumerated usb_put_packet endpoint data len tgl usb_puts endpoint data len timeout usb_kbhit endpoint usb_get_packet endpoint ptr max usb_gets endpoint ptr max timeout 68 Removes the PIC from the bus Will be called automatically by usb_task if connection is lost but can be called manually by the user Attaches the PIC to the bus Will be called automatically by usb_task if connection is made but can be called manually by the user If using connection sense pin USB_CON_SENSE_PIN returns TRUE if that pin is high Else will always return TRUE Returns TRUE if the device has been
298. power of y x power y exp y log x None pow log log10 Built in Functions ext_int_edge Syntax Parameters Returns Function Availability Requires Examples Example Files Also See fabs Syntax Parameters Returns Function Availability Requires Examples Example Files Also See ext_int_edge source edge source is a constant 0 1 or 2 for the PIC18XXX and 0 otherwise Source is optional and defaults to 0 edge is a constant H_TO_L orL_TO_H representing high to low and low to high undefined Determines when the external interrupt is acted upon The edge may be L_TO Hor H_TO_L to specify the rising or falling edge Only devices with interrupts PCM and PCH Constants are in the devices h file ext_int edge 2 L TO H Set up PIC18 EXT2 ext int edge H TO L Sets up EXT ex _wakup c INT EXT enable interrupts disable interrupts Interrupts Overview result fabs va ue value is a float result is a float The fabs function computes the absolute value of a float All devices INCLUDE lt math h gt float result result fabs 40 0 result is 40 0 None abs labs 173 CCS C 10082015 getc getch getchar fgetc Syntax value getc value fgetc stream value getch value getchar Parameters stream is a stream identifier a constant byte Returns An 8 bit character Function Th
299. ppliers will be liable for personal injury or any incidental special indirect or consequential damages whatsoever including without limitation damages for loss of profits loss of data business interruption or any other commercial damages or losses arising out of or related to your use or inability to use the Software Licensee is responsible for determining whether Software is suitable for Applications 1994 2015 Custom Computer Services Inc ALL RIGHTS RESERVED WORLDWIDE PO BOX 2452 BROOKFIELD WI 53008 U S A 356
300. put one nibble in each of the four ID words in the traditional manner The second syntax specifies the exact value to be used in each of the four ID words When a filename is specified the ID is read from the file The format must be simple text with a CR LF at the end The keyword CHECKSUM indicates the device checksum should be saved as the ID id 0x1234 id serial num id CHECKSUM ex custe None ignore_warnings Syntax Elements Purpose Examples Example Files Also See 92 ignore_warnings ALL IGNORE_WARNINGS NONE IGNORE_WARNINGS warnings warnings is one or more warning numbers separated by commas This function will suppress warning messages from the compiler ALL indicates no warning will be generated NONE indicates all warnings will be generated If numbers are listed then those warnings are suppressed ignore warnings 203 while TRUE ignore warnings NONE None Warning messages PreProcessor import options Syntax Elements Purpose Examples Example IMPORT options FILE filname The filename of the object you want to link with this compilation ONL Y symbol symbol symbol Only the listed symbols will imported from the specified relocatable object file If neither ONLY or EXCEPT is used all symbols are imported EXCEPT symbol symbol symbol The listed symbols will not be imported from the specified relocatable object file If neither ONLY
301. r Logical OR operator Member operator for structures and unions Modules assignment operator x y is the same as x x y Modules operator Multiplication assignment operator x y is the same as x x y Multiplication operator One s complement operator Right shift assignment x gt gt y is the same as x x gt gt y Right shift operator Structure Pointer operation Subtraction assignment operator x y is the same as x x y Subtraction operator Determines size in bytes of operand See also Operator Precedence Operator Precedence PIN DESCENDING PRECEDENCE expr expr lexpr type expr expr expr expr expr expr lt lt expr expr lt expr Associativity exor expr gt expr expr expr Left to Right expr expr expr Left to Right expr expr expr Right to Left expr amp value sizeof type Right to Left expr expr expr expr Left to Right expr expr Left to Right expr gt gt expr Left to Right expr lt expr expr gt expr expr gt expr Left to Right 23 CCS C 10082015 expr expr expr expr Left to Right expr amp expr Left to Right expr4expr Left to Right expr expr Left to Right expr amp amp expr Left to Right expr expr Left to Right expr expr expr Right to Left Ivalue expr lvalue expr lvalue expr Right to Left Ivalue expr lvalue expr lvalue expr Right to Left Ivalue gt gt expr lvalue lt lt expr lvalueg8 expr Right to Left Ivalue expr lvalue expr Right to Left expr expr Left to
302. r c enable interrupts GLOBAL while TRUE if TOUCHPAD HIT wait until key on PIN BO is pressed c TOUCHPAD GETC get key that was pressed c will get value A None USE TOUCHPAD touchpad state touchpad getc 341 CCS C 10082015 touchpad_state Syntax Parameters Returns Function Availability Requires Examples Example Files Also See TOUCHPAD _ STATE state state is a literal 0 1 or 2 None 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 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 All PIC s with a CSM Module USE TOUCHPAD options USE TOUCHPAD THRESHOLD 5 PIN D5 5 PIN BO C void main void char ci 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 BO is pressed c will get value C if PIN D5 is pressed c will get value 5 None USE TOUCHPAD touchpad _getc touchpad _hit tx_buffer_available Syntax Parameters Returns Function 342 value tx_buffer_available stream stre
303. r of bytes to work with undefined Rotates a bit through an array or structure The address may be an array identifier or an address to a byte or structure such as amp data Bit 0 of the lowest BYTE in RAM is considered the LSB All devices Nothing struct int cell 1 4 int cell 2 4 int cell 3 4 int cell 4 4 cells rotate right amp cells 2 rotate right amp cells 2 rotate right amp cells 2 rotate right amp cells 2 cell_1 gt 4 2 gt 1 3 gt 2 and 4 gt 3 None rotate left shift_left shift_right rtc_alarm_read Syntax Parameters Returns Function 252 rtc_alarm_read amp datetime 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 void Reads the date and time from the alarm in the RTCC module to structure datetime Availability Requires Examples Example Files Also See Built in Functions Devices that have the RTCC module Nothing rtc_alarm_read amp datetime None rtc_read rtc_alarm_read rtc_ alarm write setup rtc_alarm rtc_write setup rtc rtc_alarm_write Syntax Parameters Returns Function Availability Requires Examples Example Files Also See ric_alarm_write 8 datetime datetime A structure that will contain the va
304. r pass the address of the structure as the parameter or a pointer to the structure as the parameter Nothing To pass the set point and input from the control system to the PID module start the PID calculation and get the result of the PID calculation The PID calculation starts automatically when the input is written to the PID module s input registers All devices with a PID module Constants are defined in the device s h file pid_get_result SetPoint ADCResult amp PIDOutput Start and Read pid_get_result PID START ONLY SetPoint ADCResult Start Only pid_get_result PID READ ONLY amp PIDResult Read Only None setup pid pid read pid write pid busy pid_read register output register constant specifying which PID registers to read The registers that can be written are defined in the device s header file as PID_ADDR_ACCUMULATOR PID_ADDR_OUTPUT PID_ADDR_Z1 PID_ADDR_Z2 PID_ADDR_K1 PID_ADDR_K2 PID_ADDR_K3 output a 16 bit variable 32 bit variable or structure that specified PID registers value will be saved to The size depends on the registers that are being read Either pass the address of the variable or structure as the parameter or a pointer to the variable or structure as the parameter Nothing 219 CCS C 10082015 Function To read the current value of the Accumulator Output Z1 Z2 Set Point K1 K2 or K3 PID registers If the PID is busy with a calculation the function wi
305. rallel Master Port module Constants are defined in the devices h file setup psp PAR PSP AUTO INC Sets up legacy slave mode with PAR STOP_IN_IDLE 0x00FF read and write buffers auto increment None psp output full psp input full psp overflow See header file for device selected setup_pwm1 setup_pwm2 setup_pwm3 setup_pwm4 Syntax Parameters Returns Function Availability Examples Example Files Also See 312 setup_pwm1 settings setup_pwm2 settings setup_pwm3 settings setup_pwm4 settings 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 Undefined Sets up the PWM module On devices with a PWM module setup_pwml PWM ENABLED PWM OUTPUT None set pwm_duty Built in Functions setup_qei Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_qei options filter maxcount Options The mode of the QE module See the devices h file for all options Some common options are QEL_MODE_X2 QEI_MODE_X4 filter This parameter is optional the user can enable the digital filters and specify the clock divisor maxcount Specifies the value at which to reset the position counter void Configures the Quadrature Encoder Interface Various settings like mode a
306. rameters Returns Function Availability Requires Examples Example Files Also See crc_init data data This will setup the initial value used by write CRC shift register Most commonly this register is set to 0x0000 for start of a new CRC calculation undefined Configures the CRCWDAT register with the initial value used for CRC calculations Only the devices with built in CRC module Nothing crc init Starts the CRC accumulator out at 0 crc_init OxFEEE Starts the CRC accumulator out at OxFEEE None setup_crc crc_calc crc_calc8 cwg_status Syntax Parameters value cwg_status None 163 CCS C 10082015 Returns the status of the CWG module Function To determine if a shutdown event occured causing the module to auto shutdown Availability On devices with a CWG module Examples if cwg status CWG AUTO SHUTDOWN cwg_restart Example Files None Also See setup cwa cwg restart cwg_restart Syntax cwg_restart Parameters None Returns Nothing Function To restart the CWG module after an auto shutdown event occurs when not using auto raster option of module Availability On devices with a CWG module Examples if cwg_status CWG_AUTO SHUTDOWN cwokres tara Example Files None Also See setup cwa cwg _status dac_write Syntax dac_write value Parameters Value 8 bit integer value to be w
307. rate lots of profile data which may make it difficult to debug or follow By using profile the user can dynamically control which points of the program are being profiled and limit data to what is relevant to the user Examples profile off void BigFunction void BigFunction code goes here Since profile off was called above no profiling will happen even for other functions called by BigFunction profile on Example ex_profile c Files Also See use profile profileout Code Profile overview 107 CCS C 10082015 Elements reserve Syntax RESERVE address or RESERVE address address address or RESERVE start end address is a RAM address start is the first address and end is the last address Purpose Examples Example Files Also See rom This directive allows RAM locations to be reserved from use by the compiler RESERVE must appear after the DEVICE otherwise it will have no effect When linking multiple compilation units be aware this directive applies to the final object file DEVICE PIC16C74 RESERVE 0x60 0X6f ex custe ORG FROM address list Syntax Elements FROM type address list address is a ROM word address listis a list of words separated by commas Purpose 108 Allows the insertion of data into the HEX file In particular this may be used to program the 84 data EEPROM as shown in the following example Note that if
308. rce and prescale as 1 At 20Mhz timer5 will increment every 2us in this setup and overflows every 13 1072ms this sets timer5 register to 0 this will read the timer5 register value These options lets the user configure and use timerA It is available on devices with Timer A hardware The clock counter is 8 bit It counts up and also provides interrupt on overflow The options available are listed in the device s header file Relevant Functions setup_timer_A mode set_timerA value value get_timerA Relevant Preprocessor None Relevant Interrupts INT_TIMERA Relevant Include Files Relevant getenv parameters TIMERA Example Code 66 Disable or sets the source and prescale for timerA Initializes the timerA clock counter Returns the value of the timerA clock counter Interrupt fires when timerA overflows None all functions built in Returns 1 if the device has timerA setup_timer_A TA_OFF or setup_timer_A TA_INTERNAL TA_DIV_8 set_timerA 0 time get_timerA TimerB Functional Overview disable timerA sets the internal clock as source and prescale as 8 At 20MHz timerA will increment levery 1 6us in this setup and overflows every 409 6us this sets timerA register to 0 this will read the timerA register value These options lets the user configure and use timerB It is available on devices with TimerB hardware The clock counter is 8 bit It counts up and
309. resolution and compiler will generate a message specifying the frequency and period of PWM or if using same timer as previous stream instead of setting to maximum possible it will be set to the same as previous stream If using same timer as previous stream and period is different compiler will generate an error Sets the resolution of the the duty cycle if period or frequency is specified will adjust the period to meet set resolution and will generate an message specifying the frequency and duty of PWM If period or frequency not specified will set period to maximum possible for specified resolution and compiler will generate a message specifying the frequency and period of PWM unless using same timer as previous then it will generate an error if resolution is different then previous stream If not specified then frequency period or previous stream using same timer sets the resolution Selects the duty percentage of PWM default if not specified is 50 Initialize the PWM in the ON state default state if pwm_on or pwm_off is not specified Initalize the PWM in the OFF state Associates a stream identifier with the PWM signal The identifier may be used in functions like pwm_set_duty_percent Purpose This directive tells the compiler to setup a PWM on the specified pin using the specified frequency period duty cycle and resolution The USE DELAY directive must appear before this directive can be used This directive enables use of built
310. restart_cause if restart RTC_FROM DS release io Example Files None Also See slee reset_cpu Syntax reset_cpu Parameters None Returns This function never returns Function This is a general purpose device reset It will jump to location 0 on PCB and PCM parts and also reset the registers to power up state on the PIC18XXX Availability All devices Requires Nothing Examples if checksum 0 reset_cpu Example Files None Also See None 249 CCS C 10082015 restart_cause Syntax value restart_cause Parameters None Returns A value indicating the cause of the last processor reset The actual values are device dependent See the device h file for specific values for a specific device Some example values are WDT_FROM_SLEEP WDT_TIMEOUT MCLR_FROM_SLEEP and NORMAL_POWER_UP Function Returns the cause of the last processor reset Availability All devices Requires Constants are defined in the devices h file Examples switch restart _cause case WDT FROM SLEEP case WDT TIMEOUT handle error Example Files ex_wat c Also See restart wdt reset cpu restart_wdt Syntax restart_wdt Parameters None Returns undefined Function Restarts the watchdog timer If the watchdog timer is enabled this must be called periodically to prevent the processor from resetting The watchdog timer is used to cause a hardware reset if the software appears to be stuck
311. returned by calloc or malloc or realloc function size is an integer representing the number of byes to be allocated A pointer to the possibly moved allocated memory if any Returns null otherwise The realloc function changes the size of the object pointed to by the pir to the size specified by the size The contents of the object shall be unchanged up to the lesser of new and old sizes If the new size is larger the value of the newly allocated space is indeterminate If ptr is a null pointer the realloc function behaves like malloc function for the specified size If the ptr does not match a pointer earlier returned by the calloc malloc or realloc or if the space has been deallocated by a call to free or realloc function the behavior is undefined If the space cannot be allocated the object pointed to by ptr is unchanged If size is zero and the ptr is not a null pointer the object is to be freed All devices INCLUDE lt stdlibm h gt Lat iptry iptr malloc 10 realloc iptr 20 iptr will point to a block of memory of 20 bytes if available None malloc free calloc Built in Functions release_io Syntax release_io Parameters none Returns nothing Function The function releases the I O pins after the device wakes up from deep sleep allowing the state of the I O pins to change Availability Devices with a deep sleep module Requires Nothing Examples unsigned int16 restart restart
312. riteria as follows isalnum x isalpha x isdigit x islower x isupper x isspace x isxdigit x iscntrl x isgraph x isprint x ispunct x All devices INCLUDE lt ctype h gt char id 20 if isalpha id 0 valid_id TRUE X is 0 9 A Z or a z X is A Z or a Z X is 0 9 X is a z X is A Z X is a space X is 0 9 A F or a f X is less than a space X is greater than a space X is greater than or equal to a space X is greater than a space and not a letter or number for i 1 i lt strlen id i valid_id valid_id amp amp isalnum id i else valid id FALSE ex_str c isamong result isamong value cstring value is a character cstring is a constant sting 0 or FALSE if value is not in cstring 1 or TRUE if value is in cstring Function Availability Requires Examples Example Files Also See itoa Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions Returns TRUE if a character is one of the characters in a constant string All devices Nothing char x x if isamong x 012345678 9ABCDEFGHIJKLMNOPORSTUVWXYZ printf The character is valid INCLUDE lt ctype h gt isalnum isalpha isdigit isspace islower isupper isxdigit string itoa i32value i8base string i32valu
313. ritten to the DAC module Returns undefined 164 Function Availability Requires Examples Also See Built in Functions This function will write a 8 bit integer to the specified DAC channel Only available on devices with built in digital to analog converters Nothing int i 0 setup _ dac DAC VDD DAC OUTPUT while 1 LAA dac write i setup dac DAC Overview see header file for device selected delay_cycles Syntax Parameters Returns Function Availability Requires Examples Example Files Also See delay_cycles count count a constant 1 255 undefined Creates code to perform a delay of the specified number of instruction clocks 1 255 An instruction clock is equal to four oscillator clocks The delay time may be longer than requested if an interrupt is serviced during the delay The time spent in the ISR does not count toward the delay time All devices Nothing delay cycles 1 Same as a NOP delay cycles 25 At 20 mhz a 5us delay ex_cust c delay _us delay _ms delay_ms Syntax delay_ms time 165 CCS C 10082015 Parameters time a variable 0 65535 int16 or a constant 0 65535 Note Previous compiler versions ignored the upper byte of an int16 now the upper byte affects the time Returns undefined Function This function will create code to perform a delay of the specified length Time is specified in
314. rrupt INT_RDA Example Files None Also see DISABLE INTERRUPTS Interrupts Overview CLEAR INTERRUPT ENABLE _INTERRUPTS INTERRUPT ACTIVE 72 Stream I O Syntax Output Examples Input Functional Overview include lt ios h gt is required to use any of the ios identifiers output stream lt lt variable_or_constant_or_manipulator one or more repeats stream may be the name specified in the use RS232 stream option or for the default stream use cout stream may also be the name of a char array In this case the data is written to the array with a O terminator stream may also be the name of a function that accepts a single char parameter In this case the function is called for each character to be output variables constants May be any integer char float or fixed type Char arrays are output as strings and all other types are output as an address of the variable manipulators hex Hex format numbers dec Decimal format numbers default setprecision x Set number of places after the decimal point setw x Set total number of characters output for numbers boolalpha Output int1 as true and false noboolalpha Output int1 as 1 and O default fixed Floats in decimal format default scientific Floats use E notation iosdefault All manipulators to default settings endl Output CR LF ends Outputs a null 1000 cout lt lt Value is lt lt hex lt lt data lt l
315. rst called with a seed value of 1 All devices INCLUDE lt STDLIB H gt srand 10 I ranad None rand STANDARD STRING FUNCTIONS memchr stremp stricmp strncmp strspn Syntax Parameters 334 memcmp strcoll strlen strncpy strstr ptr strcat s1 s2 ptr strchr s1 c ptr strrchr s1 c cresult stremp s1 s2 iresult strncmp s1 s2 n iresult stricmp s1 s2 ptr strncpy s1 s2 n iresult strespn s1 s2 iresult strspn s1 s2 iresult strlen s1 ptr strlwr s1 ptr strpbrk s1 s2 ptr strstr s1 s2 ptr strncat s7 s2 n iresult strcoll s1 s2 res strxfrm s7 s2 n iresult memcmp 7 m2 n ptr memchr m 7 c n ptr strerror errnum strcat strchr strcspn strerror striwr sirncat strpbrk strrchr strxfrm Concatenate s2 onto s1 Find c in s1 and return amp s1 i Same but search in reverse Compare s1 to s2 Compare s1 to s2 n bytes Compare and ignore case Copy up to n characters s2 gt s1 Count of initial chars in s1 not in s2 Count of initial chars in s1 also in s2 Number of characters in s1 Convert string to lower case Search s1 for first char also in s2 Search for s2 in s1 Concatenates up to n bytes of s2 onto s1 Compares s1 to s2 both interpreted as appropriate to the current locale Transforms maximum of n characters of s2 and places them in s1 such that stremp s1 s2 will give the same r
316. rt_outputs pin pin port is A G pin is one of the pin constants defined in the devices h file This directive affects how the compiler will generate code for input and output instructions that follow This directive takes effect until another USE XXX_IO directive is encountered The fixed method of doing I O will cause the compiler to generate code to make an I O pin either input or output every time it is used The pins are programmed according to the information in this directive not the operations actually performed This saves a byte of RAM used in standard I O When linking multiple compilation units be aware this directive only applies to the current compilation unit tuse fixed_io a_outputs PIN A2 PIN A3 None USE FAST 10 USE STANDARD 10 General Purpose I O USE 12C options 117 CCS C 10082015 Elements Purpose Examples 118 Options are separated by commas and may be MASTER MULTI_MASTER SLAVE SCL pin SDA pin ADDRESS nn FAST FAST nnnnnn SLOW RESTART_WDT FORCE_HW FORCE_SW NOFLOAT_HIGH SMBUS STREAM id NO_STRETCH MASK nn 12C1 12C2 NOINIT Sets to the master mode Set the multi_master mode Set the slave mode Specifies the SCL pin pin is a bit address Specifies the SDA pin Specifies the slave mode address Use the fast 12C specification Sets the speed to nnnnnn hz Use the slow 12C specification Restart the WDT while waiting in 2C_READ Use hardware 12C functions Use
317. rupt active at setup cc at set compare time at get capture setup at 149 CCS C 10082015 at_interrupt_active Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 150 result at_interrupt_active interrupt interrupts an 8 bit constant specifying which AT interrupts to check if its flag is set The constants are defined in the device s header file as AT_PHASE_INTERRUPT AT_MISSING_PULSE_INTERRUPT AT_PERIOD_INTERRUPT AT_CC3_INTERRUPT AT_CC2_INTERRUPT AT_CC1_INTERRUPT TRUE if the specified AT interrupt s flag is set interrupt is active or FALSE if the flag is clear interrupt is not active To check if the specified Angular Timer interrupt flag is set All devices with an AT module Constants defined in the device s header file INT AT1 voidl_isr void FU if at_interrupt active AT PERIOD INTERRUPT handle period _interrupt ERIOD_INTERRUPT FU at_clear interrupts AT_ FU if at_interrupt active AT PHASE INTERRUPT handle phase interrupt HASE INTERRUPT FU at_clear interrupts AT_ None 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
318. s Function erase_program_eeprom address address is 16 bits on PCM parts and 32 bits on PCH parts The least significant bits may be ignored undefined Erases FLASH_ERASE_SIZE bytes to OxFFFF in program memory FLASH_ERASE_SIZE varies depending on the part For example if it is 64 bytes then the least significant 6 bits of address is ignored 171 CCS C 10082015 Availability Requires Examples Example Files Also See exp Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 172 See write_program_memory for more information on program memory access Only devices that allow writes to program memory Nothing for i 0x1000 i lt 0x1fff it t getenv FLASH ERASE SIZE erase program memory i None write program eeprom write program memory Program Eeprom Overview result exp value value is a float A float Computes the exponential function of the argument This is e to the power of value where e is the base of natural logarithms exp 1 is 2 7182818 Note on error handling If errno h is included then the domain and range errors are stored in the errno variable The user can check the errno to see if an error has occurred and print the error using the perror function Range error occur in the following case e exp when the argument is too large All devices INCLUDE lt math h gt Calculate x to the
319. s Writes N bytes to address from pointer Can also be used to put data EEPROM memory data into the hex file Allows interrupts to occur while the write_eeprom operations is polling the done bit to check if the write operations has completed Can be used as long as no EEPROM operations are performed during an ISR Interrupt fires wen EEPROM write is complete Size of data EEPROM memory inserts this data into the hex file The data eeprom address Idiffers for different family of chips Please refer to the programming specs to find the right value for the device writes 0x12 to data eeprom location O reads data eeprom location 0x0 returns 0x12 Inserts this data into the hex file The data EEPROM address differs between PICs Please refer to the device editor for device specific values Writes 0x1337 to data EEPROM location 10 Reads data EEPROM location 10 returns 0x1337 47 CCS C 10082015 Data Signal Modulator The Data Signal Modulator DSM allows the user to mix a digital data stream the modulator signal with a carrier signal to produce a modulated output Both the carrier and the modulator signals are supplied to the DSM module either internally from the output of a peripheral or externally through an input pin The modulated output signal is generated by performing a logical AND operation of both the carrier and modulator signals and then it is provided to the MDOUT pin Using this method t
320. s A function that has one CHAR parameter will accept a constant string where it is called The compiler will generate a loop that will call the function once for each character in the string Example void lcd putc char c lcd putec Hi There SEE ALSO Overloaded Functions Reference Parameters Default Parameters Variable Parameters Overloaded Functions Overloaded functions allow the user to have multiple functions with the same name but they must accept different parameters Here is an example of function overloading Two functions have the same name but differ in the types of parameters The compiler determines which data type is being passed as a parameter and calls the proper function This function finds the square root of a long integer variable long FindSquareRoot long n 35 CCS C 10082015 This function finds the square root of a float variable float FindSquareRoot float n FindSquareRoot is now called If variable is of long type it will call the first FindSquareRoot example If variable is of float type it will call the second FindSquareRoot example result FindSquareRoot variable Reference Parameters The compiler has limited support for reference parameters This increases the readability of code and the efficiency of some inline procedures The following two procedures are the same The one with reference parameters will be implemented with greater efficiency when it is
321. s a sleep after the last statement in main Availability All devices Requires Nothing Examples SLEEP Example Files ex_wakup c Also See reset cpu sleep_ulpwu Syntax sleep_ulpwu time Parameters time specifies how long in us to charge the capacitor on the ultra low power wakeup pin by outputting a high on PIN_ AO Returns undefined Function Charges the ultra low power wake up capacitor on PIN_AO for time microseconds and then puts the PIC to sleep The PIC will then wake up on an Interrupt on Change after the charge on the cap is lost 322 Built in Functions Availability Ultra Low Power Wake Up support on the PIC example PIC12F683 Requires USE DELAY Examples while TRUE if input PIN Al do something else sleep ulpwu 10 cap will be charged for 10us then goto sleep Example Files None Also See USE DELAY sleep_ulpwu Syntax sleep_ulpwu time Parameters time specifies how long in us to charge the capacitor on the ultra low power wakeup pin by outputting a high on PIN_BO Returns undefined Function Charges the ultra low power wake up capacitor on PIN_BO for time microseconds and then puts the PIC to sleep The PIC will then wake up on an Interrupt on Change after the charge on the cap is lost Availability Ultra Low Power Wake Up support on the PIC example PIC124F32KA302 Requires USE DELAY Examples while TRUE if input PIN Al
322. s nciga E heen ee 181 ARIAS Me ohne eens ie adn dd adi 181 R ELE A AS 182 EELEE E EEEE E E E EET TE E T T A E E T 182 CPT a R a E E E is 183 OBS e AE E EE E E E E E E NE EE 183 goto addres J aiaee aa aaa anarai Eea a Eaa raae eaa aa aa Eea ee ea E aa E AE Eaa Na raa aa A EEEE A 187 RGU Sed ACI RA 188 A o EE EE 188 e SO State hecne eiretar eee EE eee ere ere 189 A E AA Selc stake tet testectes hceccstilacsetaesene 190 RTE PP O EN TAE 190 A E A EE E TE E E T 191 E SS E E E A E E T E E 192 BAS STAI O An E E E EE 192 EEE e A E EE E E S EEE E E lia ldewia dt anpeiedcadanesnazagyecel 193 AEE AP E E AAE E E A E E E EE A A T AE TE E 193 ETSE e PEE AREAN NN 194 MPAA E E A T E E E E ees as 195 TN EEC E E E EEE E E E E E E A A E E EEEN 196 T a A 196 MA E O 197 isalnum char isalpha char iscntri x isdigit char isgraph x islower char isspace char isupperichan isxdigit char SHIT ISPDUNCI N coin iaa loci caba 197 A O TN 198 IE ses ce ccdtecscccsccocecassacscocetedstessteccsccscecsteascedseacetecetesstececccacecsecceceeuscuacteaseadseamecuadagancatezamsaaed eecadezeaiguadigacgateziee tas 199 Mi eb T E AE acta nate dank E A E A E A T E E S EE TET 200 TA A AEE E E A E E E E E E E E 200 Elo AEA e E A in 201 O 202 O 202 A a e E a adh eo A ha an ede 203 0 SONY esis dois dss lloc ln lo ii in 203 O A E NO 204 o E oa pense sag oso te ae ees bas susie Sas a e E teaver 204 A ee ae A A ERA ONE A PEEP EDD OPERA OEE RE 205 132 Built in Fun
323. s the following function to replace the compiler interrupt dispatcher The function is normally not required and should be used with great caution When used the compiler does not generate start up code or clean up code and does not save the registers Examples int_global ls Q A Will be located at location 4 for PIC16 chips asm bs isr flag retfie fendasm Example ex_glint c Files Also See INT xxxx line__ Syntax __line__ Elements None 98 Purpose Examples Example Files Also See list Syntax Elements Purpose Examples Example Files Also See line Syntax Elements Purpose Examples PreProcessor The pre processor identifier is replaced at compile time with line number of the file being compiled if index gt MAX ENTRIES printi Loo many entries source fille a ae lie ia Me assert h file LIST None LIST begins inserting or resumes inserting source lines into the LST file after a NOLIST NOLIST El Done Clliiciceie We tes liste lille include lt cdriver h gt LIST 16c74 h NOLIST LINE number file name Number is non negative decimal integer File name is optional The C pre processor informs the C Compiler of the location in your source code This code is simply used to change the value of LINE and _FILE_ variables 1 void main line 10 specifies the line number that should be reported for the fol
324. s which SMT registers to write The following defines have been made in the device s header file to select which registers are written SMT_TMR_REG SMT_PERIOD_REG value The 24 bit value to set the specified registers Nothing To write the Timer Registers or Period Registers of the Signal Measurement Timer SMT module Only devices with a built in SMT module smtl_write SMT_PERIOD REG 0x100000000 None smtx_status stmx_start setup smtx smtx_update smtx reset timer smtx_read setup smtx smtx_update Syntax Parameters Returns 326 smt1_update which smt2_update which which Specifies which capture registers to manually update The following defines have been made in the device s header file to select which registers are updated SMT_CAPTURED_PERIOD_REG SMT_CAPTURED_PULSE_WIDTH_REG Nothing Built in Functions Function To manually update the Capture Period Registers or the Capture Pulse Width Registers of the Signal Measurement Timer module Availability Only devices with a built in SMT module Examples smtl_update SMT CAPTURED PERIOD REG Example Files None Also See setup smtx stmx start smtx _stop smtx_status smtx reset timer smtx_read smtx_write spi_data_is_in spi_data_is_in2 Syntax result spi_data_is_in result spi_data_is_in2 Parameters None Returns 0 FALSE or 1 TRUE Function Returns TRUE if data has been r
325. se set pwm period set pwm_offset enable pwm_interrupt clear pwm_interrupt disable pwm_interrupt qei_get_counit Syntax Parameters Returns value gei_get_count type type Optional parameter to specify which counter to get defaults to position counter Defined in devices h file as QEI_GET_POSITION_COUNT QEI_GET_VELOCITY_COUNT The 16 bit value of the position counter or velocity counter 237 CCS C 10082015 Function Availability Requires Examples Example Files Also See Reads the current 16 bit value of the position or velocity counter Devices that have the QE module Nothing value qei get counter QEI GET POSITION COUNT value gei_get_counter value gei_get_ counter QEI GET VELOCITY COUNT None setup qei qei_set_count gei_status qei_status Syntax Parameters Returns Function Availability Requires Examples Example Files Also See qsort Syntax Parameters 238 status qei_status None The status of the QEI module Returns the status of the QEI module Devices that have the QE module Nothing status gei_status None setup qei qei_set_count gei get count qsort base num width compare base Pointer to array of sort data num Number of elements width Width of elements compare Function that compares two elements Returns Function Availab
326. se USB instead of RS232 Voltage Reference These functions configure the votlage reference module These are available only in the supported chips Relevant Functions setup_vref mode value Enables and sets up the internal voltage reference value Constants are defined in the device s h file Relevant Preprocesser none Relevant Interrupts none Relevant Include Files none all functions built in 70 Functional Overview Relevant getenv parameters VREF Returns 1 if the device has VREF Example code for PIC12F675 INT_COMP comparator interrupt handler void isr safe_conditions FALSE printf WARNING Voltage level is above 3 6V r n setup_comparator A1_VR_OUT_ON _A2 sets 2 comparators A1 and VR and A2 as output setup_vref VREF_HIGH 15 sets 3 6 vdd value 32 vdd 4 if vdd is 5 0V enable_interrupts INT_COMP enable the comparator interrupt enable_interrupts GLOBAL enable global interrupts WDT or Watch Dog Timer Different chips provide different options to enable disable or configure the WDT Relevant Functions setup_wdi Enables disables the wat or sets the prescalar restart_wdt Restarts the wat if wdt is enables this must be periodically called to prevent a timeout reset For PCB PCM chips it is enabled disabled using WDT or NOWDT fuses whereas on PCH device it is done using the setup_wdt function The timeout time for PCB PCM chips are set using
327. sed Speed is the input frequency restart_wdt will restart the watchdog timer on every delay_us and delay_ms use clock_out when used with the internal or oscillator types this enables the clockout pin to output the clock fast_start some chips allow the chip to begin execution using an internal clock until the primary clock is stable lock some chips can prevent the oscillator type from being changed at run time by the software USB or USB_FULL for devices with a built in USB peripheral When used with the type speed option the compiler will set the correct configuration bits for the USB peripheral to operate at Full Speed USB_LOW for devices with a built in USB peripheral When used with the type speed option the compiler will set the correct configuration bits for the USB peripheral to operate at Low Speed PLL_WAIT for devices with a PLL and a PLL Ready Status flag to test When a PLL clock is specified it will cause the compiler to poll the ready PLL Ready Flag and only continue program execution when flag indicates that the PLL is ready ACT or ACT type for device with Active Clock Tuning type can be either USB or SOSC If only using ACT type will default to USB ACT USB causes the compiler to enable the active clock tuning and to tune the internal oscillator to the USB clock ACT SOSC causes the compiler to enable the active clock tuning and to tune the internal oscillator to the secondary clock at 32 768 kHz ACT can only be us
328. ses To access these levels assign a value to the fuse For example on the 18F452 the fuse PROTECT 6 would place the value 6 into CONFIGB5L protecting code blocks 0 and 3 When linking multiple compilation units be aware this directive applies to the final object file Later files in the import list may reverse settings in previous files To eliminate all fuses in the output files use FUSES none To manually set the fuses in the output files use FUSES 1 0xC200 sets config word 1 to OxC200 Examples fuses HS NOWDT Example ex_sqw c Files Also See None hexcomment Syntax HEXCOMMENT text comment for the top of the hex file HEXCOMMENT text comment for the end of the hex file Elements None Purpose Puts a comment in the hex file Some programmers MPLAB in particular do not like comments at the top of the hex file Examples HEXCOMMENT Version 3 1 requires 20MHz crystal Example None Files Also See None 91 CCS C 10082015 id Syntax Elements Purpose Examples Example Files Also See FID number 16 FID number number number number HID filename RFID CHECKSUM Number 16 is a 16 bit number number is a 4 bit number filename is any valid PC filename and checksum is a keyword This directive defines the ID word to be programmed into the part This directive does not affect the compilation but the information is put in the output file The first syntax will take a 16 bit number and
329. sk s message queue rtos_msg_read Returns the next byte of data contained in the task s message queue rtos_msg_send task byte Sends a byte of data to the specified task The data is placed in the receiving task s message queue rtos_yield Called with in one of the RTOS tasks and returns control of the program to the rtos_run function All tasks should call this function when finished rtos_signal sem Increments a semaphore which is used to broadcast the availability of a limited resource rtos_wait sem Waits for the resource associated with the semaphore to become available and then decrements to semaphore to claim the resource rtos_await expre Will wait for the given expression to evaluate to true before allowing the task to continue rtos_overrun task Will return true if the given task over ran its alloted time rtos_stats task stat Returns the specified statistic about the specified task The statistics include the minimum and maximum times for the task to run and the total time the task has spent running Relevant Preprocessor USE RTOS options This directive is used to specify several different RTOS attributes including the timer to use the minor cycle time and whether or not statistics should be enabled TASK options This directive tells the compiler that the following function is to be an RTOS task TASK specifies the rate at which the task should be called the maximum time the task shall be allowed to r
330. sor command In no case does this compiler require this directive Examples pragma device PIC16C54 Example ex_cust c Files Also See None priority Syntax PRIORITY ints Elements ints is a list of one or more interrupts separated by commas export makes the functions generated from this directive available to other compilation units within the link Purpose The priority directive may be used to set the interrupt priority The highest priority items are first in the list If an interrupt is active it is never interrupted If two interrupts occur at around the same time then the higher one in this list will be serviced first When linking multiple compilation units be aware only 106 PreProcessor the one in the last compilation unit is used Examples priority rtcc rb Example None Files Also See INT_xxxx profile Syntax profile options Elements options may be one of the following functions Profiles the start end of functions and all profileout messages functions Profiles the start end of functions parameters sent to parameters functions and all profileout messages profileout Only profile profilout messages paths Profiles every branch in the code off Disable all code profiling on Re enables the code profiling that was previously disabled with a profile off command This will use the last options before disabled with the off command Purpose Large programs on the microcontroller may gene
331. stant 16 bit value Purpose This directive specifies the data to be used to fill unused ROM locations When linking multiple compilation units this directive must appear exactly the same in each compilation unit Examples i11_ rom 0x36 Example None Files Also See ROM fuses Syntax FUSES options Elements options vary depending on the device A list of all valid options has been put at the top of each devices h file in a comment for reference The PCW device edit utility can modify a particular devices fuses The PCW pull down menu VIEW Valid fuses will show all fuses with their descriptions Some common options are e LP XT HS RC e WDT NOWDT e PROTECT NOPROTECT e PUT NOPUT Power Up Timer e BROWNOUT NOBROWNOUT Purpose This directive defines what fuses should be set in the part when it is programmed This directive does 90 not affect the compilation however the information is put in the output files If the fuses need to be in Parallax format add a PAR option SWAP has the special function of swapping from the Microchip standard the high and low BYTES of non program data in the Hex file This is required for some device programmers PreProcessor Some fuses are set by the compiler based on other compiler directives For example the oscillator fuses are set up by the USE delay directive The debug No debug and ICSPN Fuses are set by the DEVICE ICD directive Some processors allow different levels for certain fu
332. t endl cout lt lt Price is lt lt setw 4 lt lt setprecision 2 lt lt cost lt lt endl Icdputc lt lt lt lt setw 3 lt lt count lt lt lt lt min lt lt lt lt max string1 lt lt setprecision 1 lt lt sum count string2 lt lt x lt lt lt lt y stream gt gt variable_or_constant_or_manipulator one or more repeats stream may be the name specified in the use RS232 stream option or for the default stream use cin stream may also be the name of a char array In this case the data is read from the array up to the 0 terminator 73 CCS C 10082015 Examples 74 stream may also be the name of a function that returns a single char and has no parameters In this case the function is called for each character to be input Make sure the function returns a r to terminate the input statement variables constants May be any integer char float or fixed type Char arrays are input as strings Floats may use the E format Reading of each item terminates with any character not valid for the type Usually items are separated by spaces The termination character is discarded At the end of any stream input statement characters are read until a return r is read No termination character is read for a single char input manipulators hex Hex format numbers dec Decimal format numbers default noecho Suppress echoing strspace Allow spaces to be input
333. t fifo mode ECAN Can be used to set the filter and mask ID s to the value specified by addr It is also used to set the ID of the message to be sent Returns the ID of a received message Constructs a CAN packet using the given arguments and places it in one of the available transmit buffers Retrieves a received message from one of the CAN buffers and stores the relevant data in the referenced function parameters Enables the automatic response feature which automatically sends a user created packet when a specified ID is received ECAN Disables the automatic response feature ECAN Creates and loads the packet that will automatically transmitted when the triggering ID is received ECAN Enables one of the extra filters included in the ECAN module ECAN Disables one of the extra filters included in the ECAN module ECAN Used to associate a filter to a specific buffer This allows only specific buffers to be filtered and is available in the ECAN module ECAN Used to associate a mask to a specific buffer This allows only specific buffer to have this mask applied This feature is available in the ECAN module ECAN Retrieves the next buffer in the fifo buffer Only available in the ECON module while operating in fifo mode ECAN This interrupt is triggered when an invalid packet is received on the CAN int_canwake int_canerr int_cantx0 int_cantx1 int_cantx2 int_canrx0 int_canrx1 Relevant Include Files can mc
334. t the period is compared against for error calculation Nothing Function Availability Requires Examples Example Files Also See Built in Functions To get the Angular Timer Set Point All devices with an AT module Nothing at_set_set_point set_point None at set resolution at get resolution at set missing pulse delay at get missing pulse delay at get period at get phase counter 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_at at_setup_cc Syntax Parameters Returns Function Availability Requires Examples at_setup_cc which settings which an 8 bit constant specifying which AT Capture Compare to setup can be 1 2 or 3 settings a 16 bit constant specifying how to setup the specified AT Capture Compare module See the device s header file for all options Some of the typical options include AT_CC_ENABLED AT_CC_DISABLED AT_CC_CAPTURE_MODE AT_CC_COMPARE_MODE AT_CAPTURE_FALLING_EDGE AT_CAPTURE_RISING_EDGE Nothing To setup one of the Angular Timer Capture Compare modules to the specified settings All devices with an AT module Constants defined in the device s header file at_setup_cc 1 AT_CC_ENABLED AT CC CAPTURE MODE AT CAPTURE FALLING EDGE AT CAPTURE INPUT ATCAP
335. tandard operators and or preprocessor identifiers Code is any Purpose Examples Example Files Also See error standard c source code The pre processor evaluates the constant expression and if it is non zero will process the lines up to the optional ELSE or the ENDIF Note you may NOT use C variables in the IF Only preprocessor identifiers created via define can be used The preprocessor expression DEFINED id may be used to return 1 if the id is defined and 0 if it is not and operators now accept a constant string as both operands This allows for compile time comparisons and can be used with GETENV when it returns a string result if MAX VALUE gt 255 long value else int value endif if getenv DEVICE PIC16F877 do something special for the PIC16F877 endif ex extee c IFDEF IFNDEF getenv ERROR text Syntax Elements ERROR warning text ERROR information text text is optional and may be any text Purpose Forces the compiler to generate an error at the location this directive appears in the file The text may include macros that will be expanded for the display This may be used to see the macro expansion The command may also be used to alert the user to an invalid compile time situation 87 CCS C 10082015 Examples if BUFFER SIZE gt 16 error Buffer size is too large endif error Macro test min x y Example ex psp c Files Als
336. tax rtos_yield Parameters None Returns None 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 it s 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 printf Executing code after yield r n Also See None 261 CCS C 10082015 set_adc_channel Syntax Parameters Returns Function Availability Requires Examples Example Files Also See set_adc_channel chan neg chan is the channel number to select Channel numbers start at 0 and are labeled in the data sheet ANO 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 undefined 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 channe
337. ted ISR and a global function can replace the compiler generated interrupt dispatcher Relevant Functions disable_interrupts Disables the specified interrupt 51 CCS C 10082015 enable_interrupts ext_int_edge clear_interrupt interrupt_active interrupt_enabled Relevant Preprocessor DEVICE HIGH_INTS INT_XXX fast Relevant Interrupts int_default int_global int_xxx Relevant Include Files none all functions built in Relevant getenv Parameters none Example Code int_timerO void timer0interrupt enable_interrupts TIMERO disable_interrtups TIMERO clear_interrupt TIMERO 52 Enables the specified interrupt Enables the edge on which the edge interrupt should trigger This can be either rising or falling edge This function will clear the specified interrupt flag This can be used if a global isr is used or to prevent an interrupt from being serviced This function checks the interrupt flag of specified interrupt and returns true if flag is set This function checks the interrupt enable flag of the specified interrupt and returns TRUE if set This directive tells the compiler to generate code for high priority interrupts This directive tells the compiler that the specified interrupt should be treated as a high priority interrupt This directive specifies that the following function should be called if an interrupt is triggered but no routine is associated wi
338. ter that determines which ADC pair s ready flag to check If not used all ready flags are checked An int16 If pair is used 1 will be return if ADC is done with conversion O will be return if still busy If pair isn t use it will return a bit map of which conversion are ready to be read For example a return value of 0x0041 means that ADC pair 6 AN12 and AN13 and ADC pair 0 ANO and AN1 are ready to be read Can be polled to determine if the ADC has valid data to be read Only on dsPIC33FUxxGSxxx devices None int16 result 2 setup high speed ade pair 1 INDIVIDUAL SOFTWARE TRIGGER setup_high_speed_adc ADC CLOCK_DIV_4 read high _ speed adc 1 ADC START ONLY while high _ speed _adc done 1 read _ high _ speed adc 1 ADC READ ONLY result printf AN2 value SLX AN3 value LX n r result 0 result 1 None setup high speed adc setup high speed adc pair read high speed adc i2c_init stream baud stream optional parameter specifying the stream defined in USE 12C baud if baud is 0 12C peripheral will be disable If baud is 1 12C peripheral is initialized and enabled with baud rate specified in USE 12C directive If baud is gt 1 then 12C peripheral is initialized and enabled to specified baud rate Returns Function Availability Requires Examples Example Files Also See Built in Functions Nothing To initialize 12C peripheral at run time to specified baud rate A
339. th that interrupt This directive specifies that the following function should be called whenever an interrupt is triggered This function will replace the compiler generated interrupt dispatcher This directive specifies that the following function should be called whenever the xxx interrupt is triggered If the compiler generated interrupt dispatcher is used the compiler will take care of clearing the interrupt flag bits int_timer associates the following function with the interrupt service routine that should be called enables the timer0 interrupt disables the timero0 interrupt clears the timero interrupt flag Functional Overview Low Voltage Detect These functions configure the high low voltage detect module Functions available on the chips that have the low voltage detect hardware Relevant Functions setup_low_volt_detect mode Sets the voltage trigger levels and also the mode below or above in case of the high low voltage detect module The options vary depending on the chip and are listed in the device header files Relevant Preprocessor None Relevant Interrupts INT_LOWVOLT Interrupt fires on low voltage detect Relevant Include Files None all functions built in Relevant getenv parameters None Example Code For PIC18F8722 setup_low_volt_detect E alld sets the trigger level as 3 6 volts and trigger direction as above The interrupt if enabled is fired when the voltage is
340. the ROM address is inside the program memory space the directive creates a segment for the data resulting in an error if a ORG is over the same area The ROM data will also be counted as used program memory space The type option indicates the type of each item the default is 16 bits Using char as the type treats each item as 7 bits packing 2 chars into every pcm 14 bit word When linking multiple compilation units be aware this directive applies to the final object file Some special forms of this directive may be used for verifying program memory ROM address checksum This will put a value at address such that the entire program memory will sum to 0x1248 FROM address crc16 This will put a value at address that is a crc16 of all the program memory except the specified address PreProcessor ROM address crc8 This will put a value at address that is a crc16 of all the program memory except the specified address Examples rom getnev EEPROM ADDRESS 1 2 3 4 5 6 7 8 From ints 0Ox1000 e 00s 2010 Example None Files Also See ORG separate Syntax SEPARATE 0000 Elements None Purpose Tells the compiler that the procedure IMMEDIATELY following the directive is to be implemented SEPARATELY This is useful to prevent the compiler from automatically making a procedure INLINE This will save ROM space but it does use more stack space The compiler will make all procedures marked SEPARATE separate
341. the device has an ADV UART Returns a 1 if the device has CCP number x Returns a 1 if the device has TIMER number x Smallest number of bytes that can be written to FLASH Smallest number of bytes that can be erased in FLASH Returns the number of bytes at an address location Returns the size of an instruction in bits Returns the number of RAM bytes available for your device Returns the address of the specified special file register The output format can be used with the preprocessor command bit name must match SFR denomination of your target PIC example STATUS INTCON TXREG RCREG etc Returns the bit address of the specified special file register bit The output format will be in address bit which can be used with the preprocessor command byte name must match SFR bit denomination of your target PIC example C Z GIE TMROIF etc Returns TRUE if the specified special file register name is valid and exists for your target PIC example getenv SFR_VALID INTCON 185 CCS C 10082015 Availability 186 BIT_VALID name Returns TRUE if the specified special file register bit is valid and exists for your target PIC example getenv BIT_VALID TMROIF UARTx_RX Returns UARTxPin like PINxC7 SPIx_DI Returns SPIxDI Pin SPIxCLK Returns SPIxCLK Pin QEI Returns 1 if device has QEI DSP Returns 1 if device supports DSP instructions DMA Returns 1 if device supports DMA Returns 1 if device has a CWG mod
342. the pin is not high at the end of the bit time Used to cause the compiler to keep receive errors in the variable RS232_ERRORS and to reset errors when they occur A getc normally samples data in the middle of a bit time This option causes the sample to be at the start of a bit time May not be used with the UART For FLOAT_HIGH and MULTI_MASTER this is the pin used to read the signal back The default for FLOAT_HIGH is the XMIT pin and for MULTI_MASTER the RCV pin Uses the RETURN pin to determine if another master on the bus is transmitting at the same time If a collision is detected bit 6 is set in RS232_ERRORS and all future PUTC s are ignored until bit 6 is cleared The signal is checked at the start and end of a bit time May not be used with the UART Makes getc return an int16 and putc accept an int16 This is for 9 bit data formats Will cause interrupts to be disabled when the routines get or put a character This prevents character distortion for software implemented l O and prevents interaction between I O in interrupt handlers and the main program when using the UART To set the number of stop bits default is 1 This works for both UART and non UART ports 121 CCS C 10082015 TIMEOUT X To set the time getc waits for a byte in milliseconds If no character comes in within this time the RS232_ERRORS is set to 0 as well as the return value form getc This works for both UART and non UART ports SYNC_SL
343. tics file shows the RAM ROM and STACK usage It provides information on the source codes structural and textual complexities using Halstead and McCabe metrics 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 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 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 This is a binary file containing debug information The output of the Documentation Generator is exported in a Rich Text File format which can be viewed using the RTF editor or Wordpad The Rich View Format is used by the RTF Editor within the IDE to view the Rich Text File The DGR file is the output of the flowchart maker 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 Relocatable object file 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
344. timer_ccpX get_timer_ccpX get_capture_ccpX get_captures32_ccpX set_pwm1_offset set_pwm2_offset set_pwm3_offset set_pwm4_offset set_pwmb5_offset set_pwm6_offset Syntax Parameters Returns Function Availability Requires 276 set_pwm1_offset value set_pwm2_offset value set_pwm3_offset value set_pwm4_offset value set_pwm5_ offset value set_pwm6_ offset value value 16 bit constant or variable undefined Writes the 16 bit to the PWM to set the offset The offset is used to adjust the waveform of aslae PWM module relative to the waveform of a master PWM module Devices with a 16 bit PWM module Nothing Examples Example Files Also See Built in Functions set_pwml_offset 0x0100 set_pwml_offset offset 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 Parameters Returns Function Availability Requires Examples Example Files Also See set_pwm1_period value set_pwm2_period value set_pwm3_period value set_pwm4_period value set_pwm5_period value set_pwm6_period value value 16 bit constant or variable undefined Writes the 16 bit to the PWM to set the period When t
345. tions may be PSMC_SOURCE_IS_PHASE PSMC_SOURCE_IS_ PERIOD PSMC_DISCONNECT The following may be OR ed with the above PSMC_INVERT_DUTY PSMC_INVET_PERIOD undefined This function allows one PSMC unit the slave to be synchronized the outputs with another PSMC unit the master All devices equipped with PSMC module None Also See Built in Functions setup psmc psmc_deadband psmc_sync psmc_modulation psmc_shutdown psmc_duty psmc freq adjust psmc_pins psp_output_full psp_input_full psp _overflow Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result psp_output_full result psp_input_full result psp_overflow result psp_error EPMP only result psp_timeout EPMP only None A 0 FALSE or 1 TRUE These functions check the Parallel Slave Port PSP for the indicated conditions and return TRUE or FALSE This function is only available on devices with PSP hardware on chips Nothing while psp output _full psp_data command while psp input _full if psp_overflow error TRUE else data psp data ex_psp c setup psp PSP Overview putc_send fputc_send Syntax Parameters Returns putc_send fputc_send stream stream parameter specifying the stream defined in USE RS232 Nothing 233 CCS C 10082015 Functio
346. tions may be used for advanced settings and to dynamically change the signal All devices equipped with PSMC module None Simple PWM 10khz out on pin CO assuming a 20mhz crystal Duty is initially set to 25 setup _psmc 1 PSMC_SINGLE PSMC_EVENT TIME PSMC_SOURCE_FOSC us 100 PSMC_EVENT TIME 0 PSMC_EVENT TIME us 25 psmc_pins 1 PSMC_A None psmc deadband psmc_sync psmc_blanking psmc_modulation psmc_shutdown psmc _duty psmc _ freq adjust psmc_pins setup _power_pwm Syntax Parameters setup_power_pwm modes postscale time_base period compare compare_postscale dead_time modes values may be up to one from each group of the following 309 CCS C 10082015 Returns Function Availability Requires Examples Example Files Also See 310 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 t
347. 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 Nothing 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 Also See write bank and the Common Questions and Answers section for more information read_calibration Syntax value read_calibration n Parameters nis an offset into calibration memory beginning at 0 242 Returns Function Availability Requires Examples Example Files Also See Built in Functions An 8 bit byte The read_calibration function reads location n of the 14000 calibration memory This function is only available on the PIC14000 Nothing fin read_calibration 16 ex 14kad c with 14kcal c None read_configuration_memory Syntax Parameters Returns Function Availability Requires Examples Example Files Also See read_configuration_memory offset ramPtr n ramPtris the destination pointer for the read results count is an 8 bit integer offset is an optional parameter specifying the offset into configuration memory to start reading fr
348. to the RTCC module as specified in the structure date time Devices that have the RTCC module Nothing rtc_write amp datetime CXehiGerG Also See rtos await Built in Functions rtc_read rtc_ alarm read rtc _ alarm write setup rtc_alarm rtc_write setup rtc The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires Examples Also See rtos_await expre expre is a logical expression None 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 All devices USE RTOS rtos_await kbhit None rtos_disable The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax Parameters Returns Function Availability Requires rtos_disable task task is the identifier of a function that is being used as an RTOS task None This function disables a task which causes the task to not execute until enabled by rtos_enable All tasks are enabled by default All devices USE RTOS 255 CCS C 10082015 Examples rtos disable toggle green Also See rtos enable rtos_enable The RTOS is only included in the PCW PCWH and PCWHD software packages Syntax
349. to the threshold setting Availability All devices with an AT module 148 Requires Examples Example Files Also See Built in Functions Nothing result at get set point error None 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 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_at at_get_status Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result at_get_status None An 8 bit integer The possible results are defined in the device s header file as AT_STATUS_PERIOD_AND_PHASE_VALID AT_STATUS_PERIOD_LESS_THEN_PREVIOUS To get the status of the Angular Timer module All devices with an AT module Nothing if at_get_status amp AT STATUS PERIOD AND PHASE VALID AT STATUS PERIOD AND PHASE VALID Period at_get_period Phase at_get_phase None 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_inter
350. tup spi setup Spi2 J iii ra aaa aa 316 setup UMErlA Jimdo idad dial cdi testes adi 316 IO A O A O aA e EE EEEE EAEE 317 set p timer O A AT 318 SOUP UA ii a ae eS 318 Setup vret eoa e occ E anaes Sikes DUQUE decanta caterers 319 AN A cot es RAE 319 SOLUP ZOC O 320 Shift a IE 320 A is Foes E E eae be darned hace SG EP hs Eel ct teed 321 A secertoes E techies ees hee vate eters vs creased cabal sc ee cave A A ands A beaut avian Dieses ciety soecbee ee cade 322 SISOP UIP WU Ted E sasuashaceseencssaducsslessscetasscadcasedane paaasdeasaesaashancasaaaaataneticntagtasctas 322 smi read J sith vst ral ie cen eee aie evened oi ae ae ed av ete heeded 324 SMDC TESOL Mer uan in Id wane due geese eee SAR daw ee 324 LAON D GESA fE LA O Ea E E E E a es Pe ee 325 SMDESTatus lt il ll tau a r a tdo a a 325 SMDESIO P iii iran ei caditia 325 A O AA 326 SMDC UPAAtS Jintao ria 326 spi data Isin Spl data ISO ico cade Cda 327 Spb AMIE EEE ii ollas 327 spI_prowrite data ius id cheek eel dh ce sg Le ee ee ee ee 328 Spl read Splread2 it ien een eis ies ee ee ie ee 328 spi_read_16 spi_read2_16 spi_read3_16 spi_read4_16 ooocononcccinonccccnoncncnonencncnnnannnnnnno cnn nro cnn nana nnnnn nono 329 A EEA A NE 330 SIS A zirenian aa a e i aaa a aa aa E aeaa E A desk EA aa e A EE aE aE EE E ana SE 330 T1 O E a E E E E AE ee eee A 331 ST EDA a e m a IN Oo cia E A O EA T be eae E ET ee 332 AT stokes E E A E E NT 332 SOM S P E A E E
351. tus Syntax Parameters Returns Function Availability Examples Example Files Also See 350 value zcd_status None value the status of the ZCD module The following defines are made in the device s header file and are as follows ZCD_IS_SINKING ZCD_IS_SOURCING To determine if the Zero Cross Detection ZCD module is currently sinking or sourcing current Ifthe ZCD module is setup to have the output polarity inverted the value return will be reversed All devices with a ZCD module valle ze ds tatus 0 None setup zcd STANDARD C INCLUDE FILES errno h errno h EDOM Domain error value ERANGE Range error value errno error value float h float h FLT_RADIX Radix of the exponent representation FLT_MANT_DIG Number of base digits in the floating point significant FLT_DIG Number of decimal digits q such that any floating point number with q decimal digits can be rounded into a floating point number with p radix b digits and back again without change to the q decimal digits FLT_MIN_EXP Minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized floating point number FLT_MIN_10_EXP Minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers FLT_MAX_EXP Maximum negative integer such that FLT_RADIX raised to that power minus 1 is a representable finite floating point number FLT_MAX_10_EXP Max
352. two forms or to a specified function Formatting is in accordance with the string argument When variables are used this string must be a constant The character is used within the string to indicate a variable value is to be formatted and output Longs in the printf may be 16 or 32 bit A will output a single Formatting rules for the follows See the Expressions gt Constants and Trigraph sections of this manual for other escape character that may be part of the string If fprintf is used then the specified stream is used where printf defaults to STDOUT the last USE RS232 Format The format takes the generic form nt n is optional and may be 1 9 to specify how many characters are to be outputted or 01 09 to indicate leading zeros or 1 1 to 9 9 for floating point and w output t is the type and may be one of the following c Character s String or character u Unsigned int d Signed int Lu Long unsigned int Ld Long signed int x Hex int lower case X Hex int upper case 223 CCS C 10082015 Lx Hex long int lower case LX Hex long int upper case Float with truncated decimal Float with rounded decimal Float in exponential format Unsigned int with decimal place inserted Specify two numbers for n The first is a total field width The second is the desired number of decimal places soo Example formats Specifier Value 0x12 Value Oxfe 03u 018 254 u 18 254 2u 18 5 18 254 d 18 2
353. ule Returns 1 if device has a CLC module Returns 1 if device has op amps CAP_SENSE Returns 1 if device has a CSM cap sense module and 2 if it has a CTMU module INSTRUCTION_CLOCK Returns the MPU instruction clock All devices Built in Functions Requires Nothing Examples IF getenv VERSION lt 3 050 ERROR Compiler version too old ENDIF for i 0 i lt getenv DATA EEPROM i write eeprom i 0 IF getenv FUSE VALID BROWNOUT HFUSE BROWNOUT ENDIF byte status _reg GETENV SFR STATUS bit carry flag GETENV BIT C Example Files None Also See None goto_address Syntax goto_address ocation Parameters location is a ROM address 16 or 32 bit int Returns Nothing Function This function jumps to the address specified by location Jumps outside of the current function should be done only with great caution This is not a normally used function except in very special situations Availability All devices Requires Nothing Examples define LOAD REQUEST PIN _B1 define LOADER 0x1f00 if input LOAD REQUEST goto_address LOADER Example Files setimp h 187 CCS C 10082015 Also See label_address high_speed_adc_done Syntax Parameters Returns Function Availability Requires Examples Example Files Also See i2c_init Syntax Parameters 188 value high_speed_adc_done pair pair Optional parame
354. un and how large it s queue should be Relevant Interrupts none Relevant Include Files none all functions are built in Relevant getenv Parameters none Example Code USE RTOS will use timer zero minor cycle will be 20ms RTOS timer 0 minor_cycle 20ms int sem TASK rate 1s max 20ms queue 5 Task will run at a rate of once per second 61 CCS C 10082015 void task_name rtos_run rtos_terminate rtos_enable task_name rtos_disable task_name rtos_msg_send task_name 5 rtos_yield rtos_sigal sem with a maximum running time of 20ms and a 5 byte queue begins the RTOS ends the RTOS enables the previously declared task disables the previously declared task places the value 5 in task_names queue yields control to the RTOS signals that the resource represented by sem is available For more information on the CCS RTOS please SPI SPI is a fluid standard for 3 or 4 wire full duplex communications named by Motorola Most PIC devices support most common SPI modes CCS provides a support library for taking advantage of both hardware and software based SPI functionality For software support see USE SPI Relevant Functions setup_spi mode setup_spi2 mode setup_spi3 mode setup_spi4 mode Configure the hardware SPI to the specified mode The mode configures setup_spi2 mode thing such as master or slave mode clock speed and clock data trig
355. unctions All devices INCLUDE lt stdlib h gt char string 10 float x strcpy string 123 456 x atof string x is now 123 456 ex tank c atoi atol atoi32 printf pin_select Syntax Parameters Returns Availability Requires Examples pin_select peripheral_pin pin unlock lock peripheral_pin a constant string specifying which peripheral pin to map the specified pin to Refer to pin_select for all available strings Using NULL for the peripheral_pin parameter will unassign the output peripheral pin that is currently assigned to the pin passed for the pin parameter pin the pin to map to the specified peripheral pin Refer to device s header file for pin defines If the peripheral_pin parameter is an input passing FALSE for the pin parameter will unassign the pin that is currently assigned to that peripheral pin unlock optional parameter specifying whether to perform an unlock sequence before writing the RPINRx or RPORx register register determined by peripheral_pin and pin options Default is TRUE if not specified The unlock sequence must be performed to allow writes to the RPINRx and RPORx registers This option allows calling pin_select multiple times without performing an unlock sequence each time lock optional parameter specifying whether to perform a lock sequence after writing the RPINRx or RPORx registers Default is TRUE if not specified Alth
356. underscore _ Purpose This directive tells the compiler to setup an input capture on the specified pin using the specified settings The USE DELAY directive must appear before this directive can be used This directive enables use of built in functions such as get_capture_time and get_capture_event Examples USE CAPTURE INPUT PIN_C2 CAPTURE_RISING TIMER 1 FASTEST Example None Files Also See get capture time get capture event use delay Syntax USE DELAY options Elements Options may be any of the following separated by commas clock speed speed is a constant 1 100000000 1 hz to 100 mhz This number can contains commas This number also supports the following denominations M MHZ K KHZ This specifies the clock the CPU runs at Depending on the PIC this is 2 or 4 times the instruction rate This directive is not needed if the following type speed is used and there is no frequency multiplication or division type speed type defines what kind of clock you are using and the following values are valid oscillator osc same as oscillator crystal xtal same as crystal internal int same as internal or rc The compiler will automatically set the oscillator configuration bits based upon your defined type If you specified internal the compiler will also automatically set the internal oscillator to the defined 115 CCS C 10082015 Also See speed Configuration fuses are modified when this option is u
357. up hspwm setup hspwm_ secondary set_hspwm_phase Syntax Parameters Returns Function Availability Requires Examples Example Files Also See set_hspwm_phase unit primary secondary 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 undefined Sets up the specified High Speed PWM unit Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices Constants are defined in the device s h file set_hspwm 1 0x1000 0x8000 None 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 271 CCS C 10082015 set_nco_inc_value Syntax Parame ters Returns Functio n Availabi lity Exampl es Exampl e Files Also See set_nco_inc_value value value value to set the NCO increment registers Undefined Sets the value that the NCO s accumulator will be incremented by on each clock pulse The increment reg
358. up_hspwm_chop_clock settings 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 Undefined Setup and High Speed PWM Chop Clock Generator and divisor Only on devices with a built in High Speed PWM module dsPIC33FJUxxGSxxx dsPIC33EPxxxMUxxx dsPIC33EPxxxMCxxx and dsPIC33EVxxxGMxxx devices None setup_hspwm_chop_clock HSPWM CHOP _CLK_GENERATOR_ENABLED 32 None 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 Built in Functions setup hspwm_trigger Syntax Parameters Returns Function Availability Requires Examples Example Files Also See setup_hspwm_trigger unit start_ delay divider trigger_value strigger_value 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_APPL
359. urn the current count and the function set_ticks can be used to set count to a specific starting value or to clear counter This directive creates a tick timer using one of the PIC s timers The tick timer is initialized to zero at program start This directive also creates the define TICKS_PER_SECOND as a floating point number which specifies that number of ticks that will occur in one second USE TIMER TIMER 1 TICK 1ms BITS 16 NOISR unsigned intl6 tick difference unsigned int16 current unsigned intl6 previous return current previous void main void unsigned int16 current_tick previous tick Currant cick previous cle qee _traleles 1 7 while TRUE GwueicSine ciol qu ticker a feels CHin rersnee levr rene elk jEENIOUS tells gt 1000 i output _toggle PIN_B0 Prev lousst1ck current tick None get_ticks set_ticks use touchpad Syntax Elements USE TOUCHPAD options RANGE x Sets the oscillator charge discharge current range If x is L current is nominally 0 1 microamps If x is M current is nominally 1 2 microamps If x is H current is nominally 18 microamps Default value is H 18 microamps THRESHOLD x x is a number between 1 100 and represents the percent reduction in the nominal frequency that will generate a valid key press in software Default value is 6 SCANTIME xxMS xx is the number of milliseconds used by the microprocessor to scan for one key press I
360. ut TOUCHPAD_GETC None char returns corresponding ASCII number is input declared as int 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 pre declared 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 All PIC s with a CSM or CTMU Module USE TOUCHPAD options When the pad connected to PIN BO is activated store the letter A USE TOUCHPAD PIN _BO A void main void char c enable interrupts GLOBAL Example Files Also See Built in Functions c TOUCHPAD GETC will wait until one of declared pins is detected if PIN BO is pressed c will get value A None USE TOUCHPAD touchpad _state touchpad_hit Syntax Parameters Returns Function Availability Requires Examples Example Files Also See value TOUCHPAD_HIT None TRUE or FALSE 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 All PIC s with a CSM or CTMU Module USE TOUCHPAD options When the pad connected to PIN BO is activated store the letter A USE TOUCHPAD PIN BO A void main void cha
361. utput_high pin output_low pin output_float pin output_x value output_bit pin value input pin input_state pin set_tris_x value input_change_x Relevant Preprocessor USE STANDARD_l0O port USE FAST_IO port USE FIXED_lO port_outputs in pin Relevant Interrupts Relevant Include Files None all functions built in Relevant getenv parameters PIN pb Example Code use fast_io b Int8 Tris value 0x0F intl Pin value Sets the given pin to high state Sets the given pin to the ground state Sets the specified pin to the input mode This will allow the pin to float high to represent a high on an open collector type of connection Outputs an entire byte to the port Outputs the specified value 0 1 to the specified I O pin The function returns the state of the indicated pin This function reads the level of a pin without changing the direction of the pin as INPUT does Sets the value of the I O port direction register A 1 is an input and 0 is for output This function reads the levels of the pins on the port and compares them to the last time they were read to see if there was a change 1 if there was 0 if there wasn t This compiler will use this directive be default and it will automatically inserts code for the direction register whenever an I O function like output_high or input is used This directive will configure the I O port to use the fast method of performin
362. value or set_rtcc value set_timer1 value set_timer2 value set_timer3 value set_timer4 value set_timer5 value Timers 1 amp 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 undefined Sets the count value of a real time clock counter RTCC and Timero0 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 O 1 2 Timer 0 All devices Timers 1 amp 2 Most but not all PCM devices Timer 3 Only PIC18XXX and some pick devices Timer 4 Some PCH devices Timer 5 Only PIC18XX31 Nothing 20 mhz clock no prescaler set timer 0 to overflow in 35us set_timer0 81 256 000035 4 20000000 ex patg c 279 CCS C 10082015 Also See set_ticks Syntax Parameters Returns Function Availability Requires Examples Example Files Also See set_timer1 get timerX TimerO Overview Timer1 Overview Timer2 Overview Timer5 Overview set_ticks stream value 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 void Sets the new value of the tick timer Size passed depends on the size of the tick timer All devices USE TIME
363. var 1 lt lt bit Availability Requires Examples Example Files Also See bit_test Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions All devices Nothing int x x 5 bit _set x 3 x is now 13 ex_patg c bit_clear bit_test value bit_test var bit var may be a 8 16 or 32 bit variable any lvalue bit is a number 0 31 representing a bit number 0 is the least significant bit 0or1 Tests the specified bit 0 7 0 15 or 0 31 in the given variable The least significant bit is 0 This function is much more efficient than but otherwise similar to var 8 1 lt lt bit 0 All devices Nothing if bit _test x 3 bit_test x 1 either bit 3 is 1 or bit 1 is 0 if data 0 for i 31 bit_test data i i i now has the most significant bit in data that is set toa 1 ex_patg c bit_clear bit_set 155 CCS C 10082015 brownout_enable Syntax brownout_enable value Parameters value TRUE or FALSE Returns undefined Function Enable or disable the software controlled brownout Brownout will cause the PIC to reset if the power voltage goes below a specific set point Availability This function is only available on PICs with a software controlled brownout This may also require a specific configuration bit fuse to be set for the brownout to be s
364. vices with more then 30K of RAM Nothing unsigned int8 data 8 read extended ram 1 0x0000 data 8 None Also See read_program_memory Syntax Parameters Returns Function Availability Requires Examples Example Files Also See Built in Functions read extended ram Extended RAM Overview read_external_memory READ_PROGRAM_MEMORY address dataptr count READ_EXTERNAL_MEMORY address dataptr count address is 16 bits on PCM parts and 32 bits on PCH parts 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 and 16 bit for PIC18 undefined Reads count bytes from program memory at address to RAM at dataptr B oth of these functions operate exactly the same Only devices that allow reads from program memory Nothing char buffer 64 read external memory 0x40000 buffer 64 None write program memory External memory overview Program Eeprom Overview read_high_speed_adc Syntax Parameters 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 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 p
365. voltage are Vss and Vdd undefined 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 setup adc read _adc set adc_channel ADC Overview setup_adc_reference Syntax Parameters Returns Function Availability 286 setup_adc_reference reference 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 undefined To set the positive and negative voltage reference for the Analog to Digital Converter ADC uses Only on devices with an ADC and has ANSELx x being the port letter registers for setting which pins are analog or digital Built in Functions Requires Nothing Examples set_adc_reference VSS_VREF Example Files Also See 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
366. when i2c_isr_state returns 0x80 stream specify the stream defined in USE 12C data 8 bit int Function Availability Requires Examples Example Files Also See Built in Functions Reads a byte over the 12C 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 i2c_poll to prevent a lockup Use restart_wdt in the USE 12C to strobe the watch dog timer in the slave mode while waiting All devices USE 12C i2c_start i2c_write 0xal datal i2c_read TRUE data2 i2c_read FALSE i2c_stop ex extee c with 2416 c i2c poll i2c speed i2c start i2c stop i2c slaveaddr i2c isr state i2c write USE 12C 12C Overview i2c_slaveaddr Syntax Parameters Returns Function Availability Requires Examples Example Files Also See 12C_SlaveAddr addr 12C_SlaveAddr stream addr addr 8 bit device address stream optional specifies the stream used in USE 12C Nothing This functions sets the address for the 12C interface in slave mode Devices with built in 12C USE 12C i2c_SlaveAddr 0x08 i2c _SlaveAddr i2cStreaml 0x08 ex_slave c i2c poll i2c_speed i2c_ start i2c stop i2c isr state i2c_write i2c read USE 12C 12C Overview 191 CCS C 10082015 i2c_speed Syntax Parameters Returns Function Availability
367. xxxx HIGH High priority interrupt Compiler saves restores key registers This interrupt will interrupt any normal interrupt in progress INT_xxxx NOCLEAR The compiler will not clear the interrupt The user code in the function should call clear_interrput to clear the interrupt in this case INT_GLOBAL Compiler generates no interrupt code User function is located at address 8 for user interrupt handling Some interrupts shown in the devices header file are only for the enable disable interrupts For example INT_RB3 may be used in enable interrupts to enable pin B3 However the interrupt handler is INT_RB Similarly INT_EXT_L2H sets the interrupt edge to falling and the handler is INT_EXT int_ad adc_handler adc_active FALSE inet cn o clear Asie il See ex _sisr c and ex_stwt c for full example programs enable _interrupts disable interrupts INT DEFAULT INT GLOBAL PRIORITY 97 CCS C 10082015 INT_DEFAULT Syntax INT_DEFAULT Elements None Purpose The following function will be called if the PIC triggers an interrupt and none of the interrupt flags are set If an interrupt is flagged but is not the one triggered the INT_DEFAULT function will get called Examples int_default decawiitk isr O Al printf Unexplained interruptirin Example None Files Also See FINT 00 INT global int_global Syntax INT_GLOBAL Elements None Purpose This directive cause
368. y pll_locked Syntax Parameters Returns Function Availability Requires Examples Example Files Also See result pll_locked None A short int TRUE if the PLL is locked ready FALSE if PLL is not locked ready This function allows testing the PLL Ready Flag bit to determined if the PLL is stable and running Devices with a Phase Locked Loop PLL Not all devices have a PLL Ready Flag for those devices the pll_locked function will always return TRUE Nothing while pll_locked None use delay port_x_pullups Syntax port_a_pullups value port_b _pullups value 221 CCS C 10082015 Parameters Returns Function Availability Requires Examples Example Files Also See port_d_pullups value port_e_pullups value port_j_pullups va ue port_x_pullups upmask port_x_pullups upmask downmask value is TRUE or FALSE on most parts some parts that allow pullups to be specified on individual pins permit an 8 bit int here one bit for each port pin upmask for ports that permit pullups to be specified on a pin basis This mask indicates what pins should have pullups activated A 1 indicates the pullups is on downmask for ports that permit pulldowns to be specified on a pin basis This mask indicates what pins should have pulldowns activated A 1 indicates the pulldowns is on undefined Sets the input pullups TRUE will activate and a FALSE wi
369. y it is 8 bits on the PIC In order to help with code compatibility a TYPE directive may be used to allow these types to be changed TYPE can redefine these keywords Note that the commas are optional Since TYPE may render some sizes inaccessible like a one bit int in the above four keywords representing the four ints may always be used INT1 INT8 INT16 and INT32 Be warned CCS example programs and include files may not work right if you use TYPE in your program This directive may also be used to change the default RAM area used for variable storage This is done by specifying default area where area is a addressmod address space When linking multiple compilation units be aware this directive only applies to the current compilation unit The TYPE directive allows the keywords UNSIGNED and SIGNED to set the default data type TYPE SHOR IN TONES 2 TYPE default area addressmod user ram block 0x100 0x1FF type default user_ram block all variable declarations in this area will be in 0x100 0x1FF PreProcessor type default restores memory allocation back to normal TYPE SIGNED void main int variablel variablel can only take values from 128 to 127 Example ex_cust c Files Also See None undef Syntax UNDEF id Elements id is a pre processor id defined via DEFINE Purpose The specified pre processor ID will no longer have meaning to the pre processor Examples
370. yte at offset from var Same as i8 var gt gt offset 8 amp Oxff except it is done with a single byte move All devices Nothing int32 x int y y make8 x 3 Gets MSB of x Example Files Also See make16 Syntax Parameters Returns Function Availability Requires Examples Example Files Also See make32 Syntax Parameters Returns Function Availability Requires Built in Functions None make16 make32 116 MAKE16 varhigh varlow varhigh and varlow are 8 bit integers A 16 bit integer Makes a 16 bit number out of two 8 bit numbers If either parameter is 16 or 32 bits only the Isb is used Same as 16 int16 varhigh amp Oxff 0x100 varlow amp Oxff except it is done with two byte moves All devices Nothing long x int Ni Ley x makel6 hi lo ltc1298 c make8 make32 132 MAKE32 var1 var2 var3 vard var1 4 are a 8 or 16 bit integers var2 4 are optional A 32 bit integer Makes a 32 bit number out of any combination of 8 and 16 bit numbers Note that the number of parameters may be 1 to 4 The msb is first If the total bits provided is less than 32 then zeros are added at the msb All devices Nothing 207 CCS C 10082015 Examples Example Files Also See malloc Syntax Parameters Returns Function Availability Requires Examples Example Files Als

Download Pdf Manuals

image

Related Search

Related Contents

télécharger PDF  MC235.09 - QEM srl  Portable SPeakerS  RESELLER ASSORTMENT DECISION CRITERIA, Jerker Nilsson  Dealer`s Manual  Actiontec ECB3500T Multi-band MoCA Network Adapter Datasheet  Brava User Manual - Dual-Sim  平成27年度 神戸市グリーン調達等方針に係る判断基準  Translite Users Manual  DT9837 Series User`s Manual  

Copyright © All rights reserved.
Failed to retrieve file