Shop OBEX P1 Docs P2 Docs Learn Events
Combining bits into a nib — Parallax Forums

Combining bits into a nib

ArchiverArchiver Posts: 46,084
edited 2003-10-11 19:42 in General Discussion
Hi All,

I posted this yesterday, but didn't see it show up. I am being mailbombed
for some reason, so my mail has been weird. Here goes again:

I have run into this problem before, and never found a good way of doing it.
I need this code to be tight, so I ask here for the best method to solve
this.

I want to check the status of 4 I/O pins, and then combine the results into
one variable i.e. 0000, 0101, etc. I have to use pins X3-X6 for this,
so I cant use INA. Any easy and fast way to do this?

Thanks,

Jonathan

www.madlabs.info

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-10-11 15:34
    Try this, Jonathat:

    myNib = INL >> 3

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=x0xh9laln35A6l_jc-uzW03-T5A-mpS3F8QWRC8V4QCmTaXTGGlhUN0d_LExNXqUx1qLoq9NGwM5OgkI]jpeakall@m...[/url
    Sent: Saturday, October 11, 2003 9:17 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Combining bits into a nib


    Hi All,

    I posted this yesterday, but didn't see it show up. I am being
    mailbombed for some reason, so my mail has been weird. Here goes again:

    I have run into this problem before, and never found a good way of doing
    it. I need this code to be tight, so I ask here for the best method to
    solve this.

    I want to check the status of 4 I/O pins, and then combine the results
    into one variable i.e. 0000, 0101, etc. I have to use pins X3-X6 for
    this, so I cant use INA. Any easy and fast way to do this?

    Thanks,

    Jonathan

    www.madlabs.info



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-11 17:22
    In a message dated 10/11/2003 7:13:51 AM Pacific Daylight Time,
    jpeakall@m... writes:
    I want to check the status of 4 I/O pins, and then combine the results into
    one variable i.e. 0000, 0101, etc. I have to use pins X3-X6 for this,
    so I cant use INA. Any easy and fast way to do this?

    Thanks,

    Jonathan
    __________________________

    Jonathan,

    I don't use the stamp much these days so my thought might be off, but here it
    goes......

    It does not look like the BS2 has a Rotate Right command, so maybe this will
    work if you have two open output pins.

    1) Read INL (pins 0 through 7)
    2) SHIFTOUT - shift LSB first and shift only 3 bits (0, 1 & 2)
    3) Then read the low nibble of the shifted out variable

    It would be really cool if the stamp would allow you to not specify a Dpin
    (data pin) or Cpin (clock pin), then you would not need to waste two output
    pins, but I doubt the program would allow such......syntax error.

    OR.....is there a rotate right command anybody? Have not seen it.

    Are you going to use the numerical result directly, like flash a light the
    number of times indicated by the nibble? If you are going to use a lookup table
    of some sort based on the value of the nibble, an alternate approach would be
    to;

    1) Read INL
    2) Mask the result with %01111000
    3) Do your lookup table with the numerical result returned

    ?????????/

    Ken


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-11 17:23
    In a message dated 10/11/2003 7:35:25 AM Pacific Daylight Time,
    jwilliams@p... writes:
    Try this, Jonathat:

    myNib = INL >> 3

    -- Jon Williams
    Jon,

    is ">>" rotate right?

    Ken


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-11 17:32
    >> is shift right (lsb is lost, msb becomes 0).

    -- Jon


    Original Message
    From: smartdim@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=P43JeKjVOE5sHER1RveWGTPt3VV3DOwGJ2APm9iScIL4NIPjBtzZe20r5Mi2dxIay09Dt13DDPg]smartdim@a...[/url
    Sent: Saturday, October 11, 2003 11:24 AM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Combining bits into a nib


    In a message dated 10/11/2003 7:35:25 AM Pacific Daylight Time,
    jwilliams@p... writes:
    Try this, Jonathat:

    myNib = INL >> 3

    -- Jon Williams
    Jon,

    is ">>" rotate right?

    Ken


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


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-11 19:42
    Jon,

    Perfect, thanks!

    Jonathan

    www.madlabs.info


    Original Message
    From: "Jon Williams" <jwilliams@p...>
    To: <basicstamps@yahoogroups.com>
    Sent: Saturday, October 11, 2003 7:34 AM
    Subject: RE: [noparse][[/noparse]basicstamps] Combining bits into a nib


    > Try this, Jonathat:
    >
    > myNib = INL >> 3
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=biRQuHbmRJhR2WlncRgGOTLC28fbhwEAJdKOB922VyQExrYIN70EUkKSXqNwuBmsyBpoxiNQnAx3ov4]jpeakall@m...[/url
    > Sent: Saturday, October 11, 2003 9:17 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Combining bits into a nib
    >
    >
    > Hi All,
    >
    > I posted this yesterday, but didn't see it show up. I am being
    > mailbombed for some reason, so my mail has been weird. Here goes again:
    >
    > I have run into this problem before, and never found a good way of doing
    > it. I need this code to be tight, so I ask here for the best method to
    > solve this.
    >
    > I want to check the status of 4 I/O pins, and then combine the results
    > into one variable i.e. 0000, 0101, etc. I have to use pins X3-X6 for
    > this, so I cant use INA. Any easy and fast way to do this?
    >
    > Thanks,
    >
    > Jonathan
    >
    > www.madlabs.info
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject
    > and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p....
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
Sign In or Register to comment.