Shop OBEX P1 Docs P2 Docs Learn Events
Writing to a register — Parallax Forums

Writing to a register

firewaterfirewater Posts: 25
edited 2007-12-28 05:58 in BASIC Stamp
I

Post Edited (firewater) : 7/19/2008 6:10:37 PM GMT

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-12-27 07:41
    firewater -

    You need to read the entire BYTE into the Stamp, using SHIFTIN. Then you can modify just the top bit using the AND operator with a mask of $7F which will set the top bit off. Then re-write the BYTE using SHIFTOUT.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • FranklinFranklin Posts: 4,747
    edited 2007-12-28 00:56
    You need to take what you got with the read, AND it with $7f and then send it back the first byte would be %10011010 ($1a with the MSB set to 1) the second byte would be the result of the previous read anded with $7f.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-12-28 05:58
    firewater -

    The following code is from your program:

    set_LASER_CTRLO = LASER_CTRLO & MASK 'value from read and MSB set to 1)

    If you are trying to set the high bit on, you want to do this:

    set_LASER_CTRLO = LASER_CTRLO | $80 'value from read and MSB set to 1)

    To set a bit OFF you use AND (&) with a mask that specifies everything BUT the bit(s) to be turned OFF. To set a bit ON you use OR (|) with a mask that specifies the bit(s) to be turned ON.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.