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

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

Converting data types

Post by JAW »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Converting data types

Post by Benj »

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

Post by JAW »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Converting data types

Post by medelec35 »

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

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

Re: Converting data types

Post by JAW »

Thanks Medelec that's working perfectly now.

Many Thanks

James

Post Reply