View Full Version : Can a SHIFT REGISTER , 74HC165N be used to read two BCD PushWheels?
02-10-2007, 12:37 PM
Q1) Can a SHIFT REGISTER ( such as the 74HC165N ) be used to read the BCD data pins from two BCD PUSH-WHEELS? used in a pair.
I wish to dial up any number 0-99 ( as each wheel is 0-9 used in a pair) and call the push-wheels at anytime to check its value?
What data type is best to hold this value in the propellers memory? INTEGER?
Q2) what code ( if available ) is there to read in shift register the 74HC165N Parallel to serial for the propellor?
02-10-2007, 12:43 PM
1) Sure. 0-99 would fit into any data type that the Propeller natively supports (8-bit bytes, 16-bit words, 32-bit long words).
2) Probably the easiest for someone possibly familiar with Stamps would be to use the BS2 compatibility library (downloadable from the Object Exchange. I think there's already sample code in some of the Stamp tutorials for using a 74HC165N and that can be easily adapted for the Propeller using the BS2 library.
There are lots of other I/O expanders you could use (like the Philips PCF8574 8-bit or PCF8575 16-bit). These attach to an I2C bus like that used for the boot EEPROM (and can be connected there). You would use the I2C driver library from the Object Exchange to access it.
Post Edited (Mike Green) : 2/10/2007 5:49:56 AM GMT
02-10-2007, 12:44 PM
A1) Should work just fine
A2) try the BS2 emulation library, but here is the pseudo code:
Use three lines, call them:
PL - parallel load
CP - clock line
DS - data line
bring PL low
bring PL high
that will load the shift register from the inputs
then for each of the eight bits
bring CP low
bring CP high
read DS bit
accumulate the bits into a byte, and voila! you are done!
I've got a pile of '165's that I will be using as input expanders.
-- edited after posting... mike is absolutely right, the BS2 library should work!
www.mikronauts.com (http://www.mikronauts.com) - a new blog about microcontrollers
02-10-2007, 12:51 PM
Geez, you guys are quick at responding to questions, I am really impressed here!
I did see the BS2 library of functions, and I do believe there is something in there for the shift registers. I will have a look and have a go.
Thanks for the tips,
02-10-2007, 01:10 PM
Do take a look at the I2C PCF8575, it will read or write 16 bits using 2 pins. The code is very easy.
02-10-2007, 01:32 PM
What you have to be aware of as well is that BCD data is different to Binary data.
So you have to do some nibble manipulation ( a nibble is 4 bits ..)
ie you can shift data like 10011001 ( BCD 99 on your thumwheels ) but in binary /dec this is 153..
Ronald Nollet Australia
02-10-2007, 01:41 PM
Yes, but on the Propeller, this is very very easy. If you have two BCD digits in a byte called "BB", you can convert it to an integer value with "((BB >> 4) & $F) * 10 + (BB & $F)".
02-10-2007, 03:04 PM
I found the function
"SHIFTIN" as part of the BS2 library.
Can I just use this function as my own object for the shift register?
I know I need the CONSTANTS as well, basically I want to use just a subset for testing.
I also know that I need to be aware that the 8 bits will be two nibbles and that one of the nibbles has to be multiplied by ten and added to the second nibble.
I also found a sample wiring diagram so I can no get my bits and my breadboard and have a go!
wish me luck!