17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Common Questions & Answers<br />

This example shows how to put a floating point number in a string.<br />

main() {<br />

char string[20];<br />

float f;<br />

f=12.345;<br />

sprintf(string,"\f%6.3f",f);<br />

}<br />

How do I get getc() to timeout after a specified time?<br />

GETC will always wait for a character to become available unless a timeout time is specified in<br />

the #use rs232().<br />

The following is an example of how to setup the PIC to timeout when waiting for an RS232<br />

character.<br />

#include <br />

#fuses HS,NOWDT<br />

#use delay(clock=20MHz)<br />

#use rs232(UART1,baud=9600,timeout=500) //timeout = 500 milliseconds, 1/2 second<br />

void main()<br />

{<br />

char c;<br />

while(TRUE)<br />

{<br />

c=getc();<br />

//if getc() timeouts 0 is returned to c<br />

//otherwise receive character is returned to c<br />

}<br />

}<br />

if(c) //if not zero echo character back<br />

putc(c);<br />

//user to do code<br />

output_toggle(PIN_A5);<br />

How do I put a NOP at location 0 for the ICD?<br />

The <strong>CCS</strong> compilers are fully compatible with Microchips ICD debugger using MPLAB. In order<br />

to prepare a program for ICD debugging (NOP at location 0 and so on) you need to add a<br />

#DEVICE ICD=TRUE after your normal #DEVICE.<br />

For example:<br />

#INCLUDE <br />

#DEVICE ICD=TRUE<br />

How do I wait only a specified time for a button press?<br />

The following is an example of how to wait only a specific time for a button press.<br />

357

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!