websterling 12 Posted September 8, 2011 Share Posted September 8, 2011 I'm working on a project requiring a calculated 3-digit number to be updated periodically on a LCD display and came up with a simple solution to convert the number to characters. I'm posting it here on the chance that others might find it useful. I first thought of sprintf, but it's way too big for a msp430g2452. I found and tried tfp_sprintf, but it was also too big. I tried sstream (apparently the preferred method) but it caused 100+ errors in CCS, somewhere in the TI include files. I found this to convert a single digit to a character character = (char)(((int)'0') + digit_to_convert); I had a 3 digit number to convert; after a bit of thought I came up with this- // All number variables are type int // joules is the calculated 3-digit number- it is displayed with leading joules = total_seconds/3.2; joules100 = joules/100; // joules100 is the 100's place digit joules10 = (joules/10)%10; // joules10 is the 10's place digit joules1 = joules%10; // joules1 is the 1's place digit // The complete message is in a 32 element array- these 3 digits are elements 22-24 message = (char)(((int)'0')+joules100); message = (char)(((int)'0')+joules10); message = (char)(((int)'0')+joules1); nuetron and bluehash 2 Quote Link to post Share on other sites
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.