Shop OBEX P1 Docs P2 Docs Learn Events
Variables and SHIFTIN / SHIFTOUT — Parallax Forums

Variables and SHIFTIN / SHIFTOUT

jefmjefm Posts: 50
edited 2009-01-05 18:14 in BASIC Stamp
I'm looking at Stampworks which deals with using SHIFTIN/SHIFTOUT to populate a WORD variable. Instead of one word variable, is it possible to populate several bits? I can only think of two ways to do this; by running SHIFTIN/OUT several times and reading only one bit, which seems like it would mess up the register, Or by running SHIFTIN/OUT normally and converting the word into several bits somehow. The last idea seems best but I'm still working on how to do it.
Is there some other way to do this? Thanks for any help.

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-01-04 00:46
    You can do a Word, no problem.
    In the SHIFTIN and SHIFTOUT argument is a Bits expression which establishes the number of bits which are to be clocked in/out.
    Read up on that in PBASIC Help.

    result  VAR   Word
    
    Main:
      SHIFTIN 0, 1, MSBPRE, [noparse][[/noparse]result[color=red]\16[/color]]
      END
    
    
  • jefmjefm Posts: 50
    edited 2009-01-04 01:14
    I think I got it, I reread the SHIFTIN/OUT stuff and you can have a whole stack of variables in there instead of just one. Now to reread DEBUG to see if that actually works, lol. Thanks gang
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-05 18:14
    Jef,

    You can use multiple WORD variables in the following manner…for example, if you have four 74HC595 chips in series and your data is in two word variables named result1 and result2.

    SHIFTOUT DataPin, SClk, MSBFIRST, [noparse][[/noparse]result1.HIGHBYTE, result1.LOWBYTE, result2.HIGHBYTE, result2.LOWBYTE]
    
    


    This will shift 4 bytes out in order from the two 16-bit word variables. On a real 595 this command would also be followed by a PULSOUT command to latch the data into the registers. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.