Rotary BCD (cherry) to Picaxe

Jaden

Senior Member
Don't know if anyone can get some use out of this?

I have used a Cherry BCD rotary switch
http://uk.farnell.com/cherry/pefa3000/switch-bcd-complement/dp/1180021

http://www.cherrycorp.com/english/switches/pdf/pushwheel.pdf

Just put your +5v (or what ever) to the C and the other 4 to the Picaxe. Below is what I get for each value. The rest I am just serrially transmitting it to another device, you may not need this.

Hope someone can find this of some use, I was pretty happy when it worked :D

Code:
' 0 - 11110000
' 1 - 01110000
' 2 - 10110000
' 3 - 00110000
' 4 - 11010000
' 5 - 01010000
' 6 - 10010000
' 7 - 00010000
' 8 - 11100000
' 9 - 01000000
									' 
	b21= pinsB AND %11110000				'Read value on BCD switch on pins pinsB 4,5,6,7
	SerOut A.4, N2400, (b21)				'send b19 value out pin A.4
 
Last edited:

BeanieBots

Moderator
How about converting to the actual number?

b21= pinsB AND %11110000
b21 = b21 Rev 8
b21 = b21 Xor %00001111
SerOut A.4, N2400, (b21)
 

hippy

Ex-Staff (retired)
Normally these types of switches aren't active components, just switches without internal pull-ups or pull-downs so they should be added to stop the I/O pins floating.

The easiest way to use them is with 0V to the switch common (wiper) and the four BCD outputs to I/O with internal pull-ups.
 

Jaden

Senior Member
Opps, once again I am not updating my findings! You are right hippy, I remembered reading that there was a pullup command, so I was able to normalise my original circuit (after cutting tracks :( ) and run C to ground......

Soooooooooo.... as per above, run C to common and the BCD outputs to your picaxe. Below is the result. BeanieBots you are using some stuff I don't follow so I will have to sit down and have a good read! I understand what you are getting at, but for my benifit and others could you please add statements!

Thanks

Code:
pullup on 			; enable pullups 
	pullup %11110000


'------------------------------ Main -----------------------------------------

main:

' 0 - 11110000
' 1 - 01110000
' 2 - 10110000
' 3 - 00110000
' 4 - 11010000
' 5 - 01010000
' 6 - 10010000
' 7 - 00010000
' 8 - 11100000
' 9 - 01000000
									' 
	b21= pinsB AND %11110000				'Read value on BCD switch on pins pinsB 4,5,6,7
	SerOut A.4, N2400, (b21)
 

westaust55

Moderator
@Jaden,
You do not indicate which PICAXE chip(s) your codes is aimed at.

Keep in mind that the REV command mentioned by BB is only available for the X1 and X2 parts, so other methods of bit manipulation using bit variable may need to be considered for M and M2 parts.
 

BeanieBots

Moderator
The code I posted simply reverses the bits (REV) and then inverst them (Xor) with the same mask you used (AND).
Now that you have changed the connections it's of little use anyway. (you might like to consider reversing the physical connections to make easier to read.)
 
Top