Shop OBEX P1 Docs P2 Docs Learn Events
Shiftout variable modifiers — Parallax Forums

Shiftout variable modifiers

ArchiverArchiver Posts: 46,084
edited 2003-01-24 18:39 in General Discussion
Stampers,
I've again run into Stamp trouble working late into the night...
I just can't seem to make the Stamp send the data I want.
Here are the relevant parts of the code:

Number var word
Space con %000000
Shiftout 11, 10, MSBFIRST [noparse][[/noparse]Number\7, Space\6, Number.HIGHBYTE.BIT7\9]

Say Number holds %1010101001100110. I want to Shiftout the sequence
%1010101000000001100110 by shifting out %1010101 (the first seven bits of
%1010101001100110),

^^^^^^^
%000000 (6 bits of Space), and %001100110 (the last nine bits of
%1010101001100110)

^^^^^^^^^
From what I've seen, the HIGHBYTE.BIT7 modifier seems to result in the Stamp
only sending bit 7 of the first byte, despite the \9 modifier. Is this correct?
What am I doing wrong? Any suggestions as to how I can accomplish what I want?
Thanks

- Robert
_|_
'
0
'


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-01-24 08:34
    > Number var word
    > Space con %000000
    > Shiftout 11, 10, MSBFIRST [noparse][[/noparse]Number\7, Space\6, Number.HIGHBYTE.BIT7
    \9]
    >
    > Say Number holds %10101010 01100110. I want to Shiftout the
    sequence %1010101 000000 001100110 by shifting out %1010101 (the
    first seven bits of %1010101001100110),...

    You seem to swap lowbyte and highbyte.
    %1010101001100110
    ^^^^^^^^HIGHBYTE
    ^^^^^^^^LOWBYTE
    ^bit15 ^bit0
    What you intend to do is to send the highest 7 bits, 6 bit space,
    lower 9 bits:

    ...[noparse][[/noparse]Number.BIT8\7, Space\6, Number\9]

    Im not sure whether the Number.BIT8\7 works as intended but give
    it a try.

    Hope it helps
    Adrian
  • ArchiverArchiver Posts: 46,084
    edited 2003-01-24 18:39
    Hi Robert,

    There is a lot of confusion about shiftout, when used with the \bits modifier.

    Even the manual is confused. It gives the example of x=250, which is
    %11111010 in binary. At one point the manual says that shiftout
    0,1,msbfirst,[noparse][[/noparse]250\4] will shift out the "lowest 4 bits (%0000 in this
    case)", which is wrong, because the lowest 4 bits of 250 are "%1010".
    Huh? In the next paragraph, it states that [noparse][[/noparse]250\4] will shift out
    "four bits of the number 250 (%1111)..."

    Both are wrong. What it shifts out is in fact the lowest 4 bits, "1010".

    Here is what happens with,
    shiftout 0,1,msbfirst,[noparse][[/noparse]variable\n]

    ...the Stamp grabs the lowest n bits of the variable, and if
    necessary pads the variable on the left with zeros. Then it sends
    the n bits, most significant bit first. In other words, if variable
    is a word, the shiftout does not start with the most significant bit
    of the word (unless n=16). For example
    x var word
    x = 250 ' = %0000000011111010 in binary
    shiftout 0,1,msbfirst,[noparse][[/noparse]x\4]

    does _not_ send "0000". It gets the 4 least significant bits, "1010"
    and sends those.
    Example:
    shiftout 0,1,msbfirst,[noparse][[/noparse]x\11]
    sends "00011111010", the 11 least significant bits, but it sends them
    most significant bit first. That would also be true if x had been
    declared as a byte instead of a word, because the stamp would pad the
    value with zeros on the left.

    With lsbfirst, the same thing is true, for example,
    shiftout 0,1,lsbfirst,[noparse][[/noparse]x\11]
    would transmit "01011111000", again the 11 least significant bits,
    but least significant bit first. That is easier to understand.

    The shiftout command really doesn't know or care what size of
    variable x is. It will always peal n bits of the right end and pad
    it on the left with zeros if necessary, and then send those n bits
    either msb or lsb first.

    I hope that clears up some confusion. That is my understanding of it
    anyway, which comes from looking at an oscilloscope screen to see
    what comes out. I hope someone will correct me if I've got it all
    wrong!

    In direct answer to your question, try

    Shiftout 11, 10, MSBFIRST [noparse][[/noparse]Number>>9\7, Space\6, Number\9]

    The first one shifts the most significant 7 bits all the way to the
    right, and then sends those, msbfirst. Number\9 will send the
    rightmost 9 bits, msbfirst.

    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...



    >Stampers,
    >I've again run into Stamp trouble working late into the night...
    >I just can't seem to make the Stamp send the data I want.
    >Here are the relevant parts of the code:
    >
    >Number var word
    >Space con %000000
    >Shiftout 11, 10, MSBFIRST [noparse][[/noparse]Number\7, Space\6, Number.HIGHBYTE.BIT7\9]
    >
    >Say Number holds %1010101001100110. I want to Shiftout the sequence
    >%1010101000000001100110 by shifting out %1010101 (the first seven
    >bits of %1010101001100110),
    >
    >^^^^^^^
    >%000000 (6 bits of Space), and %001100110 (the last nine bits of
    >%1010101001100110)
    >
    >^^^^^^^^^
    >>From what I've seen, the HIGHBYTE.BIT7 modifier seems to result in
    >>the Stamp only sending bit 7 of the first byte, despite the \9
    >>modifier. Is this correct?
    >What am I doing wrong? Any suggestions as to how I can accomplish what I want?
    >Thanks
    >
    >- Robert
    > _|_
    >'
    0
    '
Sign In or Register to comment.