Shop OBEX P1 Docs P2 Docs Learn Events
Addressing Bit Positions in SX/B — Parallax Forums

Addressing Bit Positions in SX/B

John CoutureJohn Couture Posts: 370
edited 2006-01-23 21:17 in General Discussion
THE QUESTION:

I need to be able to set and get individual bit positions in a byte.· The SX/B help file says to do the following:

alarms········ VAR···· Byte(2)················ ' two bytes (16 bits)
fDoor··········VAR···· alarms(0).0············ ' front door
bDoor··········VAR···· alarms(0).1············ ' back door
patio··········VAR···· alarms(1).7


Using alarm as an example, I want to:

a = 1
x = 1
y = 7
alarm(x)··· = $00· ' clear the 2nd byte (this works)
alarm(x).y· = a·· ·' to set the 8th bit position within the 2nd alarm byte with a one

The SX/B seems to imply that alarm(1).7 has to be hard coded.· I need to be able to have variables in place of the 1 and the 7.

Does anyone know how to do it.

THE APPLICATION:

In working on the 1 Wire Search ROM routine, I need to store 64 bits of information.· A zero would indicate that there is no collision in this bit position and a one would indicate that there is a collision in this position.· This information will help in the next pass to determine which bits need to be toggled so that you can change your search pattern.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • BeanBean Posts: 8,129
    edited 2006-01-23 11:54
    John,
    The problem is that the SX doesn't allow a variable for bit position. You need to do something like this:

    temp = 1 << y
    IF a = 0 THEN
    · temp = ~temp
    · alarm(x) = alarm(x) AND temp
    ELSE
    · alarm(x) = alarm(x) OR temp
    ENDIF

    Bean.

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

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • John CoutureJohn Couture Posts: 370
    edited 2006-01-23 21:17
    Thanks Bean, that is certainly more elegant than anything I could think up!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.