16f887 connect 4 - help needed


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

    Post 16f887 connect 4 - help needed

    I am having a problem on my connect 4 game that uses a bi-color matrix. I am able to drop 1 color dot down and stack that same color until it gets to the top. The problem is with my matrix you cant have difrent color dots in the same column. So i think i would need to flash the 2 colors(Portc and portd) at different times by changing them from outputs to inputs really fast.

    I tried putting a gosub flash (flash being a loop) in different locations in my code so it would constantly flash anywhere it was in my code.

    here is my flash loop

    flash:
    trisc=%00000000
    trisd=%11111111
    pauseus 1
    trisc=%11111111
    trisd=%00000000
    pauseus 1
    return

    The problem is when i add this it causes a red checker to be on when i power up(when it should be off). Then i try to press my drop button and it wont fall and if i click the button to select the red checker then it turns off completely. I have no problem with the green checker.
    I don't know what the problem is, i have a feeling it is very simple but i just cant figure it out any suggestions?

    If you have any problems understanding my code please ask and i will try to explain it to you.


    Code:
    fall var byte
    Shift var byte
    pb1 var porta.0
    pb2 var porta.1
    pb3 var porta.2
    rowvar var byte
    b1 var byte
    b var byte
    c var byte
    c1 var byte
    c2 var byte
    c3 var byte
    c4 var byte
    d1 var byte
    d2 var byte
    d3 var byte
    d4 var byte
    d 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
    shift1 var byte
    shift2 var byte
    shift3 var byte
    shift4 var byte
    shift5 var byte 
    shift6 var byte
    shift7 var byte
    fall2 var byte
    fall3 var byte
    fall4 var byte
    fall5 var byte 
    fall6 var byte
    fall7 var byte
    greenled var byte
    redled var byte
    
    
    down var byte
    counts var byte
    'define osc 8
    
    
    'portc=red
    'portd=green
    
    
    
    
    
    
    
    'osccon =%01110101
    counts=0
    ansel=0
    anselh=0
    
    fall = 0
    fall2=0
    fall3=0
    fall4=0
    fall5=0
    fall6=0
    fall7=0
    
    Shift = 7
    shift2=7
    shift3=7
    shift4=7
    shift5=7
    shift6=7
    shift7=7
    
    greenled=0
    redled=0
    
    
    
    portb=b+b1
    rows=1
    stack=1
    
    down=1
    
    
    
    
    
    
    
    
    
    
    trisA=%11111111
    trisb=%00000000
    trisc=%00000000
    trisd=%00000000
    
    
    
    
     
     b1=%11111111
        b= %01111111
    portc=%00000000
    portd=%00000000
    
        portb=b1+b
      
     
    
    
    
    
    looppick:
     if pb2=0 then goto red
     if pb3=0 then goto green
    gosub flash
     
     goto looppick
     
    red:
    b1=%11111111
        b= %01111111
    portc=%00000001
    portd=%00000000
     redled=redled+1
    gosub flash
    
    goto loopa
     
     green:
    b1=%11111111
       b= %01111111
    portd=%00000001
     portc=%00000000
     greenled=greenled+1
    gosub flash
     
    goto loopa
    
    
    
    
    
    
       loopa:
          portb=b1+b
          
         gosub flash
      
      
          
          
           
       
        pause 500
                        
        
    
        
        if (pb1==0 & b.7==0) then fall=1    
          if (fall==1) then 
            b1.0[Shift] = 1
            b1.0[Shift - 1] = 0
            Shift = Shift - 1
          endif
          
          if (b1.0[stack]=0)then fall=0:goto main
        
          
         
      
          goto loopa
          
         
          
           
          
    
          
         gosub flash 
          
         main:
          'fall=0
          'fall2=0
          'fall3=0
          'fall4=0
          'fall5=0
          'fall6=0
          'fall7=0
          portb=b1+b
          
         
          
         
     if down=0 then b1=%11111111 : b=%01111111    
     if down = 1 then b1=%11111101 : b=%01111111
     if down = 2 then b1=%11111001 : b=%01111111
     if down = 3 then b1=%11110001 : b=%01111111
     if down = 4 then b1=%11100001 : b=%01111111
     if down = 5 then b1=%11000001 : b=%01111111
     if down = 6 then b1=%10000001 : b=%01111111
    
         stack=stack+1
         down=down+1
         if down=7 then down=6
     
     counts=counts+1    
     if counts=1 then goto loopb
     if counts=2 then goto loopc
     if counts=3 then goto loopd
     if counts=4 then goto loope
     if counts=5 then goto loopf
     if counts=6 then goto loopg
    
         
          
       loopb:
      
     
         portb=b1+b
           gosub flash
        pause 500
        if (pb1==0 & b.7==0) then fall2=1    
          if (fall2==1) then 
            b1.0[Shift2] = 1
            b1.0[Shift2 - 1] = 0
            Shift2 = Shift2 - 1
          endif
          
          if (b1.0[stack]=0)then fall2=0:goto main
          goto loopb
          
          loopc:
         gosub flash
         
      portb=b1+b
           
        pause 500
        if (pb1==0 & b.7==0) then fall3=1    
          if (fall3==1) then 
            b1.0[Shift3] = 1
            b1.0[Shift3 - 1] = 0
            Shift3 = Shift3 - 1
          endif
          
          if (b1.0[stack]=0)then fall3=0:goto main
          goto loopc
          
              loopd:
              gosub flash
             
              portb=b1+b
           
        pause 500
        if (pb1==0 & b.7==0) then fall4=1    
          if (fall4==1) then 
            b1.0[Shift4] = 1
            b1.0[Shift4 - 1] = 0
            Shift4 = Shift4 - 1
          endif
          
          if (b1.0[stack]=0)then fall4=0:goto main
          goto loopd
          
              loope:
              gosub flash
            
       portb=b1+b
           
        pause 500
        if (pb1==0 & b.7==0) then fall5=1    
          if (fall5==1) then 
            b1.0[Shift5] = 1
            b1.0[Shift5 - 1] = 0
            Shift5 = Shift5 - 1
          endif
          
          if (b1.0[stack]=0)then fall5=0:goto main
          goto loope
          
            loopf:
            gosub flash
            
             portb=b1+b
           
        pause 500
        if (pb1==0 & b.7==0) then fall6=1    
          if (fall6==1) then 
            b1.0[Shift6] = 1
            b1.0[Shift6 - 1] = 0
            Shift6 = Shift6 - 1
          endif
          
          if (b1.0[stack]=0)then fall6=0:goto main
          goto loopf
          
          loopg:
    
         gosub flash
       
      
          portb=b1+b
           
        pause 500
        if (pb1==0 & b.7==0) then fall7=1    
          if (fall7==1) then 
            b1.0[Shift7] = 1
            b1.0[Shift7 - 1] = 0
            Shift7 = Shift7 - 1
          endif
          
          if (b1.0[stack]=0)then fall7=0:goto main
          goto loopg
    
    flash:
    trisc=%00000000
    trisd=%11111111
    pauseus 1
    trisc=%11111111
    trisd=%00000000
    pauseus 1
    return
    
          
        
          
          
      end

  2. #2
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62


    Did you find this post helpful? Yes | No

    Default Re: 16f887 connect 4 - help needed

    Try using the "PULSEOUT" or the "FREQOUT" command for flashing.

    Not quite sure how big your matrix is but standard connect 4 grid is 42 (6x7).

    Thinking more in depth to your project you could take it a step further and make it a hell of a lot easier on yourself by implementing a MAX6952 Matrix controller.

    but I like your project hope to see working video of it when complete.

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