Sections
You are here: Home Forum Project Discussion Integer to char then print on serial lcd

Integer to char then print on serial lcd

Up to Project Discussion

Integer to char then print on serial lcd

Posted by Paul at May 24. 2008

I've been trying to get this working forever and just the code compiles but always gives me unexpected results, im guessing im not casting it correctly but if sombody wouldn't mind taking a look at this. it prints out a single character that looks funny, like an a with a line over it maybe. I need a little help to get it to print out the temp.

http://pastie.caboo.se/202892

Thanks.

Re: Integer to char then print on serial lcd

Posted by Stein-Erik Dahle at May 25. 2008
You are looking for the sprintf() function. The sprintf is a string version of the printf. This will convert and format any number of int, char, strings, longints and so on into a string that you can send to the lcd. Check out these two references: sprintf: http://www.cppreference.com/stdio/sprintf.html printf : http://www.cppreference.com/stdio/printf.html

Re: Integer to char then print on serial lcd

Posted by Paul at May 25. 2008

Great. The int "%d" works with sprintf() but for some reason once i use doubles "%f" it prints out wierd chars once again. any Help?

Re: Integer to char then print on serial lcd

Posted by Liam Staskawicz at May 27. 2008
Depending on which toolchain you're using, floating point is most likely not built in. This can be a bit of a pain in these situations, but the reduction in code size is usually worth it. You could try doing fixed point operations to get the precision you need.

Re: Integer to char then print on serial lcd

Posted by Paul at May 27. 2008

Sorry i'm unsure what you mean by fixed point, as of now im just calculating the temp using double division etc math and then just typecast int and outputing it, as an int i guess it just truncates it huh? If you could help me by refrenceing some sites etc on how to do that that would be awsome, thanks.

Re: Integer to char then print on serial lcd

Posted by Bob Faulk at May 28. 2008
Unless you really need floating point, you should stick to using int's. Many embedded systems don't have good floating point support. The "%f" floating point format option for sprintf does not work with the yagarto arm7 toolchain. Instead of multiplying by 0.25, just use "/ 4" (or right shift by 2). Other fractional integer arithmetic can eliminate the need for floating point in most situations. Regards, Bob
Powered by Ploneboard
Document Actions