Logic Help Needed
T Chap
Posts: 4,223
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)
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
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
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