How can I use a binary bit pattern to set highs and lows on multiple pins? Easy
Brian218
Posts: 92
Hi,
I usually use the propeller, but am also trying to learn SX/B for projects where the propeller would be overkill. I mention the propeller because I can easily do the following in SPIN, but find myself stuck when attempting to do the equivalent on the SX.
I scanned through som previous forum posts without finding what I'm looking for.
I'm trying to set the highs and lows of 3 output pins using a binary bit pattern.
Is there an easy way to do this? Any help will be greatly appreciated.
Thanks in advance.
Merry Christmas
Example:
the output pins are RB.0, RB.1 and RB.2
#1
Binary_pattern = %101
The result I want based on this bit pattern is:
RB.0 high
PB.1 low
PB.2 high
#2
binary_pattern = %011
desired result:
RB.0 low
RB.1 high
RB.2 high
Using Spin the equivalent would be:
#1
Bit_pattern := %101
OUTA[noparse][[/noparse]RB0..RB2] := Bit_pattern
#2
Bit_pattern := %011
OUTA[noparse][[/noparse]RB0..RB2] := Bit_pattern
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
I usually use the propeller, but am also trying to learn SX/B for projects where the propeller would be overkill. I mention the propeller because I can easily do the following in SPIN, but find myself stuck when attempting to do the equivalent on the SX.
I scanned through som previous forum posts without finding what I'm looking for.
I'm trying to set the highs and lows of 3 output pins using a binary bit pattern.
Is there an easy way to do this? Any help will be greatly appreciated.
Thanks in advance.
Merry Christmas
Example:
the output pins are RB.0, RB.1 and RB.2
#1
Binary_pattern = %101
The result I want based on this bit pattern is:
RB.0 high
PB.1 low
PB.2 high
#2
binary_pattern = %011
desired result:
RB.0 low
RB.1 high
RB.2 high
Using Spin the equivalent would be:
#1
Bit_pattern := %101
OUTA[noparse][[/noparse]RB0..RB2] := Bit_pattern
#2
Bit_pattern := %011
OUTA[noparse][[/noparse]RB0..RB2] := Bit_pattern
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
Comments
You can also use GETBIT and PUTBIT which are pin bit operators in the forthcoming SX/B 2.0, but essentially those high level commands do the same as above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Thanks for the quick reply!
I'll study your example and try to figure it out.
B-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
Post Edited (JonnyMac) : 12/26/2008 9:20:34 PM GMT
I appreciate the info, every little bit helps <no pun intended>
B-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.