|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
simple Time display problem |
Posted: Thu Jan 04, 2007 3:11 am |
|
|
Hi i built small time display but iam facing a problem with AM/PM allthing allright when hour become over 12 it's going AM but After 1 it goes PM
Here's the code
Code: | #include<16f876a.h>
#use delay (clock=20000000)
#include "lcd.c"
#fuses HS,nowdt
int sek=0,min=53,hour=10;
//--------------------------//
void main()
{
while(true){
delay_ms(1000); // Time
printf(lcd_putc,("\f"));
printf(lcd_putc, " %2u",hour);
printf(lcd_putc,(":"));
printf(lcd_putc, "%02u",min);
printf(lcd_putc,(":"));
printf(lcd_putc, "%02u",sek);
sek++;
If(sek>59){
sek=0;
++min;}
if(min>59){
min=0;
++hour;}
if(hour>12)
hour = 1;
If(hour>11)
printf(lcd_putc, " AM");
else
printf(lcd_putc, " PM");
}
} |
|
|
|
davekelly
Joined: 04 Oct 2006 Posts: 53 Location: Berkshire, England
|
|
Posted: Thu Jan 04, 2007 3:52 am |
|
|
You need an extra flag to track whether it is Am or Pm, which gets toggled every 12 hours
eg
Code: |
#include<16f876a.h>
#use delay (clock=20000000)
#include "lcd.c"
#fuses HS,nowdt
int sek=0,min=53,hour=10;
//--------------------------//
void main()
{
int1 AmPm;
while(true)
{
delay_ms(1000); // Time
printf(lcd_putc,("\f"));
printf(lcd_putc, " %2u",hour);
printf(lcd_putc,(":"));
printf(lcd_putc, "%02u",min);
printf(lcd_putc,(":"));
printf(lcd_putc, "%02u",sek);
sek++;
If(sek>59)
{
sek=0;
++min;
}
if(min>59)
{
min=0;
++hour;
}
if(hour>12)
{
hour = 1;
AmPm = !AmPm
}
If(!AmPm)
{
printf(lcd_putc, " AM");
}
else
{
printf(lcd_putc, " PM");
}
}
}
|
|
|
|
|
|
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
|