PDA

View Full Version : How can I use for next like PORTB.MYVARIABLE ???



obaskirt
- 2nd September 2005, 04:02
'-------------[LED BLINKING SHOW]--------------

LED VAR BYTE ' Our variable name is LED.

TRISB = %0000000 ' All pins of port B are output.
PORTB = 0 ' initially turn off all leds.

LED=0 ' Make LED variable initially zero.

Loop:

FOR LED=0 to 7
HIGH PORTB.LED ' --> problem occured.
PAUSE 1000
LOW PORTB.LED ' --> problem occured.
PAUSE 1000
NEXT LED

GOTO Loop

End



IS there any simple way to do this???

mister_e
- 2nd September 2005, 04:08
for LED=0 to 7
HIGH LED
PAUSE 500
LOW LED
PAUSE 500
NEXT

obaskirt
- 2nd September 2005, 05:59
for LED=0 to 7
HIGH LED
PAUSE 500
LOW LED
PAUSE 500
NEXT


My problem is; I can not define PORTB.LED??? and in your example which port did you make high or low? For example, I connected 8 leds to PIC 16F84's PortB. How can you turn on then turn of these leds by using for next loop. Also you can do this by left and right shift operator but I am curious about how can this problem accomplish by using for-next loop. Thankss..

MaurI
- 2nd September 2005, 11:47
i var byte
x var byte

TRISB=0

i=0
begin
For i=0 to 7

Lookup i,[1,2,4,8,16,32,64,128],x
PORTB=x
Pause 200
next i
i=0
goto begin

end


Well in this little sample there is For next so check it out!

And don't use those High and Low if it is possible better use =0, =1 - it will save your code space ;)

CocaColaKid
- 2nd September 2005, 12:05
My problem is; I can not define PORTB.LED??? and in your example which port did you make high or low? For example, I connected 8 leds to PIC 16F84's PortB. How can you turn on then turn of these leds by using for next loop. Also you can do this by left and right shift operator but I am curious about how can this problem accomplish by using for-next loop. Thankss..

low = 0 does the same thing as low portb.0. You can address portb 0-7 and portc 8-15 like this. I'm not sure if you can access other ports in this fashion or not though.

Melanie
- 2nd September 2005, 13:28
See Bouncing Ball example...

http://www.picbasic.co.uk/forum/showthread.php?t=1517

crematory
- 2nd September 2005, 17:30
tou can make it that way:

Code:


TRISB = 0
INTCON = 0

X VAR BYTE

FOR X = 0 TO 7
PORTB.0[X] = 1
PAUSE 500
PORTB.0[X] = 0
PAUSE 500
NEXT X

END

Homerclese
- 3rd October 2005, 18:59
Hello,

Following the thread above, the code below does not work unless the value of k is made a constant as in: SOUND PORTC.5,[115,120,113,118]. I have never been able to use a variable to steer outputs to a specific pin. Any ideas?


pic16f8783

'sound on pin k port c

TRISC= %00000000
k var byte


start:
k=5
SOUND PORTC.0[k],[115,120,113,118]
GOTO START



"I don't know, Marge. Trying is the first step towards failure."

CocaColaKid
- 3rd October 2005, 20:16
You should be able to use:

sound x,[115,120,113,118]

Where is x is between 0-15 with PORTA.0 being 0 and PORTC.7 being 15.

Homerclese
- 4th October 2005, 00:28
WOOHOO!

Thanks, yes that works, but I have never seen it written that ports A and C are linked and addressed this way. So then, PortC.5 is 13? I never would have thought of this. Is that only for the sound command? What about the addressing for port B.







"Asleep at the switch? I wasn't asleep, I was drunk."

Melanie
- 4th October 2005, 03:26
It's all in the PBP Manual, section 4.11 Pins...