How to index Port variable


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Default How to index Port variable

    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

  2. #2
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323

    Default

    try....

    LED.0[i]


    steve
    Last edited by Byte_Butcher; - 14th February 2010 at 18:36. Reason: didn't do that right...

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,817

    Default

    Code:
    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
    Code:
    HIGH LED[i]
    pause 750
    LOW LED[i]
    pause 750
    Check this link out:
    http://www.picbasic.co.uk/forum/showthread.php?t=8876
    Last edited by Archangel; - 14th February 2010 at 18:58.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Feb 2010
    Posts
    2

    Default I tried that but ...

    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

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    794

    Default This works

    Code:
    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=126640253 9">
    Attached Images Attached Images  
    Roger

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 01:06
  2. accessing ports pins using an index variable
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th March 2008, 21:36
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  5. Question on assigning pin port to variable
    By khufumen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st June 2005, 23:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts