Shop OBEX P1 Docs P2 Docs Learn Events
Shiftout Question. — Parallax Forums

Shiftout Question.

Clock LoopClock Loop Posts: 2,069
edited 2005-11-01 03:38 in BASIC Stamp
Why doesn't this work


SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]0, Xady\7]





What Im trying to do here is take the number in variable Xady, convert it to at LEAST & MOST 7 bits binary, and then shift it out. I dont want
it to be converted to 8 bits binary due to me sending the 8th bit already.

This only works with multiples of 2. Is this a BS2 (or pbasic) code limitation?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-30 02:01
    You realize that you're command is sending 15 bits, right? Eight bits for the zero, seven bits for Xady. If you you meant to send one zero bit, you need to add \1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Clock LoopClock Loop Posts: 2,069
    edited 2005-10-30 02:36
    Oops.. sorry...

    I meant this

    SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]%0, Xady\7]
    
    



    But if you just told me I could do a \1, does that mean I can do a \7?
  • Clock LoopClock Loop Posts: 2,069
    edited 2005-10-30 03:46
    A better question...

    Anyone know of a better way to reduce FOR loops AND not use so many "%0\16"
    Basically with this code below, I am trying to CLOCK out 448 bits of binary bit "0".
    I am trying to use as little for loops as possible, to make the code run faster.
    Is my only option to do this WITH out using loop code to manually put in 28 copys of "%0\16" ?


      FOR cursor = 1 TO 9
        SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]%0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16, %0\16]
      NEXT
    
    
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-30 13:43
    If you're just clocking out zeros you could do this:

    · LOW Dpin
    · LOW Cpin
    · FOR idx = 0 TO 447
    ··· PULSOUT Cpin,·10
    · NEXT

    This creates 448 clock pulses with the data line low (0). You may need to adjust the width of the clock pulse for your device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-10-30 17:35
    To make 448 clock pulses with data=0, I think the following would also work. Note that 7*64=448. 7 cycles of PWM at 64 pulses per cycle.

    LOW Dpin
    LOW Cpin
    PWM Cpin,64,7
    



    On the other thing, you need
    SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]%0\1, Xady\7]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-30 17:49
    Tracy -

    That is neat, compact, esoteric, insightful and downright CAGEY!
    As always, my hat's off to a possibly perfect solution, and its author!

    Regards,

    Bruce Bates
  • Clock LoopClock Loop Posts: 2,069
    edited 2005-10-31 06:07
    Wow, im impressed.
    Can't wait to try all of your suggestions.....

    I am still working on the revision of my old circuit,, adding alot more... this is for the nokia cell phone LCD project. (in projects forum)

    I am sure I will have alot more quesitons once I finally wire up my keypad to my 74hc597 & 74hc595.

    I am basically running the keypad, and lcd display, and power button from 4 lines. Data, Clock, Latch, and Reset.

    The complete program and schematic will be updated in the "Nokia LCD" thread under Projects Forum.
    It will be a few days tho because Ive never attempted a circuit with both shiftin and shiftout devices, operating from the same clock and data lines.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-01 03:38
    Just a postscript on the PWM idea. The PWM command leaves the Cpin as an input, and the last level output is high, so it needs a pulldown resistor or an active LOW...

    LOW Dpin
    LOW Cpin
    PWM Cpin,64,7
    LOW Cpin    ' or have a pulldown R on Cpin to force it low after the PWM
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.