-
Uber noob needs clarity!
Hello all,
Just to keep things simple and not going into alot of details here is my question:
Can you use a variable in the port settings?
Example....
main:
for I = 0 to 7
if portb.I = 1 then xxxxx
next I
goto main
If so how do you setup the variable? (I var byte)
I have tired and tried and it always says:
"ERROR Line X: Bad variable modifier: .I."
What I am trying to do is scan a port for changes with out using 8 seperate If...then lines.
Any help is always appreciated.
Thanks,
Bill12780
SETUP:
16f873
easypic4 dev board
picbasic pro v2.47
using PM as compiler
-
May I suggest this
UNTESTED, but with no compile error.
You can try
main:
for I = 0 to 7
if (portb & DCD I) = 1 then xxxxx
next I
goto main
J-P
-
See if this helps....
Hi Bill12780,
Take a look at this post and see if it helps.
Bits, Bytes Words and Arrays - Melanie
http://www.picbasic.co.uk/forum/showthread.php?t=544
-Adam-
-
I think this is what you are looking for. In the manual under "Ports and other Registers".
Code:
anyvar = PORTB & $0f 'Isolate lower 4 bits of PORTB and place result into anyvar
$0f = 00001111
$00ff = 11111111
Now you can check "anyvar" for changes.
-
Thanks a bunch man!
Thanks everyone...
These are some really good idea's. I had to "walk away" for awhile. I will read Melanie's post(man she is a wealth of knowledge....Bet she was born with a PBP manual in her hand!), try a few things. and get back with you all tonight.
Thanks for the tips.
Bill12780
-
This will work;
Code:
X VAR BYTE
main:
for X = 0 to 7
if PortB.0[X] = 1 then xxxxx
next X
goto main
PortB.0 <-- zero after PortB indicates you're dealing with a bit.
PortB.0[X] <-- [X] = the bit index pointer.
-
bruce is the man!
"PortB.0 <-- zero after PortB indicates you're dealing with a bit.
PortB.0[X] <-- [X] = the bit index pointer."
Thanks bruce that is a brilliant little tidbit of information (for a noob like me)that I probly glazed over in the manual 20 times and it never stuck..
Thanks! I knew it could be done like that...Just not smart enought to figure out how! hahha
thanks again!
Bill12780