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

Formatted output

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







Formatted output
PostPosted: Tue Jun 08, 2004 2:06 pm     Reply with quote

Dear All,

I have bought and regulary use the PCM compiler, which I find easy and
powerful.

As part of an assignment, I have been asked to develop a program with another compiler which does not have the comforts of the PCM compiler

Problem ->

I wish to display a clock in the correct format, i.e when the seconds tick over 9, the seconds occupy two digits i.e

under 10 = 09
above 10 = 10 (ON A LCD)

Normally I would use prinf with a format specifier, this compiler cannot give a formatted output it uses

lcd_print_ch('x');

How can I ensure the correct format is displayed, any ideas??
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: Formatted output
PostPosted: Tue Jun 08, 2004 2:25 pm     Reply with quote

Steve wrote:

Problem ->

I wish to display a clock in the correct format, i.e when the seconds tick over 9, the seconds occupy two digits i.e

under 10 = 09
above 10 = 10 (ON A LCD)

Normally I would use prinf with a format specifier, this compiler cannot give a formatted output it uses

lcd_print_ch('x');

How can I ensure the correct format is displayed, any ideas??


am i missing something here?

using your example...
Code:

if (x<10)
  lcd_print_ch('0');
lcd_print_ch('x');
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 08, 2004 2:26 pm     Reply with quote

Do a test, using the "if" statement. If the value is below 10,
then send a leading '0' character to the LCD.

-------------
Edited to add:
You beat me by 1 minute. I was trying to make him work a little.
Ttelmah
Guest







Re: Formatted output
PostPosted: Wed Jun 09, 2004 2:06 am     Reply with quote

Steve wrote:
Dear All,

I have bought and regulary use the PCM compiler, which I find easy and
powerful.

As part of an assignment, I have been asked to develop a program with another compiler which does not have the comforts of the PCM compiler

Problem ->

I wish to display a clock in the correct format, i.e when the seconds tick over 9, the seconds occupy two digits i.e

under 10 = 09
above 10 = 10 (ON A LCD)

Normally I would use prinf with a format specifier, this compiler cannot give a formatted output it uses

lcd_print_ch('x');

How can I ensure the correct format is displayed, any ideas??

As has allready been posted, you can do an 'if' test, but the other solution is to use division, and the modulus function.
So (if you 'time' is in 'val', then:
putc((val/10)+'0');
putc((val%10)+'0');

Best Wisihes
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