PDA

View Full Version : Variables and port pins



PeterReed
- 22nd September 2009, 10:14
Hi,
Having assigned a variable name to a port pin, eg:

MyPin VAR PORTB.1

I would like then to be able to use another variable to refer to that pin, eg:

x = MyPin
High x

Is there any way to do this as I have tried many ways but nothing seems to work.

--------------------

Alternatively, if this would work, I could do what I want this way:

If a = 1 then
p VAR PORTB.1
ELSE
p VAR PORTB.2
ENDIF

But, when this is compiled, it reports that the variable p in the ELSE section is already an alias implying it is assiging the variable at compile time rather than when the IF statement runs.

-----------------------

Many thanks for any help or suggestions.

Peter

Melanie
- 22nd September 2009, 11:49
VAR is a COMPILE TIME directive... ie it is acted upon by the compiler when your program is compiled and assembled - it is NOT an instruction or COMMAND that is acted upon during execution (RUN TIME).

Using your own example... if you say...

x=MyPin

...you are transferring the state of MyPin into the variable x (assuming you have previously defined x as a variable).

You can have multiple definitions for any given pin...

x var PortB.1
MyPin var PortB.1

Thereafter you can use any one you want within your program. But once defined, your definitions can't be changed or reassigned 'on-the-run'.

PeterReed
- 22nd September 2009, 14:01
Many thanks, Melanie. All understood.

Peter