2014-01-02 02:47 AM
struct tm time;
char year[50]; Guys, I want to display year into LCD screen but I got 00 on LCD, any clues on how to do it ? thanks printf(''Time: %d-%d-%d %02d:%02d:%02d \r\n'', time.tm_year, \ time.tm_mon+1, time.tm_mday,\ time.tm_hour, time.tm_min, time.tm_sec); sprintf(year,''%.2f'',time.tm_year);lcd_string(year); #!complicated
2014-01-02 03:10 AM
Hi
The 'printf' can depend on the library that you are using, which can depend on the tool chain that you are using. IAR tool chain does not support the '%f' in the 'basic' library - you have to use the 'full' library but that then adds 20K of binary (IAR provide the implementations of the STD libraries - you choose which one to use basic, full + another which I forget now). So what tool chain are you using?2014-01-02 03:15 AM
I'm using MDK-ARM, isn't it gcc ?
2014-01-02 03:21 AM
I got this warning :
..\USER\RTC\RTC_Time.c(481): warning: #167-D: argument of type ''char *'' is incompatible with parameter of type ''unsigned char *'' code : struct tm time; char year[50]; time = Time_GetCalendarTime(); printf(''Time: %d-%d-%d %02d:%02d:%02d \r\n'', time.tm_year, \ time.tm_mon+1, time.tm_mday,\ time.tm_hour, time.tm_min, time.tm_sec); sprintf(year,''%02d'',time.tm_year); lcd_string(year);2014-01-02 03:23 AM
2014-01-02 03:30 AM
Hi
Where is the printf going to ? ''sprintf(year,''%.2f'',time.tm_year);'' will probably not be null terminated - so when ''lcd_string(year);'' executes - it probably goes on beyond the buffer you allocated and crashed.2014-01-02 04:14 AM
Hi
''sprintf(year,''%.2f'',time.tm_year);'' will probably not be null terminated'' Forget that - apparently it does Null terminate.2014-01-02 04:45 AM
At least 2 problems here:
1. Should be ''%02d'' not ''%.2f''2. tm_year is an integer containing number of years since 1900. Therefore to get year as 2 digits would be something like this ''sprintf(year, ''%02d'', (time.tm_year + 1900) % 100);''2014-01-02 05:20 AM
2. tm_year is an integer containing number of years since 1900. Therefore to get year as 2 digits would be something like this ''sprintf(year, ''%02d'', (time.tm_year + 1900) % 100);''
Same two digits without the addition, mind.2014-01-02 07:21 AM
Same two digits without the addition, mind.
Indeed Clive