Confused by Port/Pin Naming

thunderace7

New Member
Hi. I'm a bit confused by port/pin naming conventions. For example:

symbol sensor1=C.1
readtemp sensor1,intemp


works but:

symbol sensor1=pinC.1
readtemp sensor1,intemp


causes a syntax error.

Yet,

symbol breakcontact=C.1
let break=breakcontact


gives no syntax error but doesn't work unless I change it to

symbol breakcontact=pinC.1
let break=breakcontact


Can anyone explain why, please?
 

Aries

New Member
I'm sure others can go into much more detail, but essentially "C.1" etc are just numbers, whereas "pinC.1" etc are variables.

So,
readtemp uses a number to indicate which pin is being read
let break = xyz is expecting a variable (it wouldn't be much use if it always gave the number of the pin, which is why using "C.1" compiles but doesn't do what you want)
 

WhiteSpace

Well-known member
@thunderace7 - I had the same question a few days ago, and had the following very helpful explanation from @lbenson:
“SYMBOL TSOPinput1 = C.7” provides a symbolic name for a pin which you can use in, for instance, HIGH or LOW or PWM commands.

“SYMBOL TSOPinput1pin = pinC.7” provides a symbolic name which can be used in a statement which reads the value (0 or 1) of an input pin, e.g.,
IF TSOPinput1pin = 1 THEN . . .

It's confusing that you have to use different symbols for input or output, but part of that requirement is that "C.7" resolves to a number--15--and it wouldn't make sense and wouldn't be what you intend if you were to write a statement which the interpreter decodes as "IF 15 = 1 THEN".

If in the simulator, you run the following line, it will result in C.7 blinking:

DO: HIGH 15: PAUSE 500: LOW 15: PAUSE 500: LOOP
 

thunderace7

New Member
Thanks all for your replies. I've been away for a few days and I've only just seen them.
The statement that C.7 resolves to a number (15) makes sense because I was using C.0 and C.1 and these gave results of 8 and 9, I think, when I was expecting a 1 or a 0. All very confusing at the time but a little clearer now. I'll take a while to go over your replies and really get to understand them (I hope).
 

thunderace7

New Member
A follow-up question or 3 regarding C.7 resolving as the number 15:
Where do these numbers come from? Is it because C.7 is a pin designation or is it something arithmetic?
Do all of the pins have associated numbers?
Thanks.
 

lbenson

Senior Member
Do all of the pins have associated numbers?
Yes. As available on the chip, B.0-B.7, 0-7; C.0-C.7, 8-15; A.0-A.7, 16-23; D.0-D.7, 24-31.

It has to do with how the interpreter designates pins, and the particular numbering probably derives from an historical context. For any pin, you can see the number it corresponds to by running code like the following in the simulator: sertxd(#A.0,cr,lf)

This allows you to use a variable to specify an output pin. In the simulator, this will turn pins A.0 and A.1 green, and then B.0 through B.7:
Code:
b1=A.0
b2=17
high b1
high b2
for b3=0 to 7
  high b3
  pause 500
next b3
do: loop ' linger so you can see the pins change color
 
Last edited:

Aries

New Member
Alternatively, use something like this:
Code:
symbol MyC1 = C.1
symbol MyC2 = C.2
... (repeat for other pins)
Then compile it ("check syntax") and look at the Constants window.
 
Top