CCS, Inc. C Compiler Version 5 supports Microchip's PIC10F®, PIC12®, PIC16F® 8-bit peripherals. These peripherals include: Numerically Controlled Oscillator(NCO), Pulse-Width Modulation(PWM), Complementary Waveform Generator(CWG), Configurable Logic Cell(CLC), and Data Signal Modulator(DSM).
Part two of this series will cover the Configurable Logic Cell(CLC), and Data Signal Modulator(DSM) peripherals within C Compiler Version 5.
The Configurable Logic Cell (CLC) module is a new peripheral that is supported by the CCS C compiler. The CLC module allows creating several different types of logic functions which are not limited by software execution speed. The CLC module can be configured into eight different types of logic cells including AND-OR gate, OR-XOR gate, 4-input AND gate, S-R Latch, 1-Input D Flip-Flop with Set and Reset, 2-Input D Flip-Flop with Reset, J-K Flip-Flop with Reset and 1-Input Transparent Latch with Set and Reset.
The CCS C compiler makes it easy to setup and use the CLC module by providing several built-in functions including setup_clcx(), clcx_setup_input() and clcx_setup_gate(), x being the module number 1 to 4 depending on the PIC. The setup_clcx() function enables and sets the logic type of the CLCx module. The clcx_setup_input() function is used to select the four inputs to be used with the CLCx module. Finally, the clcx_setup_gate() function is used to select which inputs to use with the 4 gates and the basic logic of the gates. The following is a simple example program that sets up the CLC2 module to perform an AND operation on the two CLC2 input pins (RC3 and RC4) and outputs the result onto the CLC2 output pin (RC0):
#include <16F1507.h>
#fuses NOWDT
#use delay(internal=16MHz)
void main(){
setup_clc2(CLC_ENABLED | CLC_OUTPUT | CLC_MODE_AND); clc2_setup_input(1,CLC_INPUT_0); //assign CLC2IN0 as input 1 clc2_setup_input(4,CLC_INPUT_5); //assign CLC2IN1 as input 4 clc2_setup_gate(1,0x102); //assign input 1 to gate 1 clc2_setup_gate(2,0x180); //assign input 4 to gate 2 clc2_setup_gate(3,CLC_GATE_SET); //assign a high level to gate 3 clc2_setup_gate(4,CLC_GATE_SET); //assign a high level to gate 4
while(TRUE) { } }
Another new peripheral that is supported by the CCS C compiler is the Data Signal Modulator (DSM) module. The DSM module allows mixing a data steam, modulator signal, with a carrier signal to produce a modulated output. The modulator signal supplied to the DSM module can be generated internally from a peripheral, for example the UART peripheral, or supplied externally from the MDMIN pin. The carrier signal is comprised of two distinct and separate signals, a carrier high signal and a carrier low signal. Both of which can be generated internally from a peripheral, for example CCP1, or supplied externally from the MDCIN1 and MDCIN2 pins. Using this method allows the DSM module to generate Frequency-Shift Keying (FSK), Phase-Shift Keying (PSK) and On-Off Keying (OOK) modulation schemes.
The CCS C compiler makes it easy to setup and use the DSM module by providing a single function, setup_dsm(), to setup and enable the module. The setup_dsm() function requires three parameters to be passed to it, the first parameter enables and setup the basic setting of the module, the second parameter selects the modulator signal source and the third parameter selects the carrier signal sources and sets up some carrier specific settings. The following is a simple example that sets up up the DSM module to modulate the UART1 signal with a 100 kHz carrier when the UART transmit line is high and a 20 kHz carrier when the UART transmit line is low. The modulated signal is then output on the MDOUT pin, pin RC4 for the PIC16F1829 used in the example:
#include <16F1829.h>
#fuses NOWDT
#use delay(internal=16MHz)
#use rs232(xmit=PIN_B7,rcv=PIN_B5,baud=9600)
void main() {
char c;
setup_timer_2(T2_DIV_BY_1,39,1); //period 10us, frequency 100kHz setup_timer_4(T4_DIV_BY_4,49,1); //period 50us, frequency 20kHz
setup_ccp1(CCP_PWM | CCP_TIMER2); set_pwm1_duty((unsigned int16)80); //50% duty cycle
setup_ccp2(CCP_PWM | CCP_TIMER4); set_pwm2_duty((unsigned int16)100); //50% duty cycle
setup_dsm(DSM_ENABLED | DSM_OUTPUT_ENABLED, DSM_SOURCE_UART1, DSM_CARRIER_LOW_CCP2 | DSM_CARRIER_HIGH_CCP1);
while(TRUE) { if(kbhit()) { c = getc(); putc(c);
if(c == 'r') putc('n'); else if(c == 0x08) { putc(' '); putc(c); } } } }
We invite to learn more about CCS C Version 5 by pointing your browser to: http://www.ccsinfo.com/version5
Like us on Facebook and 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. REAL ICE, ICSP and In-Circuit Serial Programming are trademarks of Microchip Technology Inc. in the U.S. and other countries.
|