PDA

View Full Version : Uber noob needs clarity!



bill12780
- 20th July 2007, 02:35
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

GrandPa
- 20th July 2007, 03:42
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

Pic_User
- 20th July 2007, 03:49
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-

mackrackit
- 20th July 2007, 05:00
I think this is what you are looking for. In the manual under "Ports and other Registers".



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.

bill12780
- 20th July 2007, 16:05
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

Bruce
- 20th July 2007, 19:02
This will work;


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.

bill12780
- 23rd July 2007, 21:40
"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