Shop OBEX P1 Docs P2 Docs Learn Events
Can a SHIFT REGISTER , 74HC165N be used to read two BCD PushWheels? — Parallax Forums

Can a SHIFT REGISTER , 74HC165N be used to read two BCD PushWheels?

DavidMDavidM Posts: 626
edited 2007-02-10 08:04 in Propeller 1
Hi,

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?


Thanks

Dave M

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-10 05:43
    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
  • Bill HenningBill Henning Posts: 6,445
    edited 2007-02-10 05:44
    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

    then simply

    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 - a new blog about microcontrollers
  • DavidMDavidM Posts: 626
    edited 2007-02-10 05:51
    Hi all,

    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,
    regards

    Dave M
  • T ChapT Chap Posts: 4,223
    edited 2007-02-10 06:10
    Do take a look at the I2C PCF8575, it will read or write 16 bits using 2 pins. The code is very easy.
  • OzStampOzStamp Posts: 377
    edited 2007-02-10 06:32
    Hi Dave

    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..

    cheers
    Ronald Nollet Australia
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-10 06:41
    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)".
  • DavidMDavidM Posts: 626
    edited 2007-02-10 08:04
    Hi,

    Thanks Again,


    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!

    Dave M
Sign In or Register to comment.