|
|
View previous topic :: View next topic |
Author |
Message |
Steve Guest
|
printf equivalent |
Posted: Thu Jun 10, 2004 7:11 am |
|
|
Dear ALL,
I am trying to implement a real time clock in the correct
format, I am haveing a bit of trouble:
Code: |
lcd_cursor(7,1); \\position text on LCD
lcd_print_ch(sec + 0x30); \\print units of sec
if ((sec%10) == 0) \\ has a multiple of 10 second passed
{
lcd_cursor(6,1);
secT++; \\ increment 10's of seconds variable
if (secT < 6) \\ 10's of seconds lower than 6 (60 seconds)
{
lcd_print_ch(secT+ 0x30); \\send 10's of seconds to the LCD
}
else
{
secT=0;
}
|
I have used my own LCD drivers,
Problem:
The secT numbers seem to fly passed, yet the sec (units of seconds) do not change at all.
I have checked, the sec variable does increment every second
Can anyone help?? |
|
|
Steve Guest
|
|
Posted: Thu Jun 10, 2004 7:15 am |
|
|
The LCd drivers do work correctly |
|
|
Ttelmah Guest
|
Re: printf equivalent |
Posted: Thu Jun 10, 2004 7:32 am |
|
|
Steve wrote: | Dear ALL,
I am trying to implement a real time clock in the correct
format, I am haveing a bit of trouble:
Code: |
lcd_cursor(7,1); \\position text on LCD
lcd_print_ch(sec + 0x30); \\print units of sec
if ((sec%10) == 0) \\ has a multiple of 10 second passed
{
lcd_cursor(6,1);
secT++; \\ increment 10's of seconds variable
if (secT < 6) \\ 10's of seconds lower than 6 (60 seconds)
{
lcd_print_ch(secT+ 0x30); \\send 10's of seconds to the LCD
}
else
{
secT=0;
}
|
I have used my own LCD drivers,
Problem:
The secT numbers seem to fly passed, yet the sec (units of seconds) do not change at all.
I have checked, the sec variable does increment every second
Can anyone help?? |
Without seeing what incrments your 'seconds', it is hard to guess what is going on, but there is an obvious comment. At present you are printing the 'seconds' first, and the 'tens of seconds' next. Normally these digits want to be the other way round!. I suspect it is the seconds that are 'flying past', and the tens of seconds that are not changing. Now you don't show the declaration of 'SecT', but if this whole assembly is a subroutine, and this is not declared as 'static', or declared globally outside the routine, it will be lost between successive calls to the routine. In this case, the storage area holding this number may be being used by another part of the code, and contain a 'fixed' value, hence never change in the display.
Try something like:
div_t value;
//You must include stdio.h for this to work
value=div(sec,10);
lcd_print_ch(value.quot + '0');
lcd_print_ch(value.rem + '0');
This does the same arithmetic as your secs%10, but saves both the quotient (which should contain the tens of seconds), and the remainder (which should be the seconds), then outputs these in the correct order, savng quite a bit of code.
Alternatively, re-write what you allready have, but generate the 'tens' first.
Best Wishes |
|
|
|
|
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
|