CCS News RSS

Utilizing the new Signal Measurement Timer (SMT) PIC® MCU peripheral with the CCS C Compiler

Tuesday 06 December, 2016

The Signal Measurement Timer (SMT) is a powerful new timing peripheral found on several of the newer PIC® MCU devices, such as the PIC16F18877 and PIC18F67K40 families. Each SMT is a 24bit timer that can operate in one of several modes:

* Timer - A simple 24bit timer, similar to the Timer0 or Timer1 peripheral.

* Gated Timer - Like timer mode above, but only increments when the signal GPIO signal is high.

* Period and duty cycle measurement - Like gated timer, increments a counter when the signal GPIO signal is high. But when the signal GPIO goes low, the timer value is stored for future use and the counter is reset back to 0.

* High and low measurement - Similar to Period and duty cycle mode above, but resets and stores on every signal edge.

* Window Measurement - akin to period and duty cycle measurement above, but measures time between two rising edge signals on the window GPIO pin.

* Gated window measurement - Like window measurement above, but time only increments when the signal GPIO pin is high.

* Time of flight - Similar to window measurement, but timing starts when the window GPIO pin goes high and the timer is stored and reset to 0 when the window GPIO pin or signal GPIO pin goes high.

* 24bit capture - Simply stores the timer value when the window GPIO pin changes state.

* 24bit counter - Counts all the rising edges of the signal GPIO pin.

* Gated counter - Comparable to the 24bit counter mode, but only increments when the window GPIO pin is high.

* Windows counter - Like the gated counter mode, but a rising edge of the window GPIO pin will store the existing timer counter and then reset it to 0.

The CCS C Compiler has been updated to add a library that allows for controlling, configuring and using the SMT in your PICmicro C projects. The functions that have been added are setup_smtX() (or setup_smt1() to setup the first SMT peripheral), smtX_status(), smtX_start(), smtX_stop(), smtX_update(), smtX_reset_timer(), smtX_read() and smtX_write(). For more help, refer to the CCS C Compiler Help file for documentation.

Here is an example of using the Timer mode to blink an LED at a 1Hz rate:

#define LED_PIN PIN_B4
#define SMT_PERIOD (getenv("CLOCK") - 1)

#INT_SMT1
void my_smt_isr(void)
{
output_toggle(LED_PIN);
}

void my_smt_init(void)
{
setup_smt1(SMT_ENABLED | SMT_MODE_TIMER | SMT_CLK_FOSC, SMT_PERIOD);
smt1_start();

enable_interrupts(INT_SMT1);
enable_interrupts(GLOBAL);
}

The CCS C Compiler also provides 2 full example programs showing how to use the SMT, which can be found in the examples directory of the CCS C Compiler. First ex_smt_timer.c which is an example of using the SMT peripheral in Timer mode to toggle an I/O pin, and second ex_smt_period_duty.c which is an example of using the SMT peripheral in Period and Duty Cycle Acquisition mode to determine the period and duty cycle of an input signal.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Capture Event Timers with the CCS C Compiler

Tuesday 06 December, 2016

The Capture Compare (CCP) peripheral of the PIC16 and PIC18 PIC® MCUs and the Input Capture (IC) peripheral of the dsPIC and PIC24 PIC® MCUs allow the MCU to capture and hold a timer value when a specific input pin reaches a user defined state. This peripheral is useful for measuring the duration between events, or determining the frequency or duty cycle of an incoming signal. This peripheral operates independent of the MCU operation, meaning it can trap the timer on the input signal without the developer having to block code execution waiting for the input signal to happen.

Version 5 of the CCS C Compiler has added a #use capture() library that makes it easy to use the CCP or IC peripheral. The API for this library provides an easy to use method for using and configuring the peripheral and timers, while also being portable from one PIC® MCU device to another. Here is an example of its use:

#use capture(CCP1, input=PIN_C2, capture_rising, stream=CAPTURE1)

unsigned int16 WaitForEvent(void)
{
while(!get_capture_event(CAPTURE1));
return(get_capture_time(CAPTURE1));
}

#use capture() configures a CCP or IC peripheral for use, and by using the STREAM option several peripherals can be configured with several instances of #use capture(). #use capture() also provides a method of configuring the timer peripheral to use and the tick rate of the timer. Several other configuration options exist, see the compiler help manual for documentation.

get_capture_event() returns TRUE if the CCP or IC peripheral has trapped an event that can be read, and get_capture_time() returns the time the event happened.

The CCS C Compiler provides an example of using this library, ex_use_caputure.c which can be found in the examples directory of the CCS C Compiler. This example can be used on any PCM, PCH or PCD version 5 CCS C Compiler.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

NEW! ICD-U80 Programmer/Debugger

Friday 14 October, 2016

ICD-U80
Sku: 53506-1648
Price: $119

Introducing the new ICD-U80 Programmer/Debugger from CCS. The advantages of the ICD-U80 include:
  • Accelerated programming speed
  • Integrated Vdd generator to supply 1.5-5.5V to target
  • Software controlled power to target - no jumpers to change

Check out the complete line of CCS Programmer/Debuggers to fit your needs. http://www.ccsinfo.com/programmers-debuggers.php


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Add Non-Volatile Storage to Any PIC® MCU with the virtual EEPROM driver

Tuesday 07 June, 2016

Looking to store settings or data in your embedded project, but you are using a PIC® MCU without an internal EEPROM and your design doesn't have an external EEPROM? The virtual EEPROM driver included in the CCS C Compiler adds the ability to use the PIC® MCU's re-programmable flash memory as data storage. This driver also performs write balancing, which allows the developer to write to a specific location several times without fear of wearing out the endurance of the flash memory. The virtual EEPROM driver recently was updated to add support for PIC16 and to optimize the memory usage when used on 8-bit PIC® MCUs (PIC16, PIC18, etc).

To add this library into your project, simply #include the file virtual_eeprom.c. The function init_virtual_eeprom() needs to be called to initialize access to the virtual EEPROM. write_virtual_eeprom() can be used to write a value to a location, and read_virtual_eeprom() can be used to read the value at a specified location. The last two erase pages of the PIC's re-programmable flash are used as storage for the virtual EEPROM system.

Here is an example of usage:

#include <virtual_eeprom.c>

void test_virtual_eeprom(void)
{
init_virtual_eeprom();
write_virtual_eeprom(0, 55);
write_virtual_eeprom(1, 65);
write_virtual_eeprom(2, 75);
printf("%urn", read_virtual_eeprom(0)); //should say '55'
printf("%urn", read_virtual_eeprom(1)); //should say '65'
printf("%urn", read_virtual_eeprom(2)); //should say '75'
}

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Using the CCS C Compiler with Analog-to-Digital Converters with Computation Module

Tuesday 07 June, 2016

Support has been added to the CCS C Compiler for the new Analog-To-Digital Converter with Computation (ADC2) module that the PIC16F188xx family of devices have. In addition to legacy mode of operation the ADC2 module can be setup in Accumulate, Average, Burst Average or Low-Pass Filter modes of operation. When setup for Accumulate mode with each trigger of the ADC the conversion result is added to the accumulator and the ADCNT register is incremented. When setup for Average mode with each trigger of the ADC the conversion result is added to the accumulator and when the specified number of triggers has been done the average will be preformed on the accumulator. When setup for Burst Average mode it is similar to Average mode the difference being that when the ADC is triggered, it will perform the specified number of conversions and then perform the average calculation. When setup for Low-Pass Filter mode with each trigger of the ADC the conversion result is sent through the filter.

To support the new modes of operation the CCS C Compiler's built-in setup_adc() function has been updated to setup the ADC in these modes. Additionally an optional second and third parameter as been added to the function to set some additionally settings when using these the new modes of operation. When using Accumulate, Average or Burst Average modes the second parameter sets how much the accumulated value is divided by after each conversion. When using Low-Pass Filter mode the second parameter sets the cut-off frequency of the filter. The third parameter to the function sets the number of samples to be done before performing a threshold comparison for Average, Burst Average and Low-Pass Filter modes of operation.

In addition to the updates to the setup_adc() function the built-in functions adc_write() and adc_read() have been added to write and read some the other registers used by the ADC2 module. For example when setup for Low-Pass Filter mode the filtered result is stored in the ADFLTRH and ADFLTRL registers. After the calculation is completed the adc_read() function can be then be used to read the filtered result, for example:

Result = adc_read(ADC_FILTER);

Another feature of the ADC2 module is the ability to set a trigger source to start a conversion. To support this feature the built-in function set_adc_trigger() has been added to the CCS C Compiler. For example the following can be used to setup the ADC2 module to trigger the conversion when Timer 2 period match occurs:

set_adc_trigger(ADC_TRIGGER_TIMER2);

The following is an example using the CCS C Compiler to setup and use the ADC2 module for Low-Pass Filter mode, see ex_lowpass_filter_adc2.c in the PICCExamples folder for entire example:

setup_timer_2(T2_CLK_INTERNAL | T2_DIV_BY_128, 155, 10); //~10ms period, 100ms interrupt

setup_adc_ports(ADC_PIN, VSS_VDD);
setup_adc(ADC_LOW_PASS_FILTER_MODE | ADC_CLOCK_INTERNAL | ADC_TAD_MUL_255 | ADC_THRESHOLD_INT_END_OF_CALCULATION, FILTER_CUT_OFF_FREQ, ADC_READINGS);

set_adc_channel(ADC_CHANNEL);
set_adc_trigger(ADC_TRIGGER_TIMER2);

while(TRUE)
{
if(interrupt_active(INT_AD_THRESHOLD))
{
FilteredResult= adc_read(ADC_FILTER);

clear_interrupt(INT_AD_THRESHOLD);
}
}

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

New and Improved Development Boards!

Monday 14 March, 2016

Now available are two new development boards from CCS, the Rapid-18 and LPC Starter. CCS also has updated the PIC24 development boards to now include the PIC24FJ256GA106 and the PIC24EP256GP206.

The Rapid-18 uses the PIC18F4523 and has a built-in bootloader for loading code and a USB port for text communication to the running program, and provides advanced peripherals including a 12-bit ADC. The prototyping board features a PIC18F4523 attached to a potentiometer, two pushbuttons, three LEDs, and an ICD connector.

LPC Starter is designed to be an easy way to start software testing with the low pin count (8, 14, 18 and 20) parts that are not as easy to find on other development boards. This board provides standard IC sockets for DIP parts, access to all I/O pins, three LEDs, two buttons, one potentiometer, and a USB to RS-232 converter. Dip switches are used to connect or disconnect the USB port and to select internal or external (8Mhz) clock for the 14, 18 and 20 pin sockets.

CCS has also updated the devices to newer PIC24 devices for general development. The PIC24F board has the newer PIC24F256GA106 device that includes access to 53 I/O pins. The PIC24EP board has the PIC24EP256GP206 that includes 53 I/O pins, 16 analog pins and 2 RS-232 ports.

Click here to view all CCS Development Kits: http://www.ccsinfo.com/development-kits.php

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Using the Advanced Analog-to-Digital Converter (ADC) of the dsPIC33EPxxGS50x

Monday 14 March, 2016

There is a chance that you will need to read multiple analog signals at once or are the analog signals you are reading too small? The dsPIC3EPxxGS50x family of microcontrollers solve both of these problems, and the CCS C Compiler makes it easy to use. This family of chips have new ADC capable of sampling up to 5 analog inputs simultaneously. With the addition of two new functions for setting up the dedicated ADC cores, the Compiler makes it simple to read a single channel or multiple channels simultaneously. The following is an example of how to setup the ADC to read AN0 using the Dedicated ADC Core 0:

setup_adc_ports(sAN0, VSS_VDD);

setup_adc(ADC_CLOCK_SYSTEM | ADC_CLOCK_DIV_1 | ADC_WARMTIME_512);

setup_dedicated_adc(0, ADC_DEDICATED_CLOCK_DIV_2 |
ADC_DEDICATED_TAD_MUL_257 |
ADC_DEDICATED_CORE_CONV_DELAY);

set_dedicated_adc_channel(0, ADC_CHANNEL_AN0);

while(TRUE)
{
ADCReading = read_adc(ADC_START_AND_READ, 0);
...
}

Since the dsPIC33EPxxGS50x family of devices have individual Data Ready Status flags and Buffer registers for each analog channel, an optional second parameter was added to the read_adc() function to specify the channel to read. This allows for quicker reads with far less code generated to determine the flag to test and buffer to read.

Additionally the dsPIC33EPxxGS50x family have two Programmable Gain Amplifiers (PGA). The PGA is an op amp based non-inverting amplifier that can be used to amplify small voltages by 4x, 8x, 16x, 32x or 64x to improve the signal-to-noise ration of the measured signal. The PGA output voltage can then be read by one of the dedicated cores of the of the ADC, or used as an input to the Analog Comparator.

The new built-in functions are available in IDE compilers and the PCM command-line compilers starting with version 5.056.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Higher Accuracy PWMs with PIC16F1574 and PIC16F1764

Monday 14 March, 2016

Ever wanted more accuracy in the output of your PWMs? The new PIC16F1574 and PIC16F1764 family of devices both have a 16-bit PWM peripheral. The advantage of using a 16-bit PWM is that it increases the resolution of the PWM signal allowing for more precise duty cycles. Additionally each 16-bit PWM peripheral has an independent timer, this allows for generating the PWM without using one of the device's timers. The CCS C Compiler supports the new 16-bit PWM peripheral using either built-in functions or the #use pwm() library. The following is an example of how to use the #use pwm() library to setup the 16-bit PWM peripheral on a PIC16F1574:

#include <16F1574.h>
#fuses NOWDT

#use delay(internal=8MHz)

#use pwm(output=PIN_C3, frequency=122Hz, bits=16, duty=50)

void main()
{
for(;;);
}

Because the 16-bit PWM peripheral has an independent timer and registers for setting the PWM signal's phase and offset, the following built-in functions have been added to the CCS C Compiler to set the period, phase and offset:

SET_PWMx_PERIOD() //x being the PWM peripheral
SET_PWMx_PHASE() //x being the PWM peripheral
SET_PWMx_OFFSET() //x being the PWM peripheral

The following is an example of how to use the built-in functions to setup the 16-bit PWM peripheral:

#include <16F1574.h>
#fuses NOWDT
#use delay(internal=8MHz)

#pin_select PWM1=PIN_C3

void main()
{
set_pwm1_period(0xFFFF); //8.192ms period, ~122Hz frequency
set_pwm1_duty(0x7FFF); //50% duty

setup_pwm1(PWM_STANDARD);

for(;;);
}

The new built-in functions are available in IDE compilers and the PCM command-line compilers starting with version 5.056.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

PID Module Introduced for the PIC16F1614 Family

Friday 22 May, 2015

Built-in functions have been added to the CCS C Compiler for setting up and using the PID module introduced for the PIC16F1614 family of devices. The PID module is a mathematics module that can perform a variety of operations, most prominently acting as a PID (Proportional-Integral-Derivative) controller.

The module accomplishes the task of calculating the PID algorithm by utilizing user-provided coefficients along with a multiplier and accumulator. The main benefit of using the PID module is for the PID calculation to be completed much faster with the hardware module than in software. For example when running the PIC® from the 32 MHz internal oscillator the built-in HW PID function was measured to take 12.8 us, compared to a software PID function which was measure to take 216 us. This is approximately 1/16 of the time.

The following are the built-in functions that have been added for the PID module:

  • setup_pid() - used to setup the PID module and set the user-input coefficients.
  • pid_get_result() - used to input the set point and feedback from the external system to the PID module, start the calculation, and to retrieve the result to input in the external system.
  • pid_read() - used to read various PID module registers.
  • pid_write() - used to write various PID module registers.
  • pid_busy() - used to check if PID module is busy or not-busy, finished, with calculation.

The user-input coefficients, K1, K2 and K3, are calculated from the three classic PID coefficients Kp, Ki and Kd with the following equations:



T is the sampling period.

The following is an example of how to setup and use the PID module:

void main(void) {
pid_struct_t PIDOutput;
unsigned int16 ADCReading;
signed int16 K1 = 7, K2 = -6, K3 = 0;
unsigned int16 SetPoint = 500;
unsigned int16 PWMDuty;

setup_pid(PID_MODE_PID, K1, K2, K3);

//Setup ADC
setup_adc_ports(sAN3, VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);

//Setup PWM 3
setup_timer_4(T4_CLK_INTERNAL | T4_DIV_BY_32, 249, 1); //1ms period, from 32 MHz clock
set_pwm3_duty(0); //0% duty
setup_pwm3(PWM_ENABLED | PWM_OUTPUT | PWM_TIMER4);

while(TRUE) {
delay_ms(50);

ADCReading = read_adc();
pid_get_result(SetPoint, ADCReading, &PIDOutput);

PIDOutput.u &= 0x07;

if(PIDOutput.u >= 4) //PIDOutput is negative, set PWMDuty to Minimum
PWMDuty = 0;
else if(PIDOutput.u != 0) //PIDOutput > Maximum, set PWMDuty to Maximum
PWMDuty = 1000;
else if(PIDOutput.l > 1000) //PIDOutput > Maximum, set PWMDuty to Maximum
PWMDuty = 1000;
else
PWMDuty = PIDOutput.l;

set_pwm3_duty(PWMDuty);
}
}

The new built-in functions are available in IDE compilers and the PCM command-line compilers starting with version 5.045.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Serializing your USB devices, now made easier with CCS tools

Friday 22 May, 2015

Starting with version 5.046 of the CCS C Compiler and version 5.018 of CCSLOAD programming software has made it easy to create Unicode strings and write a user-provided serial number to the USB device descriptor during programming. In the device descriptor of a USB device a serial number string can be provided, but this is optional. If a serial number is provided in the device descriptor, two or more USB devices attached to a host cannot contain the same VID/PID/serial combination. Since USB has a mechanism for storing and reading serial numbers, it may be advantageous to a developer to use this mechanism instead of developing a custom mechanism on top of whatever USB protocol is being used. A challenge with using the standard USB mechanism, however, has been programming a user provided serial number due to the string being in Unicode and having the Unicode string packed in a table with other strings in the string table with a length field in front of the string. All of these problems have been solved in the latest tools from CCS.

First, a new pre-processor has been added to the CCS C Compiler:

_unicode(x)

When called, it converts the string x to a UTF-16 Unicode string. This is the format used by string descriptors in USB. For example:

char string[] = _unicode("Hello");

Since "Hello" is an ASCII string (no character has a value greater than 0x7F), all characters encoded will be 16bit - therefore the size of string[] would be the strlen("Hello")*2. string[], when in Unicode, will not be null terminated. It is not null-terminated since 0x00 is a valid character in UTF-16 and not a null-terminator. That means to get the string length of string[] the user would have to use sizeof() instead of strlen().

Second, the #serialize() pre-processor has been updated in the CCS C Compiler to tell the CCS CCSLOAD programming software how to serialize a Unicode string. The new parameter added is unicode, which tells the #serialize which USB string to write during programming with the user provided serial number. Here is an example:

#serialize(id=USB_STRING_DESC, unicode=3, prompt="SN#")

USB_STRING_DESC is a table of USB strings and is read by the CCS C Compiler's USB stack when the host PC reads a string from the PIC®. A value of 3 is passed to the Unicode parameter, to tell the #serialize that the serial number should be encoded as a Unicode string and that it should overwrite the 4th string in USB_STRING_DESC (the first string in USB_STRING_DESC is 0). In the device descriptor for your USB device, the field identifying which string to use for the serial number should also have been set to 3.

A working example of this is provided in the file ex_usb_hid.c. When compiled and programmed onto the PIC®, CCSLOAD will ask the user for the serial number and write the serial number onto the string descriptor used for the serial number.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

 Displaying 1 to 10 (of 140 articles)   Result Pages:  1  2  3  4  5 ...  [Next >>]