Shop OBEX P1 Docs P2 Docs Learn Events
Calling MCP23016 pins — Parallax Forums

Calling MCP23016 pins

NewzedNewzed Posts: 2,503
edited 2004-11-02 22:12 in BASIC Stamp
I have an MCP23016 with a lot of lines working.· I need to monotor the state of just of of the pins.· Can I write

if GP0.7·= 128 then do something?

12 of the pins on the chip could be in any state but I am only concerned about the state of GP0.7

Sid

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-02 17:44
    Sid, if you're monitoring one bit, then it would be either a 1 or 0...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-02 18:10
    You need to read the whole port, then check the bit in question. Something like this:

    I2CIN SDA, slaveAddr, GP0, [noparse][[/noparse]temp]
    IF (temp.BIT7) THEN
      ' do something
    ENDIF
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-11-02 19:17
    I took the easy way out, Jon.· I wrote:

    if GP0>=128 then dosomething.·

    This statement is true only of GP0.7 is
    high.· If it is NOT true, then GP0.7 must be low.

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-02 22:12
    You're right.· On the other hand, you could write "better" (my opinion -- please hold your flames) code by doing things like this:

    flags   VAR  Byte
    frGate  VAR  flags.BIT7
     
    IsOpen  CON  1
     
    ...
     
      IF (frGate = IsOpen) THEN
        ' deal with open front gate
      ENDIF
     
    
    


    To many this seems like a lot of work, but after 20 years of programming I can assure you that it saves the programmer time, and is immensely helpful when that same programmer wants to share his/her code with others.· It's also helpful when you change a circuit design as a couple changes in your definitions section is easier than hunting through a long listing for "magic numbers."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.