BCD Thumbwheel Switch output to decimal

alhoop

Member
Hello

I am a bit banger from the sixties. Is there a better way to do the following
using Picaxe-20M? I am reading BCD thumbwheel switches(1-2-4-8 on units and 1-2 on tens) with the common grounded.
Code:
     result = 0 	
     result10 = 0	
     let b0 = pins & $3f	
     if bit0 = 0 then:result = result +1
     endif					
     if bit1 = 0 then:result = result +2	
     endif			
     if bit2 = 0 then:result = result + 4
     endif					
     if bit3 = 0 then:result = result + 8	
     endif					
     if bit4 = 0 then:result10 = 1	
     endif					
     if bit5 = 0 then:result10 = result10 +2	
     endif			'
     result10 = result10 * 10	'
     cnt1 = result10 + result
Thanks
Al
 
Last edited:

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

if the common were to +V it would be straight forward ...

cnt1 = pins & $0F
cnt1 = pin4 * 10 + cnt1
cnt1 = pin5 * 20 + cnt1

If you can use b0 for a temporary ...

b0 = pins ^ $3F
cnt1 = b0 & $0F
cnt1 = bit4 * 10 + cnt1
cnt1 = bit5 * 20 + cnt1
 
Last edited:

alhoop

Member
I can tie common to +v.
Running the simulation, the first batch of code
works fine and saves about 40 bytes.

Thanks

Al
 
Top