Need help on pic connect 4


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    19

    Default Need help on pic connect 4

    Im doing a pic based connect 4 using a led matrix for my senior project in high school. I am very novice at coding so please make sure to keep that in mind while critiquing my work. All i want it to do for now is to have a light at the top left to be on and when you push a button it falls down and stops at the bottom,then when you press a button again another one falls on top of that and so on. I have the first led falling but after the led stops it starts stacking until the whole left column is on. I don't know how this is possible when i have
    if (b.0[rows]=0)then fall=0 : goto main
    it acts if it keeps going through the loop main. Any suggestions?


    Code:
    fall var byte
    Shift var byte
    pb1 var porta.0
    pb2 var porta.1
    rowvar var byte
    b var byte
    rows var byte
    stack var byte
    row1 var byte
    row2 var byte
    row3 var byte
    row4 var byte
    row5 var byte
    row6 var byte
    row7 var byte
    
    
    
    
    
    
    
    
    
    
    
    
    ansel=0
    anselh=0
    fall = 0
    Shift = 7
    down=1
    portb=b
    rows=0
    stack=0
    
    
    
    
    
    
    
    
    trisA=111111
    trisb=000000
    trisc=000000
    trisd=000000
    b=~000000
    portc=000001
    portd=000000
    
    
    
    
    
    
    
    
    
    
       loopa:
          portb=b+b1
           portb=b
       
        pause 500
        if (pb1==0 & b.7==0) then fall=1    
          if (fall==1) then 
            b.0[Shift] = 1
            b.0[Shift - 1] = 0
            Shift = Shift - 1
          endif
      if (b.0[rows]=0)then fall=0 : goto main
        
        goto loopa
              
     
          main:
         portb=b
           
         
          rows=rows+1
                if rows=6 then rows=0
            
           if stack=6 then stack=5
               
                
         
         if stack = 0 then b=~000010
         if stack = 1 then b=~000110
         if stack = 2 then b=~001110
         if stack = 3 then b=~011110
         if stack = 4 then b=~111110
         if stack = 5 then b=~111110
         portc=000001 
               
         stack=stack+1  
                   
    goto loopa
    Last edited by lockjawz; - 16th November 2011 at 18:44.

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need help on pic connect 4

    This line in your code ...
    Code:
    if (b.0[rows]=0)then fall=0 : goto main
    is the same as...

    Code:
    if (b.0[rows]=0)then fall=0 
    goto main
    you probably need this...
    Code:
    if (b.0[rows]=0)then 
      fall=0 
      goto main
    endif
    That way the "goto main" will only be executed if the preceding IF statement is true

    from the PBP manual...
    4.13. Multi-statement Lines



    In order to allow more compact programs and logical grouping of related commands, PBP supports the use of the colon

    ":" to separate statements placed on the same line. Thus, the following two examples are equivalent:



    W2 = W0
    W0 = W1
    W1 = W2



    is the same as:



    W2 = W0 : W0 = W1 : W1 = W2



    This does not, however, change the size of the generated code.
    Last edited by Heckler; - 16th November 2011 at 20:12.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

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