BS2 as a bcd to decimal converter
patay
Posts: 2
i have a 4 bit binary input and i want 12 decimal independent outputs.
i'm new in this and i don't know how can i configure the I/O pins to make this work?
i'm new in this and i don't know how can i configure the I/O pins to make this work?
Comments
Jeff T.
The Manual's section on memory allocation discusses how the Stamp I/O pins work and how to use them.
How do you want this to work? With a 4 bit binary input, you've got 16 possible codes. How do you want them to work with 12 outputs? Do you want this to work like a BCD to decimal selector IC where only one output is on at a time and that's the one selected by the 4 bit input value?
The Stamp can handle sets of I/O pins together, so groups of 4 pins (starting at multiples of 4) can be used as "nibbles" and groups of 8 pins (starting at multiples of 8) can be used as bytes. Again, the Manual goes into detail on this.
You'll need to write a program that inputs a "nibble" value from some group of 4 I/O pins (like 12-15), then makes up a value with a 1 bit in one bit position and 0s elsewhere. You then write this value to the output register where it affects I/O pins 0-11. It actually affects all the output pins, but you will only set I/O pins 0-11 to output mode and leave I/O pins 12-15 in input mode. Again, read the Reference Manual for details.
Here is one way brute force to convert BCD to individual output bits.
As Jeff said, make sure your I/O pins are indeed configured for output.
In hardware implementation you may see term "1 out of 16" selector.
I am sure there is a smarter way to accomplish this.
Index VAR Nib
BinaryNumber VAR Word
Main:
DO
DEBUG "BCD to Binary Bit conversion",CR
DEBUG "BCD in decimal = "
DEBUGIN DEC Index
DEBUG CR
LOOKUP Index-1, [1,2,4,8,16,32,64,128,512,1024 ], BinaryNumber
DEBUG ? Index
DEBUG ? BinaryNumber
DEBUG BIN16 ? BinaryNumber
LOOP
END
Happy programming
Vaclav
Addendum - let the mashine do the work using binary math
'Main:
DO
DEBUG "BCD to Binary Bit conversion",CR
DEBUG "BCD in decimal = "
DEBUGIN DEC Index
DEBUG CR
'LOOKUP Index-1, [1,2,4,8,16,32,64,128,512,1024 ], BinaryNumber
BinaryBit = 1 << (Index - 1)
DIRS = 0 ' set all I/O to input
DIRS = BinaryBit ' selected pin I/O direction - output
DEBUG BIN16 ? DIRS
DEBUG ? Index
DEBUG ? BinaryBit
DEBUG BIN16 ? BinaryBit
HIGH BinaryBit ' set I/O pin
LOOP