Welcome to the Parallax Discussion Forums, register to participate.

# Binary Clock

edited October 2010
I'm trying to build a binary clock. Hour Minutes and Seconds I have a DS1307 connected to the Propeller. There are 4 LEDs connected to pins 0-3 for the hours. 8,4,2,1 Then 6 LEDs connected to pins 4-9 for the minutes. 32,16,8,4,2,1 There are 6 LEDs connected to pins 10-15 for seconds. 32,16,8,4,2,1 How do I convert the decimal DS1307 to binary output to the LEDs?
Tagged:

• edited October 2010 Posts: 0
The standard technique for converting from one base to another is to keep dividing the number by the new base, outputting the remainders in reverse order. Try doing it with pencil and paper.
Leon Heller<br>G1HSM
• edited October 2010 Posts: 0
The output is BCD which is really easy to convert -- here's a method you could use:
```pub frombcd(bcdval)

return ((bcdval >> 4) * 10) + (bcdval & \$F)
```
Jon McPhalen<div>Burbank, CA</div>
• edited October 2010 Posts: 0
So the RTC (real time clock) sends BCD (binary-coded decimal) to make it easy to display the digits on normal 2digit pairs 7seg.
You want to scramble it back to raw binary.

If the minutes is at 49, in BCD you would get %0100_1001
```' in this example bcd = 49 = %0100_1001
dat
mov temp, bcd        ' bcd= two 4 bit nybbles
and bcd, #%1111      ' just keep the lower nybble = 9
and temp, #%11110000 ' just keep the higer nybble = 64
shr temp, #1         ' divide by 2 = 32
add bcd, temp        ' add it to new bcd. 32+9 = 41
shr temp, #2         ' divide it by 4  = 8
add bcd, temp        ' add it to bcd, the bcd is now 49
...                 ' continue your regular code here.

bcd long %01001001
temp res 1
```
• edited October 2010 Posts: 0
If you are doing a binary readout clock why not go all the way and use only 10 leds (11 if you want a 24 hour clock).
In science there is no authority. There is only experiment.
• edited October 2010 Posts: 203
This is How my display looks for clarity. The O are LEDs
O O O O O O O O O O O O O O O O
32 16 8 4 2 1 32 16 8 4 2 1 8 4 2 1
Hours Minutes Seconds

Im not doing the BCD

8 O O O
4 O O O O O
2 O O O O O
1 O O O O O O
H M S

Attached is my code it only has seconds works great but the code is very long.
• edited October 2010 Posts: 0

if sec == 0
outa[10..15] := %000000

I hope you did see a pattern and that all your code so far can be replaced
with a single line of
outa[10..15] := sec

and that the rtcEngine already have NumBCD<>BCDNum converter built-in
• edited October 2010 Posts: 203
Thanks a lot Tonyp12 that worked great.