Converting data types

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

Converting data types

Postby JAW » Thu May 27, 2010 7:54 am

I'm having trouble being able to convert to decimal values into a hex value to send to a dallas time chip. I'm trying to write code for a clock with a menu enabelling you to change the time. The display shows the decimal value but I can't get my head round converting to hex and then sending down the I2C. Any help would be greatly appreciated.

Regards

James

User avatar
Benj
Matrix Staff
Posts: 14075
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4297 times
Been thanked: 4051 times
Contact:

Re: Converting data types

Postby Benj » Thu May 27, 2010 9:00 am

Hello James,

First use the string manipulation function toString to convert the number in to an ascii string. Once you have done this you can send the string by referencing the string as a byte array.

eg

stringvar = toString(123)

i2csend (stringvar[0])
i2csend (stringvar[1])
i2csend (stringvar[2])

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

Re: Converting data types

Postby JAW » Thu May 27, 2010 9:48 am

Hi Benj,

Thank you for your reply. I'm trying to go down the route of converting the decimal value to a bcd code. So far I've found a previous post but can't get it to workk correctly :-

dec_t = dec/10
dec_u = dec MOD 10
bcd = (dec_u << 4)
bcd = bcd + dec_u

dec is the original decimal value
dec_t and dec_u are temporary values
bcd is the final final value

Regards

James

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8294
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2373 times
Been thanked: 3380 times
Contact:

Re: Converting data types

Postby medelec35 » Thu May 27, 2010 12:03 pm

Hello JAW.
Try chaging bcd = (dec_u << 4)
to
bcd = (dec_t << 4)

So you have:
dec_t = dec/10
dec_u = dec MOD 10
bcd = (dec_t << 4)
bcd = bcd + dec_u

Hope this helps.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

Re: Converting data types

Postby JAW » Thu May 27, 2010 12:41 pm

Thanks Medelec that's working perfectly now.

Many Thanks

James