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


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    I'm referring to portb.1 or whatsoever as a hardware endpoint, you - as program statement, this is the main difference.

    Ok, here's example in sinclair basic, just consider that there's no HIGH/LOW statements, thres OUT statement, with syntax OUT X,Y, where X=portnumber, Y=portstate

    Let's say, I have leds connected to ports 3,8,12,9, and I want to light them up in listed sequence.

    Code:
    DIM LEDS(4) 'declare array with 4 members
    LET LEDS(1)=3
    LET LEDS(2)=8
    LET LEDS(3)=12
    LET LEDS(4)=9 ' put port numbers into array
    
    FOR A=1 to 4 ' make increment
    OUT LEDS(A), 1' set high port number, stored in specific cell of LEDS array. 
    PAUSE 1 'wait some time, in sinclair basic, pause is in seconds, not ms
    OUT LEDS(A), 0' turn led off
    NEXT A ' loop

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,607


    Did you find this post helpful? Yes | No

    Default Re: How to write port names into array ?

    Hi,
    I'm referring to portb.1 or whatsoever as a hardware endpoint, you - as program statement, this is the main difference.
    No, I'm referring to PortB.1 or whatever as an adress in "memory".

    OK, that Sinclair example stores the adress of the port you're setting in the array and is not the same thing as you doing HIGH Array[1] in PBP even if it had worked.

    Code:
    myArray VAR BYTE[4]
    myArray[0] = 2      ' Offset from PortA.0 to PortA.2
    myArray[1] = 8      ' ....PortB.0
    myArray[2] = 9      ' ....PortB.1
    myArray[3] = 18     ' ....PortC.2
    
    i VAR BYTE
    
    Main:
    for i = 0 to 3
        PortA.0[myArray[i]] = 1
        PAUSE 500
    NEXT
    
    FOR i = 0 to 3
        PortA.0[myArray[i]] = 0
        PAUSE 500
    NEXT
    Goto Main
    /Henrik.

  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 ?

    Yes, it stores address, and then when reading from array, sets apropriate numbered port HIGH, by statement OUT.

    OUT LEDS(A), 1

    reads value stored in LEDS(A) array part, and then outputs "1" into port with that #.

  4. #4
    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 Richard, your example seems to do the thing I want to do. But I don't have PBP at hands, will have to check it on monday.

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