cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert integer to string?

antonius
Senior
Posted on January 02, 2014 at 11:47

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
31 REPLIES 31
Andrew Neil
Evangelist III
Posted on January 02, 2014 at 23:40

''I'm using MDK-ARM, isn't it gcc ?''

Most definitely

not

!

Keil (an ARM company) makes & sells tools on a commercial, closed-source basis.

antonius
Senior
Posted on January 03, 2014 at 13:28

would it be ?

sprintf(year, ''%02d'', (time.tm_year + 1900) % 100);

     lcd_string(year);

I got warning :

 warning:  #167-D: argument of type ''unsigned char *'' is incompatible with parameter of type ''char *restrict''

antonius
Senior
Posted on January 03, 2014 at 13:32

I tried to run it, it's freezed in the middle, any suggestions ??

chen
Associate II
Posted on January 03, 2014 at 13:53

Hi again

''I tried to run it, it's freezed in the middle, any suggestions ??''

Can you tell us what you do see?

What happens when you step through the code, where does it stop?

You did not answer my question :

Where is the printf going to ?

(Embedded systems do not normally have a console - so where is the printf directing to?)

What happens in the lcd_string() when the char is not an ASCII char?

Posted on January 03, 2014 at 14:13

I tried to run it, it's freezed in the middle, any suggestions ??

You'll need to use a debugger, and be more specific.

The utility of the time/year values would depend on them being correctly set and read from the RTC.

printf() would require some kind of semi-hosting in Keil to push the data out a Serial or SWV connection. Absent that you'll likely end up in the Hard Fault routine, as the result of an BKPT/SWI instruction trying to call some support functions.

You could implement a better Hard Fault handler, but again this would require some output device/mechanism.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on January 03, 2014 at 14:59

printf is going to print a text on terminal (USART)

antonius
Senior
Posted on January 03, 2014 at 15:01

any suggestion on how to debug it ? I'm not familiar with keil...

chen
Associate II
Posted on January 03, 2014 at 15:13

Why did you choose Keil then??

Go to the line you want to stop on,

Debug menu - insert breakpoint (or just press F9)

Then run (F5). When the line of code is reached - the debugger should stop and wait for your next operation.

You can single step (step into)

or step over

Step out

or Run

trevor23
Associate III
Posted on January 03, 2014 at 17:00

Is printf working as you expect? i.e. if you comment out the call to lcd_string does it work as expected? It's not obvious to me where your problem lies i.e. printf or lcd_string. It is always a good ides to cut a problem down to it's simplest form and be as specific as possible when describing the issue.

And good advise above re single stepping to where the problem lies.
antonius
Senior
Posted on January 04, 2014 at 13:45

printf is working fine, lcd_string can not read the variable.....

code :

void Time_Display(void)

{

   struct tm time;

   unsigned 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 + 1900) % 100);

//    lcd_string(time.tm_year);

}