Making Array of two ports


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Default Making Array of two ports

    Hi all PBP Artists!
    i'm trying to create an array of two ports -porta and portc (16f630)

    Output VAR bit[9]

    SYMBOL Output[0] = PORTA.0
    SYMBOL Output[1] = PORTA.1
    SYMBOL Output[2] = PORTA.2
    SYMBOL Output[3] = PORTA.3
    SYMBOL Output[4] = PORTA.4
    SYMBOL Output[5] = PORTC.0
    SYMBOL Output[6] = PORTC.1
    SYMBOL Output[7] = PORTC.2
    SYMBOL Output[8] = PORTC.3
    SYMBOL Output[9] = PORTC.4

    for x = o to 9
    Output[x] = 1
    next x

    it doesn't work! where is my mistake?

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Question

    May be help on the thread " Word arrays and EEPROM"

    Alain

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    3 things:
    1. your Array size must be 10 instead of 9
    2. for to next loop=o or loop=0 ?
    3. you didn't set your TRIS register. TRISC=0 : TRISA=0

    BUT i don't know if you can address i/o in array...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi John,

    There's no way to do that with standard PBP commands. Normal PBP arrays must be completely contiguous. However, we can create a new command with a little assembly language.

    This isn't exactly what you were looking for, but it does accomplish the exact same thing.

    Put this code near the top of your program.
    Code:
    '------[ PortOut macro ]----------------
    Temp_idx    VAR  byte
    Temp_State  VAR  BIT
    
    ASM
    PortOut  macro idx, state
        MOVE?BB idx, _Temp_idx
        MOVE?CT state, _Temp_State
    EndASM
        if Temp_idx < 5 then
            PORTA.0[Temp_idx] = Temp_State
        else
            Temp_idx = Temp_idx - 5
            PORTC.0[Temp_idx] = Temp_State
        endif
    @   endm
    '---------------------------------------
    Then you can simply do this...
    Code:
    for x = 0 to 9
    @   PortOut  _X, 1  
    next x
    With this code, the state("1" in this case) must be a constant. I did it that way just to be consistant with your request.

    If you wanted to use a variable instead, simply change this line in the PortOut routine...

    MOVE?CT state, _Temp_State

    -- changed to --

    MOVE?TT state, _Temp_State

    HTH,
    &nbsp;&nbsp;&nbsp;Darrel

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. RS232 receive an array (packet)
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2008, 05:02
  4. Custom array of ports using array?
    By blainecf in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 18th June 2006, 01:43
  5. making ports outputs on a 12F629
    By bartman in forum mel PIC BASIC
    Replies: 2
    Last Post: - 14th November 2004, 17:47

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