View Full Version : How to index Port variable
jpadin1
- 14th February 2010, 17:07
In this short program I am trying to index a variable assigned to a port in order to turn on LEDs by indexing it with a counter. But the compiler gives me a: "Bad variable modifier" error. In other words it doesn't like LED.i it wants a number (e.g. LED.0, LED.1, etc) instead of variable.
Has anyone done this?
LED var PORTD ' Alias PORTD.0 to LED
i VAR BYTE
mainloop:
for i = 0 to 7
High LED.i ' Turn on LED connected to PORTD.i
Pause 250 ' Delay for .5 seconds
Low LED.i ' Turn off LED connected to PORTD.i
Pause 750 ' Delay for .5 seconds
Next i
Goto mainloop ' Go back to loop and blink LED forever
End
Byte_Butcher
- 14th February 2010, 17:33
try....
LED.0[i]
steve
Archangel
- 14th February 2010, 17:45
LED var PORTD ' Alias PORTD.0 to LED
i VAR byte
mainloop:
for i = 0 to 7
High LED ' Turn on LED connected to PORTD.i
Pause 250 ' Delay for .5 seconds
Low LED' Turn off LED connected to PORTD.i
Pause 750 ' Delay for .5 seconds
Next i
Goto mainloop ' Go back to loop and blink LED forever
End
Hi Jpadin1,
Byte is a bit array, lose the modifier and it should do what you want see snippet above
or
HIGH LED[i]
pause 750
LOW LED[i]
pause 750
Check this link out:
http://www.picbasic.co.uk/forum/showthread.php?t=8876
jpadin1
- 14th February 2010, 19:41
Hello and thanks for the reply. I try this shown below but the array indexing is not working either. I can turn it on using the .5 but I can't turn it off using i = 5 and LED[i]
LED var PORTD ' Alias PORTD all LEDS
i VAR byte
i = 5
mainloop:
' for i = 0 to 7 step 1
'High LED[i] ' Turn on LED connected to PORTD.i
High LED.5 ' Turn on LED connected to PORTD.i
Pause 250 ' Delay for .5 seconds
'Low LED[i] ' Turn off LED connected to PORTD.i
Low LED[i] ' Turn off LED connected to PORTD.i
Pause 750 ' Delay for .5 seconds
' Next i
Goto mainloop ' Go back to loop and blink LED forever
End
flotulopex
- 17th February 2010, 10:36
Counter VAR BYTE
Output VAR PORTB.0
START:
FOR Counter = 0 to 7
Output[Counter] = 1 'High
PAUSE 100
Output[Counter] = 0 'Low
PAUSE 100
NEXT
GOTO START:
END
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4002&stc=1&d=1266402539">
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.