PDA

View Full Version : Pin as variable?



dream-
- 14th September 2010, 21:38
Is there a way to set a Pin as a variable?

Something like:


...
myPin = PORTB.1

High myPin
Pause 1000
Low myPin

myPin = PORTA.0

High myPin
Pause 500
Low myPin
...

Using myPin VAR PORTB.1 is not good since I cannot define the variable several times. Am I missing something obvious?

gadelhas
- 14th September 2010, 23:02
Hi;

Yes;

like this;

LED VAR PORTA.1

High led
pause 500
low led

dream-
- 15th September 2010, 02:49
Hi;

Yes;

like this;

LED VAR PORTA.1

High led
pause 500
low led

Thank you for your response, but as I mention in my original post, that is not what I am looking for, since you cannot define the variable repeatedly in the program. If you look at my example I am assigning two different Pins to the same variable. Thank you anyway :)

mackrackit
- 15th September 2010, 05:37
Why do you want to use the same variable name for two different things?

dream-
- 15th September 2010, 20:42
Why do you want to use the same variable name for two different things?

I am not using the same variable for two different things.

I have a subroutine that sends a special signal through a pin, and I need to be able to control which PIN the signal is sent through.

So the easiest way would be to do something like:


myPin = PORTB.1
gosub SendSignal
...
myPin = PORTA.1
Gosub SendSignal
...
myPin = PORTA.0
Gosub SendSignal
...
SendSignal:
...
HIGH myPin
(Do more stuff)
LOW myPin
Pause T
HIGH myPin
T = something
Pause T
Low myPin
(more stuff)
High myPin
Tf = T*something
Pause Tf
Low myPin
...
RETURN

Since the SendSignal routine is quite complex, I would like to implement it this way. I can't use a CASE SELECT either because everytime the routine has to do something with the pin, I would have to have a separate CASE block.

Any ideas?

mackrackit
- 15th September 2010, 21:46
myPin = PORTB.1
Read the state of the pin and stores the value to myPin.

HIGH myPin
Is for making a pin HIGH.

So the way you want to do it will not work.

The only way I see to do what you want is to use an IF/THEN/ELSE block with three condiitons or CASE SELECT with three conditions.

Darrel Taylor
- 15th September 2010, 21:52
Indexing Port Pins (Bruce)
http://www.picbasic.co.uk/forum/showthread.php?t=3753&highlight=port+pin

dream-
- 15th September 2010, 22:32
myPin = PORTB.1
Read the state of the pin and stores the value to myPin.

HIGH myPin
Is for making a pin HIGH.

So the way you want to do it will not work.


Yes, I know it wont work, that's why I am asking if there is a way to do something like that.



The only way I see to do what you want is to use an IF/THEN/ELSE block with three condiitons or CASE SELECT with three conditions.

Right, that's what I said in my previous post. I want to avoid using CASE or IF/THEN blocks because of the number of times I have to invoke the PIN in the routine (In my actual code I don't have just 3 conditions). It is just not practical to have so much redundant code as I need the space for other things.

Thank you anyway, I appreciate your taking the time to look at my problem :)

dream-
- 15th September 2010, 22:33
Indexing Port Pins (Bruce)
http://www.picbasic.co.uk/forum/showthread.php?t=3753&highlight=port+pin

PERFECT!

This is exactly what I was looking for. Thank you Darrel.

mackrackit
- 15th September 2010, 22:34
Do not give up. Darrel came to the rescue again with the link he posted.

dream-
- 15th September 2010, 22:57
Do not give up. Darrel came to the rescue again with the link he posted.

Yes, and I already implemented it!. Works like a charm.

Thank you guys again! :)

(One happy camper glad he didn't have to recode everything in C)