Assign different port bits to an array?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    15

    Question Assign different port bits to an array?

    I have several outputs that are on different ports. I would like to use an array to cycle through the outputs, turning then on and off one at a time.

    Is there a way to assign different port bits to an array?
    Something like this: (I know this won't work but this kind of shows what I want to do)

    Code:
    '***********************************************                                        
    '* Configure Variables for Lights
    '***********************************************
        Lights    VAR Bit[NoLights]
        Lights[0] VAR PORTB.1
        Lights[1] VAR PORTE.2
        Lights[2] VAR PORTE.1
        Lights[3] VAR PORTE.0
        Lights[4] VAR PORTA.5
        Lights[5] VAR PORTA.4
    Then I would do something like this:

    Code:
    'turn off all the lights
        for x = 0 to NoLights
            Lights[x] = 0        
        next x
    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Hi vamtbrider,
    read these posts for your answer:
    http://www.picbasic.co.uk/forum/showthread.php?t=1339
    http://www.picbasic.co.uk/forum/show...t=4074&p=22065

    Use this tool to search this forum, it is a special Google engine, and you can also search 2 or 2 letter items:
    http://www.google.com/custom?hl=en&c...ch&sitesearch=
    Last edited by Archangel; - 29th November 2010 at 19:35.
    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.

  3. #3
    Join Date
    Mar 2010
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Joe S.

    Thanks for the link, that was exactly what I was looking for. I haven't played with marcos much but this will be a good start.

    I have been searching for a couple hours using the forum search and wasn't finding any leads.

    I will now use the google link you sent.

    Thanks again for pointing me in the right direction.

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


    Did you find this post helpful? Yes | No

    Default

    <h1>Super !</h1>
    Happy it helped ! So many times, it seems my help isn't, but I try.

    "Trying is the first step toward failure". Homer Simpson
    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.

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    This should also work for what you are trying to do.

    Code:
    ' PORT OFFSETS
    '
    '
    '"A.0",0
    '"A.1",1
    '"A.2",2
    '"A.3",3
    '"A.4",4
    '"A.5",5
    '"A.6",6
    '"A.7",7
    '"B.0",8
    '"B.1",9
    '"B.2",10
    '"B.3",11
    '"B.4",12
    '"B.5",13
    '"B.6",14
    '"B.7",15
    '"C.0",16
    '"C.1",17
    '"C.2",18
    '"C.3",19
    '"C.4",20
    '"C.5",21
    '"C.6",22
    '"C.7",23
    '"D.0",24
    '"D.1",25
    '"D.2",26
    '"D.3",27
    '"D.4",28
    '"D.5",29
    '"D.6",30
    '"D.7",31
    '"E.0",32
    '"E.1",33
    '"E.2",34
    '"E.3",35
    '"E.4",36
    '"E.5",37
    '"E.6",38
    '"E.7",39
    '"F.0",40
    '"F.1",41
    '"F.2",42
    '"F.3",43
    '"F.4",44
    '"F.5",45
    '"F.6",46
    '"F.7",47
    '"G.0",48
    '"G.1",49
    '"G.2",50
    '"G.3",51
    '"G.4",52
    '"G.5",53
    '"G.6",54
    '"G.7",55
    '"H.0",56
    '"H.1",57
    '"H.2",58
    '"H.3",59
    '"H.4",60
    '"H.5",61
    '"H.6",62
    '"H.7",63
    '"J.0",64
    '"J.1",65
    '"J.2",66
    '"J.3",67
    '"J.4",68
    '"J.5",69
    '"J.6",70
    '"J.7",71
         
         For X = 0 to 10   
      
            Lookup X,[0,1,2,5,9,10,11,12,13,15,19,70],PortValue ; Put the bits you want to modify here, use table above
            
            Lookup X,[1,1,0,1,1,0,1,0,0,0,0],State ; put a 1 or a 0 here to determine state.
    
            TRISA.0(PortValue) = 0               ;Make it an output  
            PORTA.0(PortValue) = State        ;Set/Clear the bit             
         Next X
    Charles Linquist

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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