Custom array of ports using array?


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Since portpins rarely move(constants) you could use the LOOKUP statement to get the offset values. Should free up some RAM. The LOOKUP could ofcourse be placed in a subroutine if you need to access it from many different locations in your program. That way saving ROM.
    Code:
    x      var byte
    i       var byte
    
    main:
    for i = 0 to 3
    '               a  b  c  d
    '               0  6  4  2
         LOOKUP i, [0,14,20,26], x
         porta.0[x]=1
         PAUSE 1000
         porta.0[x]=0
         PAUSE 300
    next i
    /Ingvar

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile Sweet

    Nice improvement! - The code for what blaine originally wanted to do is getting pretty clean considering it is an undocumented feature.

    Best,

    Paul

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nice job Paul & Ingvar..;o}

    Yet another version.
    Code:
        DEFINE OSC 4
    
    '   BASIC/ASM version = 172 words
        
        x   var word
        i   var byte
        RelayNum var PORTA
        
    '    High byte = FSR / Low byte = port pin (or multiple pins)
        RLY1 CON %0000010100000001 ' PORTA|Bit0
        RLY2 CON %0000011001000000 ' PORTB|Bit6
        RLY3 CON %0000011100010000 ' PORTC|Bit4
        RLY4 CON %0000100000000100 ' PORTD|Bit2
        
        ADCON1 = 7
        PORTA = 0 : PORTB = 0 : PORTC = 0 : PORTD = 0
        TRISA = 0 : TRISB = 0 : TRISC = 0 : TRISD = 0
        
    ASM
    RelayOn macro
        movf  _x+1,w ; high byte = pointer to port file reg
        movwf FSR    ; load FSR
        movf  _x,w   ; low byte = port bit to change
        xorwf INDF,f ; toggle port pin
        endm
    ENDASM
    
    ASM
    RelayOff macro
        movf  _x,w   ; reload port pin to toggle
        xorwf INDF,f ; do it
        endm
    ENDASM
                             
    main:
        for i = 0 to 3
            LOOKUP2 i, [RLY1,RLY2,RLY3,RLY4], x ' lookup file reg & XOR pattern
            @ RelayOn
            PAUSE 500
            @ RelayOff
            PAUSE 500
        next i
        
        END
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    I agree, good stuff!

    Here's another one.
    Code:
    INCLUDE "VirtualPort.bas"
    
    Relays  VAR BYTE : Relays = 0
    
    ASM
    RelayPort  macro
        Vpin  0, PORTB, 6  ; RELAY1
        Vpin  1, PORTC, 4  ; RELAY2
        Vpin  2, PORTD, 2  ; RELAY3
      endm
    
      OutputPort  RelayPort    ; Set Port to OUTPUT
    ENDASM
    Then, here's a test loop to cycle thru the relays...
    Code:
    i  VAR BYTE
    
    Main:
        for i = 0 to 2
            Relays = DCD i
            @  WritePort _Relays, RelayPort
            PAUSE 500
        next i
    Goto Main
    Code size = 104 words, 65 without the PAUSE.

    or you can just...
    Code:
    Relays = %010
    @  WritePort _Relays, RelayPort
    to turn on RELAY2 by itself.
    Code size = 21 words.

    http://www.pbpgroup.com/Vport/VirtualPort.bas.txt

    HTH,
        DT

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile Amazing yet again ...

    Bruce, Darrel,

    You guys are amazing yet again! I continue to learn and what good fun.

    Paul

    Edit - I am an ASL student (Assembly Second Language) student and removed some code from this post that was not correct.-pb
    Last edited by paul borgmeier; - 15th June 2006 at 09:53.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Just keeps getting better & better ehh...;o}

    Nice work Darrel.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Talking Bruce and Darrel Cheated!!!

    Bruce and Darrel,
    You guys cheated(lol). Paul and Ingvar got the job done tidely with PBP. You had to resort to Assembly.

    This is what I love about this forum. Bright, capable folks working together to make a good product (PBP) work even better! I knew in my initial post that there just had to be a way to do this, it just was not documented and was beyond my basic skills. Great learning oppurtunity. I think this is worth putting in the FAQ (in some form) for others to reference later.

    Even though it wasn't my post originally, thanks guys for the great lessons.

    Cheers,
    Steve

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 05:46
  3. Custom array of pins
    By bmagistro in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2009, 00:15
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 16:04
  5. Making Array of two ports
    By John7 in forum General
    Replies: 3
    Last Post: - 5th March 2005, 03:20

Members who have read this thread : 2

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