Shop OBEX P1 Docs P2 Docs Learn Events
pin question — Parallax Forums

pin question

OwenOwen Posts: 100
edited 2007-07-06 06:04 in General Discussion
I'm new to the SX and have a quick question...
I need to define a set of 4 rb pins but I only know how to define all 8 as a group and not just the first 4
at the moment my cod looks like this:

'pins
LcdBus VAR RB

Can I define LcdBus as just pins rb.0 to rb.3 ?
thanks for any help,

Owen

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-05 20:59
    I do not think there is a way to assign a variable name to a group of more than one but less than eight bits. However, when you want to change just the first four bits the following statements should help you accomplish this without changing the other four bits of RB.

    NewValue = LcdBus XOR NewValue       ' Identify the bits that must change.
    NewValue = NewValue AND %0000_1111   ' Ensure NewValue does not have the upper four bits set.
    LcdBus = LcdBus XOR NewValue         ' Change the required bits.
    
    


    You will need to declare NewValue as a byte varible or replace it with an existing variable.

    I hope this helps.

    - Sparks


    [noparse][[/noparse]EDIT: I improved the code segment. The previous version would have cleared the high bits of LcdBus.]

    Post Edited (Sparks-R-Fun) : 7/5/2007 9:59:00 PM GMT
  • JonnyMacJonnyMac Posts: 8,945
    edited 2007-07-05 21:09
    There are no nibbles in the SX (they're internally synthesized in the BASIC Stamp). To expand on Sparks's suggestion, here's how you can move a value to the lower four pins on RB without affecting the others:

    newValue = newValue & $0F
    RB = RB & $F0
    RB = RB | newValue
    



    If you want to use the upper four bits of RB as the LCD buss, you can do it like this:

    newValue = newValue & $0F
    SWAP newValue
    RB = RB & $0F
    RB = RB | newValue
    
  • OwenOwen Posts: 100
    edited 2007-07-05 21:34
    this solved my problem
    thank you!

    Owen
  • bennettdanbennettdan Posts: 614
    edited 2007-07-06 03:36
    JonnyMac,
    When you enable the lower 4 pins with this code does this disable the upper 4 pins or can you use the upper 4 pins for something else?
  • JonnyMacJonnyMac Posts: 8,945
    edited 2007-07-06 06:04
    The line

    RB = RB & $F0
    



    clears the lower bits of RB while preserving the upper bits -- that way they can be used for something else without being bothered by writing to the lower four.
Sign In or Register to comment.