Shop OBEX P1 Docs P2 Docs Learn Events
Two bit parallel signal — Parallax Forums

Two bit parallel signal

kingnebkingneb Posts: 65
edited 2005-11-03 01:28 in General Discussion
How do you concatinate four two bit values onto the end of one another? I have a signal coming from the PC's parallel port two bits at a time. I need to assemble those four two bit values as a byte.

Thank you

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Too many lies from the right, which is the wrong side of the tracks.

Post Edited (kingneb) : 11/2/2005 10:59:56 PM GMT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-02 22:50
    Didn't we go through this already? And through a looonngg, drawn-out, often vague discussion?

    --> http://forums.parallax.com/showthread.php?p=553414

    You have two know when you have your two bits -- which means you actually need a third signal (latch, strobe, whatever you want to call it) unless you can guarantee that there will always be a bit change. In either case, grab the bits, shift them to their proper position, OR them with the final result.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 11/2/2005 10:54:11 PM GMT
  • BeanBean Posts: 8,129
    edited 2005-11-02 22:52
    Which is it, first you say four two bit values, then you say two four bit values ???
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    Those that would give up freedom for security will have neither.
    ·
  • kingnebkingneb Posts: 65
    edited 2005-11-02 22:53
    Sorry, I worded it in reverse. Its been a long day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Too many lies from the right, which is the wrong side of the tracks.

    Post Edited (kingneb) : 11/2/2005 11:00:38 PM GMT
  • kingnebkingneb Posts: 65
    edited 2005-11-02 23:06
    What do we use as a bit shift operator?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Too many lies from the right, which is the wrong side of the tracks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-02 23:08
    >> shifts right, << shifts left.

    Both are in the help file -- please have a read (see Reference -> Operators)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-11-02 23:31
    x var byte
    y var byte
    result var byte

    x = 3
    y = 2

    result = x >> y

    would this assemble a nibble properly? I know this is not the full byte however I want to see If I have the right idea. I never had to use bitwise operations this etensively before.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Too many lies from the right, which is the wrong side of the tracks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-02 23:42
    I suggest you fire up your compiler and run the program through Guenther's simulator (there's a button for it on the toolbar). Use RB or RC as your result variable so that you can see it in the output panel (make sure you make the select port bits outputs). Note that to do this you don't even need to have your SX connected. This will be a far more valuable experience for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-11-03 00:55
    This statement moves the two bit unit over to the highest position in the byte:

    tris_b = 0
    rb = 0
    unit1 var byte
    unit2 var byte
    
    unit1 = 3
    unit2 = 2
    
    rb = unit2 << 6
    
    



    This statement moves the two bit unit over to the second highest position:

    tris_b = 0
    rb = 0
    unit1 var byte
    unit2 var byte
    
    unit1 = 3
    unit2 = 2
    
    rb = unit2 << 4
    
    



    How do you move unit1 to the highest position and unit2 to the second highest position? The result should be 11100000.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Too many lies from the right, which is the wrong side of the tracks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-03 01:01
    You're getting four groups of two bits, right? Well, then, you're going to have to do a multi-step process:

    result = 0
    result = result | (bitsIn1 << 6) <-- these are the highest bits
    result = result | (bitsIn2 << 4)
    result = result | (bitsIn3 << 2)
    result = result | (bitsIn4) <-- these are the lowest bits

    Please understand that this is pseudo-code to demonstrate the process; you'll have to clean it up to actually run it through the SX/B compiler.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-11-03 01:28
    No big deal

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Too many lies from the right, which is the wrong side of the tracks.
Sign In or Register to comment.