bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Guys,
How can I use mktime for displaying weekday from RTC on STM32?
I used mktime, but it's not yet displaying the proper weekday, I don't understand ?
Please have a look for the code below,
code :
Any clues ?
thanks
How can I use mktime for displaying weekday from RTC on STM32?
I used mktime, but it's not yet displaying the proper weekday, I don't understand ?
Please have a look for the code below,
code :
Code:
uint32_t THH,TMM,TSS,WEEKDAY,DATE,MONTH,YEAR;
unsigned char date[20],day[30],month[20],year[20],hour[20],min[20],sec[32];
char *weekday_label[]={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
char *month_label[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"};
struct tm *utcTimeSnapshot = NULL;
time_t Tmp;
/* Load the Counter value */
Tmp = RTC_GetCounter();
utcTimeSnapshot = localtime(&Tmp);
/* Compute day */
// WEEKDAY = ((Tmp / 86400)%7)+1;
WEEKDAY = utcTimeSnapshot->tm_wday;
/* Compute date */
//DATE = ((Tmp / 31556926)%365)-40;
// DATE = ((Tmp / 86400)%365)-41;
DATE = utcTimeSnapshot->tm_mday;
/* Compute month */
//MONTH = ((Tmp / 2629743)%12);
MONTH = (utcTimeSnapshot->tm_mon)-1;
/* Compute year */
//YEAR = (Tmp / 31556926)+1970;
YEAR = (utcTimeSnapshot->tm_year)+1900;
/* Compute hours */
// THH = ( Tmp / 3600 ) % 24;
THH = utcTimeSnapshot->tm_hour;
/* Compute minutes */
//TMM = ( Tmp / 60 ) % 60;
TMM = utcTimeSnapshot->tm_min;
/* Compute seconds */
//TSS = Tmp % 60;
TSS = utcTimeSnapshot->tm_sec;
mktime(utcTimeSnapshot);
// printf("GET TIME");
//lcd_cmd(LCD_CLEAR);
sprintf(day,"%.2d",WEEKDAY);
sprintf(date,"%.2d",DATE);
//sprintf(month,"%02d",MONTH);
sprintf(year,"%.2d",YEAR);
sprintf(hour,"%.2d",THH); //convert integer to string
sprintf(min,"%.2d",TMM); //convert integer to string
sprintf(sec,"%.2d",TSS); //convert integer to string
//lcd_string("HOUR:MIN:SEC");
lcd_xy(0,0);
if (utcTimeSnapshot && (utcTimeSnapshot->tm_wday >= 0) && (utcTimeSnapshot->tm_wday <= 6))
{
lcd_string(weekday_label[utcTimeSnapshot->tm_wday]);lcd_string(",");
printf ("That day is a %s.\n", weekday_label[utcTimeSnapshot->tm_wday]);
}
else
lcd_string("???,");
//lcd_string(weekday_label[WEEKDAY]);lcd_string(",");
//lcd_string(day);
lcd_string(date);lcd_string("-");
lcd_string(month_label[MONTH]);
//lcd_string(month);
lcd_string("-");lcd_string(year);
lcd_xy(1,0);
lcd_cmd(SECOND_ROW);
lcd_string(hour);lcd_string(":");
lcd_string(min);lcd_string(":");
lcd_string(sec);
}
thanks