![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Steve Guest
|
Formatted output |
Posted: Tue Jun 08, 2004 2:06 pm |
|
|
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?? |
|
![](templates/subSilver/images/spacer.gif) |
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: Formatted output |
Posted: Tue Jun 08, 2004 2:25 pm |
|
|
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');
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 08, 2004 2:26 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: Formatted output |
Posted: Wed Jun 09, 2004 2:06 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|