combining variables

vshortt

Senior Member
Working with a DS1307

Is there a way to combine variables like this:

b1 = 1
b2 = 2

b3 = (b1 + b2) = "12"

b3 = 12

Is there a way to do this? I don't want to add them together, I just want put combine them...
 

BeanieBots

Moderator
Except, if you are working with a DS1307 I would GUESS that you want BCD numbers?

So
b1=1
b2=2

b3= b1*16 + b2

ie. b3 = $12
 

vshortt

Senior Member
Except, if you are working with a DS1307 I would GUESS that you want BCD numbers?
You're right, since they come out in BCD format, there was one more step I have add, here's how I get the hours. Since the ASCII value is just the number plus $30 - just do it backwards... subtract $30 and voila!

b3 = b1-$30*10 + b2-$30 =

B3 = 12
 

marcos.placona

Senior Member
This is what I use to convert BCD to decimal (i.e. when getting data back from a DS1307):

Code:
BCDtoDec:
	tmpB4 = value / 16 * 10	'conv 16's column
	value = value & $0F + tmpB4
return
 

vshortt

Senior Member
Are you dealing with decimal, BCD or ASCII ? The DS1307 uses BCD data.
I'm dealing with ASCII becuase I use BCDTOASCII to convert the number.

Code:
symbol seconds = b1             ' symbol declaration for "seconds"
hi2cin [%11010000], 0,(seconds) ' read the seconds variable DS1307
                                ' use DS1307 i2c address because there is more than one chip on the i2c bus
 BCDTOASCII seconds,b2,b3       ' convert BCD variable to two ASCII numbers
 b50 = b2-$30*10 + b3-$30       ' convert ASCII to numerical and do math to add together,  b50 now equalis a whole number between 1 and 59
'continue code.....
 

hippy

Ex-Staff (retired)
As you seem to be using an X1 or X2 you can simplify that to ...

hi2cin [%11010000], 0,(seconds)
seconds = BcdToBin seconds

An illustration of where the question asked does not necessarily reflect what one wants to achieve.
 

vshortt

Senior Member
As you seem to be using an X1 or X2 you can simplify that to ...

hi2cin [%11010000], 0,(seconds)
seconds = BcdToBin seconds

An illustration of where the question asked does not necessarily reflect what one wants to achieve.
Thanks for the shortcut. I Think I've illustrated what I wanted to achieve in detailed enough manner.
 
Top