Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SWORDFISH CODE NOT MINDING

Status
Not open for further replies.

MrDEB

Well-Known Member
Be hacking at this swordfish basic code and inserting led markers but code still does not declimate the numbers (SEE SUD ROUTINES)
the COUNTER is working but still the matrix is not displaying correctly. I had a similar code that worked but with a harddrive issue most is gone. Trying to rebuild working code.
Am sure it is something simple but I have yet to get the correct configuration
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/18/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/14/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/12/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/10/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/9/2022                                                       *
*  Version : 1.0                                                            *
*  Notes   : PORTB and D are the leds  ON MATRIX OLD BOARDS                                                            *
*          : porta are the player leds                                                             *
*****************************************************************************
}
Device = 18F43k22 ' Tell the compiler what chip we are using
Clock = 8 ' Tell the compiler what we will be setting the clock to (Mhz)

#OPTION DIGITALLIO_INIT=TRUE
Include "SetDigitalIO.bas"       // Include this file when we compile so that we can use keywords like 'setalldigital'
Include "utils.bas"
Include "convert.bas"
Include "intosc.bas"

Dim y As Byte
Dim x As Byte
Dim Player As Byte
Dim counter As Byte
Dim Switch As PORTE.1    //old boards


//PLAYER LEDS   OLD BOARDS porta
Dim led0 As PORTC.0
Dim led1 As PORTC.1
Dim led2 As PORTC.2
Dim led3 As PORTC.3
Dim led4 As PORTC.4
Dim led5 As PORTC.5
Dim led6 As PORTC.6
Dim led7 As PORTC.7

//player buttons
Dim Button0 As PORTA.0
Dim Button1 As PORTA.1
Dim Button2 As PORTA.2
Dim Button3 As PORTA.3
Dim Button4 As PORTA.4
Dim Button5 As PORTA.5
Dim Button6 As PORTA.6
Dim Button7 As PORTA.7
 
'Dim Battery As porta.2  'hlvd
'Dim Power As porta.1     'hlvd


Const Cathodes_Data(8)As Byte = (%01111111,       ' KEEP THESE AS THEY DON"T CHANGE PER LETTER
                                 %10111111,        ' this is for scanning the rows
                                 %11011111,        //cathodes
                                 %11101111,
                                 %11110111,
                                 %11111011,
                                 %11111101,
                                 %11111110)
                                
                                
                                
Const Cat_Data(8)As Byte =    (%10000000,
                               %01000000,
                               %00100000,
                               %00010000,
                               %00001000,
                               %00000100,
                               %00000010,                                 
                               %00000001)

 Const One(8)As Byte =  (%00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,                                 
                         %00000000)       

' number 2
                                
Const Two(8)As Byte =  (%10000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000001)                 
                                        
Const Three(8) As Byte =(%10000000,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000001)
                                        
 Const Four(8) As Byte =(%10000001,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001)                                       
                                
 
Const Five(8) As Byte = (%10000001,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001)   

Const Six(8) As Byte =  (%10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)
                                                            
Const Seven(8) As Byte =(%10010001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)
                        
                                                            
Const Eight(8) As Byte =(%10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000)
                        
 Const Nine(8) As Byte= (%10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000)
                        
                                                                                                  
 Const Ten(8) As Byte=  (%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10000010,
                         %00000000,
                         %10000010,
                         %00000000)
                        
                                                            
Const Eleven(8) As Byte=(%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10000010,
                         %00000000)
                        
                                                        
Const Tweleve(8)As Byte=(%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,                                 
                         %00000000)
                                                                              
// Arrays
 Sub T_12()   //12

         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Tweleve(x)// colums 8 (L-R the X is the scan
             DelayuS(100)
              PORTD = %00000000       //eliminate ghosting
             DelayuS(100)
             Next
          End Sub
    
 Sub E_11()    //11
    
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Eleven(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
  
  
Sub T_10()   //10   
 
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Ten(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
    
      
 Sub N_9()  //9       
    
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Nine(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
          
            
Sub E_8() //8
            
         For x = 0 To 7
            PORTB =Cathodes_Data(x) //rows top to bottom
            PORTD = Eight(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
    
            
                
Sub S_7()   //7                 
  
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Seven(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD =%00000000
             DelayUS(100)
             Next
    End Sub
      
                
                    
Sub S_6()  //SIX
  
         For x = 0 To 7
            PORTB =Cathodes_Data(x) //rows top to bottom
            PORTD = Six(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
      
        
Sub F_5()  //5
    
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Five(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next       
    End Sub
                        
  Sub F_4()  //FOUR                             
    
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Four(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next         
    End Sub
          
                                
Sub T_3()
                  
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Three(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next       
    End Sub
          
          
          
                                    
 Sub T_2()  //2
 
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Two(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next       
    End Sub
                                                  
                                                            
  Sub O_1()  //1
              
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = One(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
    End Sub
    
    
    
Sub Matrix_sel()
      If counter = 12 Then
        T_12()
       End If
       'COUNTER = COUNTER - 1
        If counter = 11 Then
            E_11()
        End If
       ' COUNTER = COUNTER - 1
            If counter = 10 Then
                T_10()
            End If
            
                If counter = 9 Then
                    N_9()
                End If
                    If counter = 8 Then
                        E_8()
                    End If
                        If counter = 7 Then
                            S_7()
                        End If
                            If counter = 6 Then
                                S_6()
                            End If
                                If counter = 5 Then
                                    F_5()
                                End If
                                    If counter = 4 Then
                                        F_4()
                                    End If
                                        If counter = 3 Then
                                            T_3()
                                        End If
                                            If counter = 2 Then
                                                T_2()
                                            End If
                                                If counter = 1 Then
                                                    O_1()
                                                End If
                                                    If counter <>0 Then
                                                        T_12()
                                                    EndIf
                            End Sub
                            
Sub Matrix_Change()
    counter = (counter - 1)
    DELAYMS(400)
 End Sub
                            
SetAllDigital                       // Make all Pins digital I/O's
'TRISA=0         //inputs on old boards          // LED port - all outputs on new mexi train boards
TRISC = 0                 //PLAYER LEDS
TRISD=0                   //ANODES

TRISB = 0                // CATHODES
'WPUB = $ff                // enable pullups on all porta pins
'INTCON2.bits(7) = 0        // set bit RBPU = 0 turns on pullups
              

x = 0
y = 0


//Input (Switch)           // counter button


//PLAYER LEDS  porta
Output (led0)
Output (led1)
Output (led2)
Output (led3)
Output (led4)
Output (led5)
Output (led6)
Output (led7)

//PLAYER INPUT BUTTONS
Input(Button0)
Input(Button1)
Input(Button2)
Input(Button3)
Input(Button4)
Input(Button5)
Input(Button6)
Input(Button7)
 

//HLVD
'Output (Battery)
'Output (Power)

led0 =0
led1 =0
led2 =0
led3 =0
led4 =0
led5 =0
led6 =0
led7 =0
Input(Switch)     //PORTE.1
counter = 12


While true
    
    ' Matrix_sel()             //when SWITCH is pressed then COUNTER = COUNTER - 1
 
If counter = 12 Then T_12()End If
      
        If counter = 11 Then E_11()End If
        
            If counter = 10 Then T_10()End If
            
                If counter = 9 Then N_9()End If
                
                    If counter = 8 Then E_8()End If
                    
                        If counter = 7 Then S_7()End If
                        
                            If counter = 6 Then S_6()End If
                            
                                If counter = 5 Then F_5() End If
                                
                                    If counter = 4 Then F_4()EndIf
                                    
                                        If counter = 3 Then T_3()EndIf
                                        
                                            If counter = 2 Then T_2()EndIf
                                            
                                                If counter = 1 Then O_1()EndIf
                                                
                                                    If counter <>0 Then T_12()EndIf
                                                    
                                                      
  
                  IF SWITCH = 0 THEN Matrix_Change() endif             //DECREMENT MATRIX
                
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
                  //testing if COUNTER  is decrementing   ===  YES
                  if counter <= 12 then led2=1 end if
                  if counter <12 then led4 = 1 endif
                  if counter <11 then toggle(led2) delayms(500) toggle(led2)endif
    'press()
   ' If Switch=0 GoTo SkipCode
      ' DelayMS(delayms(400))
 

 

'SkipCode:

'   counter = counter - 1
 
              
 Wend
 

Attachments

  • old brds.bas
    19.4 KB · Views: 208
As usual, post your schematic.

That code doesn't match any of the ones you've posted here that I'm aware of (not that anyone would know unless they follow all the different posts you make)
 
I have to redo the "lost" schematic. Had to reverse engener the board to find out what each port does.
Player LEDs = port C
player buttons = portA
the matrix is ports D and B
the e.1 is the switch that changes the matrix display.
Will dra up new schematic
 
Maybe a long way around but it works perfect AND got the idea to turn OFF all the LEDs on portC when switch=0
this is an edited version of post #1. ALL is good now.
Code:
{




Device = 18F43k22 ' Tell the compiler what chip we are using
Clock = 8 ' Tell the compiler what we will be setting the clock to (Mhz)

#OPTION DIGITALLIO_INIT=TRUE
Include "SetDigitalIO.bas"       // Include this file when we compile so that we can use keywords like 'setalldigital'
Include "utils.bas"
Include "convert.bas"
Include "intosc.bas"

Dim y As Byte
Dim x As Byte
Dim Player As Byte
Dim counter As Byte
Dim Switch As PORTE.1    //old boards


//PLAYER LEDS   OLD BOARDS porta
Dim led0 As PORTC.0
Dim led1 As PORTC.1
Dim led2 As PORTC.2
Dim led3 As PORTC.3
Dim led4 As PORTC.4
Dim led5 As PORTC.5
Dim led6 As PORTC.6
Dim led7 As PORTC.7

//player buttons
Dim Button0 As PORTA.0
Dim Button1 As PORTA.1
Dim Button2 As PORTA.2
Dim Button3 As PORTA.3
Dim Button4 As PORTA.4
Dim Button5 As PORTA.5
Dim Button6 As PORTA.6
Dim Button7 As PORTA.7
 
'Dim Battery As porta.2  'hlvd
'Dim Power As porta.1     'hlvd


Const Cathodes_Data(8)As Byte = (%01111111,       ' KEEP THESE AS THEY DON"T CHANGE PER LETTER
                                 %10111111,        ' this is for scanning the rows
                                 %11011111,        //cathodes
                                 %11101111,
                                 %11110111,
                                 %11111011,
                                 %11111101,
                                 %11111110)
                                
                                
                                
Const Cat_Data(8)As Byte =    (%10000000,
                               %01000000,
                               %00100000,
                               %00010000,
                               %00001000,
                               %00000100,
                               %00000010,                                 
                               %00000001)

 Const One(8)As Byte =  (%00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,                                 
                         %00000000)       

' number 2
                                
Const Two(8)As Byte =  (%10000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000000,
                        %00000001)                 
                                        
Const Three(8) As Byte =(%10000000,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000001)
                                        
 Const Four(8) As Byte =(%10000001,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001)                                       
                                
 
Const Five(8) As Byte = (%10000001,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001)   

Const Six(8) As Byte =  (%10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)
                                                            
Const Seven(8) As Byte =(%10010001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)
                        
                                                            
Const Eight(8) As Byte =(%10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000)
                        
 Const Nine(8) As Byte= (%10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000,
                         %00000000,
                         %10010010,
                         %00000000)
                        
                                                                                                  
 Const Ten(8) As Byte=  (%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10000010,
                         %00000000,
                         %10000010,
                         %00000000)
                        
                                                            
Const Eleven(8) As Byte=(%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10000010,
                         %00000000)
                        
                                                        
Const Tweleve(8)As Byte=(%10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,
                         %00000000,
                         %10010010,                                 
                         %00000000)
                                                                              
// Arrays
 Sub T_12()   //12
      repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Tweleve(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000       //eliminate ghosting
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
           until switch = 0
          
          End Sub
    
 Sub E_11()    //11
     repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Eleven(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
             If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
             until switch = 0
    End Sub
  
  
Sub T_10()   //10   
   repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Ten(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
             until switch = 0 
    End Sub
    
      
 Sub N_9()  //9       
       repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Nine(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
             until switch = 0 
    End Sub
          
            
Sub E_8() //8
      repeat       
         For x = 0 To 7
            PORTB =Cathodes_Data(x) //rows top to bottom
            PORTD = Eight(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
             until switch=0
    End Sub
    
            
                
Sub S_7()   //7                 
       repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Seven(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD =%00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0
    End Sub
      
                
                    
Sub S_6()  //SIX
       repeat
         For x = 0 To 7
            PORTB =Cathodes_Data(x) //rows top to bottom
            PORTD = Six(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0
    End Sub
      
        
Sub F_5()  //5
      repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Five(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0       
    End Sub
                        
  Sub F_4()  //FOUR                             
         repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Four(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0         
    End Sub
          
                                
Sub T_3()
         repeat         
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Three(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0       
    End Sub
          
          
          
                                    
 Sub T_2()  //2
         repeat
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = Two(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0       
    End Sub
                                                  
                                                            
  Sub O_1()  //1
         repeat     
         For x = 0 To 7
            PORTB = Cathodes_Data(x) //rows top to bottom
            PORTD = One(x)// colums 8 (L-R the X is the scan
             DelayUS(100)
              PORTD = %00000000
             DelayUS(100)
             Next
                  If (Button0 = 0)Then delayms(400) Toggle(led0) EndIf           //delayms is for button debounce
                  If (Button1 = 0)Then delayms(400) Toggle(led1) EndIf
                  If (Button2 = 0)Then delayms(400) Toggle(led2) EndIf
                  If (Button3 = 0)Then delayms(400) Toggle(led3) EndIf
                  If (Button4 = 0)Then delayms(400) Toggle(led4) EndIf
                  If (Button5 = 0)Then delayms(400) Toggle(led5) EndIf
                  If (Button6 = 0)Then delayms(400) Toggle(led6) EndIf
                  If (Button7 = 0)Then delayms(400) Toggle(led7) EndIf
              until switch=0
    End Sub
    
    
SUB Leds_off()
for y = 0 to 7
    portc.bits(y)=0
    next
end sub
    

Sub Matrix_Change()
    counter = (counter - 1)
    DelayMS(400)
    portc=0
 End Sub
                            
SetAllDigital                       // Make all Pins digital I/O's
'TRISA=0         //inputs on old boards          // LED port - all outputs on new mexi train boards
TRISB = 0                // CATHODES
TRISC = 0                 //PLAYER LEDS
TRISD=0                   //ANODES


'WPUB = $ff                // enable pullups on all porta pins
'INTCON2.bits(7) = 0        // set bit RBPU = 0 turns on pullups
              

x = 0
y = 0


//Input (Switch)           // counter button


//PLAYER LEDS  porta
Output (led0)
Output (led1)
Output (led2)
Output (led3)
Output (led4)
Output (led5)
Output (led6)
Output (led7)

//PLAYER INPUT BUTTONS
Input(Button0)
Input(Button1)
Input(Button2)
Input(Button3)
Input(Button4)
Input(Button5)
Input(Button6)
Input(Button7)
 

//HLVD
'Output (Battery)
'Output (Power)

led0 =0
led1 =0
led2 =0
led3 =0
led4 =0
led5 =0
led6 =0
led7 =0
Input(Switch)     //PORTE.1
counter = 12


While true
    
  
 
            t_12()                 //SUBROUTE FOR EACH DIFFERENT DISPLAY
            matrix_change()        // debounce SWITCH
            'Leds_off()               // TURN OFF ALL ledS
            e_11()
            matrix_change()
            T_10()
            matrix_change()
            N_9()
            matrix_change()
            E_8()
            matrix_change()
            S_7()
            matrix_change()
            S_6()
            matrix_change()
            F_5()
            matrix_change()
            F_4()
            matrix_change()
            T_3()
            matrix_change()
             T_2()
             matrix_change()
             O_1()
             matrix_change()
            
      
                
              
 Wend
 
That's not going to work out very well unless you've added pullup resistors to PORTA since the last schematic you posted here...
 

Attachments

  • mex train schematic.jpg
    mex train schematic.jpg
    456.1 KB · Views: 220
the board I am using has 10k pullup resistors on PortA.
Still working on code for board using weal pullups on portB
Will post schematic of the posted code in post#4
 
here is a schematic that matches the posted code in post#4
 

Attachments

  • old boards.jpg
    old boards.jpg
    442.9 KB · Views: 203
I'll take your word for it that there are pullups on PORTA since they're not shown in that schematic.

If that code works for you then great.
 
oUPS! I forgo to put the 10K pullups on portA. My bad.
I used the schematic that I have for my newer boards with PortB for the switch inputs,
Thanks.
I will maKe additions but If I get the boards with PortB switch inputs working then will probally never use the old board schematic
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top