Setup port pins into an array


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Setup port pins into an array

    using hendric example as base i know repeating the code for each port group and offset it will work , but its not a good way to code for many port groups using the same code , need a nice way to point to the i/o pin groups,

    Code:
    A_PortOffset VAR BYTE
    B_PortOffset VAR BYTE
    C_PortOffset VAR BYTE
    
    For T = 0 to 2
      LOOKUP T, [0,2,3], A_PortOffset
      FOR Cycles = 1 TO PulseCnt
        PORTA.0 [A_PortOffset] = 1
        PAUSEUS 100
        PORTA.0 [A_PortOffset] = 0
        PAUSEUS 200
      NEXT Cycles
      PAUSEUS 350
    NEXT T
    
    T= 0
    For T = 0 to 1
      LOOKUP T, [2,5], B_PortOffset
      FOR Cycles = 1 TO PulseCnt
        PORTB.0 [B_PortOffset] = 1
        PAUSEUS 100
        PORTB.0 [B_PortOffset] = 0
        PAUSEUS 200
      NEXT Cycles
      PAUSEUS 350
    NEXT T
    
    T= 0
    For T = 0 to 3
      LOOKUP T, [0,1,3,5], C_PortOffset
      FOR Cycles = 1 TO PulseCnt
        PORTC.0 [C_PortOffset] = 1
        PAUSEUS 100
        PORTC.0 [C_PortOffset] = 0
        PAUSEUS 200
      NEXT Cycles
      PAUSEUS 350
    NEXT T

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


    Did you find this post helpful? Yes | No

    Default Re: Setup port pins into an array

    Hi,
    Surely THIS can't be for the 12F683 can it?
    Anyway, if you open up the datasheet for the actual PIC and look memory map you'll see (always doublecheck !) that all the Port registers are consecutive in memory. This means that if you, for example, do PortA.0[14] = 1 you'll actually set PortB.6 because PortB.6 is 14 bits "away" from PortA.0 - pretty cool.
    Code:
    For i = 0 to 8   ' 9 output
      Lookup i, [0, 2, 3, 10, 13, 23, 24, 26, 28], PortOffset
      PortA.0[PortOffset] = 1
    NEXT
    Again, make sure you check the datasheet for the actual PIC!

    /Henrik.

Similar Threads

  1. Pointers To Port Pins ?
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd December 2009, 21:38
  2. Variables and port pins
    By PeterReed in forum mel PIC BASIC
    Replies: 2
    Last Post: - 22nd September 2009, 15:01
  3. Custom array of pins
    By bmagistro in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2009, 00:15
  4. Array of pins
    By The Master in forum General
    Replies: 6
    Last Post: - 2nd December 2007, 01:21
  5. Port A pins
    By Eric123 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 22nd August 2006, 04:25

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