SPIN Theory Question1
TheTech69
Posts: 51
in Propeller 1
Happy New Year, forum members!!
I came across bit of code:
con
#(true) ON, OFF
The parenthesis are to list parameters; the pound sign is an Object Constant reference. The Propeller Manual v1.1 has an example for the Object Constant reference as numbers (#1) and then some other user defined words. I understand that example in the manual. What I don't understand is why is "true" in parenthesis instead of a number?
Thank you
I came across bit of code:
con
#(true) ON, OFF
The parenthesis are to list parameters; the pound sign is an Object Constant reference. The Propeller Manual v1.1 has an example for the Object Constant reference as numbers (#1) and then some other user defined words. I understand that example in the manual. What I don't understand is why is "true" in parenthesis instead of a number?
Thank you
Comments
# is used for enumeration of constants in a Spin CON section.
true is a predefined constant with value -1
So the enumeration starts with -1 for ON, and OFF is set one higher which is 0.
You could also write it like that:
CON
ON = -1
OFF = 0
Andy
Ok...but I know that "1" usually equates to a HIGH output on the pin. Since TRUE is predefined as "-1" how does that make the output HIGH?
I might be thinking too much about this and probably should press the "I Believe" button but I am wanting to learn the theory behind why the constant declaration was written the way it is.
Thank you
1 = high
0 = low
1 =voltage
0 =ground
That is how I've always viewed it but maybe I'm wrong. I'm just learning SPIN and have little experience other then what I've learned so far.
so ON (or true) is all 32 bits set, and OFF is all bits cleared.
If you set only one portpin you can use 0 and 1 to output low or high.
But if you set several bits at once, it's helpful to have ON defined with all bits set: This sets pins P4..P7 to high. For this example ON needs to have the lowest 4 bits set. To make it always work one can just sets all bits to 1 for ON.
It's BTW the same if you write: But I don't like these ~~ and ~ to set and clear pins, it's very unreadable.
Andy
Like him, I don't like the trailing tildes, and if you do a test, using the form:
...is actually a little faster than: ...which may not make sense to people new to some of the details of unique Spin operators.
The parenthesis are not necessary when using true in that line, but if you change it to: ...it will not compile in BST. This does: