Shop OBEX P1 Docs P2 Docs Learn Events
Shiftin from a 74HC165 — Parallax Forums

Shiftin from a 74HC165

Mike LightonMike Lighton Posts: 3
edited 2005-09-03 02:37 in BASIC Stamp
I am fairly new to the Basic Stamp world. I have spent most of yesterday and today tring to find out how I can convert the bit pattern from the shiftin, into seperate variables. I am tring to use the additional inputs as discrete switch inputs to increase seperate counters, ie; if input 5 goes high the counter for input 5 increases by 1. Can anyone point me in the right direction ?

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-03 01:55
    Mike,

    ·· You can use some simple math to do this.· All you need to do is add the bit position to the current variable.· For example if counter5 needs to be incremented when bit 5 is 1, then each read of the 74HC165 you simple do something like:

    counter5 = counter5 + hc165.bit5
    

    You would have to do this for each bit you wanted added to a variable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Mike LightonMike Lighton Posts: 3
    edited 2005-09-03 02:13
    Chris,
    Would this need to be in a Loop function containing the Shiftin command ? I am assuming that in your example hc165 would be the variable in the Shiftin function ??
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-03 02:29
    Mike,

    DO
      SHIFTIN inValue  <--- specifics of your shiftin routine here.
      cnt0 = cnt0 + inValue.bit0
      cnt1 = cnt1 + inValue.bit1
      cnt2 = cnt2 + inValue.bit2
      cnt3 = cnt3 + inValue.bit3
      etc.    ' This could be a subroutine instead of within DO...LOOP
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Mike LightonMike Lighton Posts: 3
    edited 2005-09-03 02:35
    hop.gif·Thanks Chris, I will give this a try in the AM. Thanks again.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-03 02:37
    Mike,

    ·· Sorry if I seemed a little vague...I didn't have a demo together for this, just kinda top o' the head stuff...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.