CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

printf??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








printf??
PostPosted: Mon Mar 12, 2007 11:17 pm     Reply with quote

Hi
Can anyone explain to me how to use printf instead of using lcd_putc?

And if my input is in analog value, what is the suitable data type should i use? int or int8 or float or int16?

I also dont know the function of %. if i want my output in point, what should i write? Let say i want 7.564

Is it correct printf(%2f output)?
Ttelmah
Guest







PostPosted: Tue Mar 13, 2007 3:57 am     Reply with quote

You use 'lcd_putc', as the 'target' for the printf. So:

printf(lcd_putc,"format string",data to print);

Now really, I'd suggest getting a C primer, since an explanation of what the various formats 'do', would be a multi page document!. However I'll make a suggestion, based upon fairly efficient 'useage' in CCS, and one 'special' CCS format. You will need to put this 'into' a suitable program.
Code:


int16 val; //You want an int16, since the ADC, returns a 10bit value

val=read_adc(); //obviously need to select ADC channel first etc..

//Now assuming you are using the power rail as a reference, and this
//is 5v, you want 5.000 for 1024 counts (will never get this).
//You can do this two ways:

printf(lcd_putc,"%5.3f",(float)val/204.8);

//This converts 'val' into a floating point number (the 'float' bit), and
//scales this to give the right value. Downside, is that it is _bulky_, and
//_slow_. Floating point arithmetic, is not ideal on a small processor...
//The 'layout' is saying 5 characters, with three after the decimal point.

//Now a typical alternative:
val=((val*32)+(val*16))/10;

//This looks a lot more complex, but in computing terms is a lot quicker
//calculation. *32, and *16, are implemented using simple bit shifts.
//The slowest part is the division, and even this only takes about 1/4 the
//clock cycles of the floating point division.

printf(ld_putc,"%5.3lw",val);

//This uses a 'special' format in the CCS compiler, to print an
//integer, as a 'scaled' float. The advantage is that all the arithmetic
//for the printout, is still done using integer maths.

Now the second example,won't be quite accurate, but will be a _lot_ faster. Smile
It'll give a display of 2.457, for 2.5v in. In general, by carefully choosing the voltages involved, it may be possible to do better.

Best Wishes
pijang
Guest







PostPosted: Thu Mar 15, 2007 2:17 am     Reply with quote

Hi.. Razz

Hoho.. Finally my PIC and my LCD display is worked
Thank u for your help.
And also to PCM programmer that help me a lot in understanding
the programming..

Thank u again Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group