Shop OBEX P1 Docs P2 Docs Learn Events
Naming I/Os in SX/B — Parallax Forums

Naming I/Os in SX/B

ClintClint Posts: 95
edited 2007-02-12 21:11 in General Discussion
When defining the I/O pins in SX/B, can you name an arbitrary·group of pins? For example, could I name pins RC4 through RC 6 as a variable? I would like to be able to easily output a three bit number to a group of pins.

The structure I am referring to is something like:

··· name ·VAR· ·RC

except I would like to replace "RC" with a group of pins

I appreciate any help. I am new to the SX.

Comments

  • BeanBean Posts: 8,129
    edited 2007-02-12 17:21
    Clint,
    · You can only name individual pins (RC.0) or the whole port (RC).
    · To do three pin you would use "OR" and "AND" to set or clear the bits as needed:

    · temp = value << 4················ ·'·Get bits in position
    · temp = temp OR %1000_1111 · ' Create AND mask
    · RC = RC AND temp·············· ·· ' Clear bits that are zero
    · temp = temp AND %0111_0000 ' Create OR mask
    · RC = RC·OR temp··················· ' Set bits that are one

    · It might make more sense to just do:

    · RC.4 = value.0
    · RC.5 = value.1
    · RC.6 = value.2

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman

    Post Edited (Bean (Hitt Consulting)) : 2/12/2007 5:28:36 PM GMT
  • ClintClint Posts: 95
    edited 2007-02-12 17:38
    Thanks for the response Bean. I think I will use this structure unless someone has a better idea.
    · It might make more sense to just do:

    · RC.4 = value.0
    · RC.5 = value.1
    · RC.6 = value.2

  • JonnyMacJonnyMac Posts: 8,941
    edited 2007-02-12 21:11
    I, too, have been down this road and agree with Bean. I usually bundle this code into a subroutine so that it's easy to call when/where I need it. You can do something like this to pass any [noparse][[/noparse]byte] variable to your port bits:

    SET_PORT:
      RC.4 = __PARAM1.0
      RC.5 = __PARAM1.1
      RC.6 = __PARAM1.2
      RETURN
    
    
Sign In or Register to comment.