Shop OBEX P1 Docs P2 Docs Learn Events
Logic Help Needed — Parallax Forums

Logic Help Needed

T ChapT Chap Posts: 4,223
edited 2008-09-29 02:58 in Propeller 1
There are 16 LEDs on a PCF 8575 I2C expander.

A loop is running at all times updating the PinState word . The Pinstate is the LED pins to be ON (1).

There are 16 VAR's that need to get OR'd together. If one pin needs to go back to OFF, the Pinstate needs to have the specific pin removed.

An example below(just an example, not the real code)

CON
    LED1 =  %0000_0000_0000_0001
    LED2 =  %0000_0000_0000_0010
    ON = 1
    OFF = 0
VAR
   Word Pinstate
   Byte LED1State, LED2State

PUB Main
      Repeat
          SetPinState
          SendPinState

PUB SendPinstate
        i2c.start
        .....
      

PUB SetPinState
       LED1State := ON
       LED2State := ON
       Case LED1State   
             ON    :    Pinstate  |: LED1
             OFF   :    ???
       Case LED2State  
             ON    :    Pinstate  |: LED2
             OFF   :    ???





I can figure out how to OR the 16 Words together to create the Pinstate. I can't figure out a good way to remove a pin from the pin state if the pin needs to be OFF.

XOR Will Remove it, but if the pin was not on to start with XOR will turn it on.

Anyone know a trick to subtract the pin back out? I didn't try it yet, but is Pinstate - LED1 even an option?

Thanks

Post Edited (Originator) : 9/29/2008 3:01:07 AM GMT

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-29 00:26
    on
    pinstate |= |<lednumber 'set the bit

    off
    pinstate &= !|<lednumber 'reset the bit

    explanation - get the bit in the same way as or, then invert all the bits (!) and then and, will clear the bit that is 0

    Post Edited (Timmoore) : 9/29/2008 12:34:19 AM GMT
  • T ChapT Chap Posts: 4,223
    edited 2008-09-29 00:51
    Ok great. Thanks for that !
  • MovieMakerMovieMaker Posts: 502
    edited 2008-09-29 02:26
    shouldn't the third line read LED2 ?
  • T ChapT Chap Posts: 4,223
    edited 2008-09-29 02:58
    Yes, this was just a fast example, not the actual code.
Sign In or Register to comment.