Bcd And Binary

fingerstyle86

New Member
Hi guys does anyone know how to make your pins count in BINARY or BCD?By using the output pins 0 - 3 (Example : 0011 - 3low 2low 1high 0high)

Thanks guys!Cheers!
 

hippy

Technical Support
Staff member
pins = %0000
pins = %0001
pins = %0010
pins = %0011 etc

or

For b0 = 0 To 9
pins = b0
Next

or

For b0 = 0 To 9
outpin0 = bit0
outpin1 = bit1
outpin2 = bit2
outpin3 = bit3
Next

or

For b0 = 0 To 9
If bit0 = 1 Then : High 0 : ELse : Low 0 : End If
If bit1 = 1 Then : High 1 : ELse : Low 1 : End If
If bit2 = 1 Then : High 2 : ELse : Low 2 : End If
If bit3 = 1 Then : High 3 : ELse : Low 3 : End If
Next
 

hippy

Technical Support
Staff member
:)

I forgot ...

pin3 = 0 : pin2 = 0 : pin1 = 0 : pin0 = 0
pin3 = 0 : pin2 = 0 : pin1 = 0 : pin0 = 1
pin3 = 0 : pin2 = 0 : pin1 = 1 : pin0 = 0
pin3 = 0 : pin2 = 0 : pin1 = 1 : pin0 = 1 etc
 

manie

Senior Member
Once again, the ability to put somebody on their way to learn more has come through ! Well done Hippy !;) As to the other post, well : Dippy, Dippy, Dippppyyyyy !:rolleyes:;)
 

inglewoodpete

Senior Member
Counting in BCD

And for counting in BCD, try the following in the simulator:

Code:
#Picaxe 18x
b0 = 0
Do
   Pins = b0
   Pause 300                           'display for 0.3 seconds
   If b0 = $99 Then                    'That's really BCD 99
      b0 = 0                           'Reset to 0
   ElseIf bit0 = 1 and bit3 = 1 Then	'Ie If lower nibble of b0 = %1001 = 9
      b0 = b0 + 7                      '9 + 7 = 16 = %10000 = BCD 10
   Else
      Inc b0
   EndIf
Loop
Have fun: I did:p

Edit: Oh yes, forgot to add: set the simulator debug widow to display in hex.
 
Last edited:
Top