How to write port names into array ?


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124

    Default How to write port names into array ?

    Hello.

    I have a code, where port names are assigned to specific variables, like this:

    Code:
    AC5 var PORTC.5
    AC4 var PORTC.4
    AC3 var PORTB.3 
    AC2 var PORTB.1
    AC1 var PORTB.5 
    
    AR1 var PORTB.6
    AR2 var PORTC.7
    AR3 var PORTB.2 
    AR4 var PORTB.0 
    AR5 var PORTB.4 
    AR6 var PORTB.7
    AR7 var PORTC.6
    I want to modify code in te way, to store this data into array, so I can read sequentally with FOR-NEXT. How should I add port names into array members?

    Say my array name is ROW, code should look like:

    ARRAYWRITE ROW, [what maxlength?, what label?]

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    There is good info here addressing your question, both better written and more correct than anything I may post. It explains how to read and write bits in bytes, bytes in words, bits in arrays, etc.
    Last edited by Amoque; - 12th December 2013 at 03:58.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    Thanks, but it does not answers.

    In fact, another memeber there asks exact same question, but gets no answer.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?


  5. #5
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    Sure, this is way better, but still not exactly what I want. Since it utilizes loop and constant subroutine calls. I want to have defined the array in the beginning of the code, and access it as needed.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    So are you looking to . . .
    AC5 var PORTC.5
    AC4 var PORTC.4
    AC3 var PORTB.3
    AC2 var PORTB.1
    AC1 var PORTB.5

    AC = %00010101
    and then have the listed ports go high according to the declaration above?
    If SO try AC = ~~%00010101
    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.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    var byte LEDS[4] 'declare array with 4 members
    LEDS[0]=3
    LEDS[1]=8
    LEDS[2]=12
    LEDS[3]=9 ' put port numbers into array

    FOR A=0 to 3 ' make increment
    high leds[A] 'set high port number, stored in specific cell of LEDS array. could try high portb.0[leds[a]]
    PAUSE 1000 'wait some time,
    low LEDS[A] ' turn led off might be low leds[A]
    PAUSE 1000
    NEXT


    see port indexing this forum just a few days ago or page 30 of pbp manual



    you could also use lookup
    Last edited by richard; - 14th December 2013 at 08:55. Reason: more info and another idea

Similar Threads

  1. Setup port pins into an array
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 25th April 2013, 16:24
  2. Assign different port bits to an array?
    By vamtbrider in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th November 2010, 02:40
  3. Why (or how to) make a port array for OW
    By Roy___ in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd February 2009, 23:30
  4. array and port
    By piombazzo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th November 2008, 20:58
  5. Replacing an ARRAY with EEPROM write to save space?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th March 2005, 18:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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