2014-01-11 01:28 PM
Guys,
Why suddenly sprintf doesn't work ? It was working yesterday, I shut down the power supply now, it's not giving me a good response code : uint32_t /*Tmp,*/THH,TMM,TSS,WEEKDAY,DATE,MONTH,YEAR; unsigned char date[10],day[10],month[10],year[10],hour[10],min[10],sec[10]; struct tm *utcTimeSnapshot; Tmp = RTC_GetCounter(); TSS = utcTimeSnapshot->tm_sec; sprintf(sec,''%02d'',TSS); lcd_string(sec); If I commented out sprintf, now it's running properly, I can see RTC on USART, but if I use sprintf, it's running 2 seconds and freeze......any ideas ? Thanks #learn-to-code2014-01-14 02:52 AM
I used mktime, but it's not yet displaying the proper weekday, I don't understand ?
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); }2014-01-16 05:18 AM
RTC_SetCounter(seconds_from_epoch);
===> doesn't work for me...
2014-01-17 07:58 PM
2014-01-17 09:04 PM
Likely you do not have source, but only a library in object form.
2014-01-18 02:16 PM
where can I find the source ?
is it related : http://www.keil.com/support/man/docs/armlib/armlib_Chdbbgcd.htmThe source for the Rogue Wave Standard C++ Library is not freely distributable. It can be obtained from Rogue Wave Software Inc., or through ARM, for an additional license fee. thanks2014-01-30 02:41 AM
How can I adjust the year with button and then save it into RTC register ?
any ideas ? thanks
1.
time
.tm_year=YEAR++;
2.
Time_SetCalendarTime(
time
);
3.
lcd_string(year);
2014-01-30 03:50 AM
As per my example(s) above. Manipulate the time structure to what you want and then call set_time which uses the time struct to set the RTC time in seconds from epoch. So iftime_struct is setup already as you need (parameters filled in as per my example) then to increment the year by one and set the new time all you would do is:
time_struct.tm_year++;
set_time(&time_struct);
2014-02-16 07:32 PM
When I pushed the button, it didn't increase the year, any comments ?
1.
if
(button1)
2.
{
3.
time_struct.tm_year++;
4.
lcd_string(year);
5.
}
2014-02-17 05:09 AM
You are displaying ''year'' and you didn't increment ''year''.
You do realise that you are not changing the RTC counter here?2014-02-17 05:24 AM
Observe there is no relationship established in your code between time_struct.tm_year and year