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 CCS Technical Support

printf question.....

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








printf question.....
PostPosted: Thu Jan 03, 2008 5:26 pm     Reply with quote

Hi all,

I have a line of code that outputs two temperatures to an LCD as follows:

Code:

fprintf(LCD, "1: %lu F  2: %lu F", Temp[0], Temp[1]);


Before this code, I test Temp[0] and Temp[1] to be sure they are each in the appropriate range, and their respective sensor has not become disconnected. If a disconnect is detected, I'd like to replace the temperature value with '--' or 'NC' or something like that to flag the user. The problem is how to do this with printf that is setup for numeric data? The data type must be specified and it's a numeric value, not some ASCII text. I can do this with lots of kludgy code, but was wondering if there is a neat and clean way to accomplish it?

Thanks!

Dave
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jan 03, 2008 5:48 pm     Reply with quote

I don't think there exists a very elegant solution and you will always come to a variation of the code below:
Code:
if Sensor1Disconnected
  fprintf(LCD, "1: NC  ");
else
  fprintf(LCD, "1: %lu F", Temp[0]);

if Sensor2Disconnected
  fprintf(LCD, "  2: NC  ");
else
  fprintf(LCD, "  2: %lu F", Temp[1]);
Guest








PostPosted: Tue Jan 08, 2008 10:52 am     Reply with quote

Hi All,

OK, a related question:

I want to insert the degree symbol into the data that is displayed on the LCD. Here is what I am sending to the serial LCD now:

Code:

fprintf(LCD, "1: %lu F", Temp[0]);


I know that the degree symbol exists in the character set of the LCD display, and I can display it by itself using:

Code:

fputc(0xdf, LCD);


My question is how do I put everything in the same line? If I break the line up into multiple statements, I can't get it to compile Sad

Thanks,

Dave
Ttelmah
Guest







PostPosted: Tue Jan 08, 2008 11:11 am     Reply with quote

Code:

#define DEGREE 0xDF

fprintf(LCD, "1: %lu %cF", Temp[0],DEGREE);


You can also include it directly, with:
Code:


fprintf(LCD, "1: %lu \xDFF", Temp[0);


Best Wishes
Guest








PostPosted: Tue Jan 08, 2008 11:44 am     Reply with quote

Ttelmah,

Great! Works like a charm! Thanks for the tip!

Dave
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