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.

head aches! plus

Status
Not open for further replies.

MrDEB

Well-Known Member
Have used this code before but it has a contemplation error, using Swordfish basic
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 6/11/2020                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/19/2016                                                     *
*  Version : 1.0                                                            *
*  Notes   :  COMMON CATHODE MATRIX                                                              *
*          :                                                                *
*****************************************************************************
}


//xxxxxxxxxxxxxxxxxxxxxxxxxx

Device = 18F43k22 ' Tell the compiler what chip we are using
Clock = 8 ' Tell the compiler what we will be setting the clock to (Mhz)
//CONFIG MCLRE = OFF
Config fOSC = INTIO67 ' Internal oscillator, IO on pins 6 and 7
#option DIGITAL_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"
Include "adc.bas"  //xxxxx
Dim y As Byte
Dim x As Byte
Dim counter As Byte
Dim Switch As PORTA.3
Dim led1a As PORTD.3
Dim led1c As PORTB.3
Dim adval As Word
Dim adcout As Word
Dim led1 As PORTC.0
Dim led2 As PORTC.1
Dim led3 As PORTC.2
Dim led4 As PORTC.3
Dim led5 As PORTC.4
Dim led6 As PORTC.5
Dim led7 As PORTC.6
Dim led8 As PORTC.7
Dim led9 As PORTE.1
Dim led10 As PORTE.2
Dim Battery As PORTA.2  'hlvd
Dim Power As PORTA.1     'hlvd

//read adc port
Function adinasvolt() As Word
         result = (ADC.Read(0)) //set adc port as porta.0
End Function
// CONST Cathodes_Data(9)AS BYTE = (%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000)                               
                      
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 Z_ro(8)As Byte = (%00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,                                 
                         %00000000)                                   

 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,
                        %00000001,
                        %00000000)                 
                                        
Const Three(8) As Byte =(%10000000,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %00000010,
                         %00000000)
                                        
 Const Four(8) As Byte =(%10000001,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)                                       
                                
 
Const Five(8) As Byte = (%10000010,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000)   

Const Six(8) As Byte =  (%10000010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000)
                                                            
Const Seven(8) As Byte =(%10010010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %00000000,
                         %00000000,
                         %10000010,
                         %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 Matrix_Display()
 //12
 Repeat
    adval = ADC.Read(0)
 DelayMS(50)

         For x = 0 To 7
            PORTD = Cathodes_Data(x) //rows top to bottom
            PORTB = Tweleve(x)// colums 8 (L-R the X is the scan
             DelayUS(300)
             Next
         Select adval
                Case > 1000 //Play1 = 1'value over 100  913,750,650,550,450,350,201,30
                    'no button pressed
                Case > 913 Toggle(led1)DelayMS(500)
                Case > 750 Toggle(led2)DelayMS(500)
                Case > 650 Toggle(led3)DelayMS(500)
                Case > 550 Toggle(led4)DelayMS(500)
                Case > 450 Toggle(led5)DelayMS(500)
                Case > 350 Toggle(led6)DelayMS(500)
                Case > 250 Toggle(led7)DelayMS(500)
                Case > 150 Toggle(led8)DelayMS(500)
         End Select
         Until Switch=0
              DelayMS(500)
              counter = counter - 1   //11           
    

    
          //11
              Repeat
               adval = ADC.Read(0)
               DelayMS(50)
                 For x = 0 To 7
                    PORTD = Cathodes_Data(x) //rows top to bottom
                    PORTB = Eleven(x)// colums 8 (L-R the X is the scan
                     DelayUS(500)
                      Next
                      Select adval
                        Case > 1000 //Play1 = 1'value over 100
                            'no button pressed
                        Case > 913 Toggle(led1)DelayMS(500)
                        Case > 750 Toggle(led2)DelayMS(500)
                        Case > 650 Toggle(led3)DelayMS(500)
                        Case > 550 Toggle(led4)DelayMS(500)
                        Case > 450 Toggle(led5)DelayMS(500)
                        Case > 350 Toggle(led6)DelayMS(500)
                        Case > 250 Toggle(led7)DelayMS(500)
                        Case > 150 Toggle(led8)DelayMS(500)
                 End Select
                     Until Switch=0
                     DelayMS(500)
                      counter = counter - 1   //10

  
    
                     //10
                        Repeat
                         adval = ADC.Read(0)
                         DelayMS(50)
                         For x = 0 To 7
                            PORTD = Cathodes_Data(x) //rows top to bottom
                            PORTB = Ten(x)// colums 8 (L-R the X is the scan
                             DelayUS(500)
                             Next
                             Select adval
                                Case > 1000 //Play1 = 1'value over 100
                                    'no button pressed
                                 Case > 913 Toggle(led1)DelayMS(500)
                                Case > 750 Toggle(led2)DelayMS(500)
                                Case > 650 Toggle(led3)DelayMS(500)
                                Case > 550 Toggle(led4)DelayMS(500)
                                Case > 450 Toggle(led5)DelayMS(500)
                                Case > 350 Toggle(led6)DelayMS(500)
                                Case > 250 Toggle(led7)DelayMS(500)
                                Case > 150 Toggle(led8)DelayMS(500)
                         End Select
                            Until
                            Switch =0
                             DelayMS(500)
                              counter = counter - 1  //9
                  
                      
                             //9   
                               Repeat
                                adval = ADC.Read(0)
                                DelayMS(50)
                                 For x = 0 To 7
                                    PORTD = Cathodes_Data(x) //rows top to bottom
                                    PORTB = Nine(x)// colums 8 (L-R the X is the scan
                                     DelayUS(500)
                                    Next 
                                     Select adval
                                        Case > 1000 //Play1 = 1'value over 100
                                            'no button pressed
                                         Case > 913 Toggle(led1)DelayMS(500)
                                        Case > 750 Toggle(led2)DelayMS(500)
                                        Case > 650 Toggle(led3)DelayMS(500)
                                        Case > 550 Toggle(led4)DelayMS(500)
                                        Case > 450 Toggle(led5)DelayMS(500)
                                        Case > 350 Toggle(led6)DelayMS(500)
                                        Case > 250 Toggle(led7)DelayMS(500)
                                        Case > 150 Toggle(led8)DelayMS(500)
                                 End Select
                                    Until Switch=0
                                    DelayMS(500)
                                   counter = counter - 1   //8
                                  
            
                                     //8       
                                       Repeat
                                        adval = ADC.Read(0)
                                        DelayMS(50)
                                         For x = 0 To 7
                                            PORTD = Cathodes_Data(x) //rows top to bottom
                                            PORTB = Eight(x)// colums 8 (L-R the X is the scan
                                             DelayUS(500)
                                              Next
                                              Select adval
                                                Case > 1000 //Play1 = 1'value over 100
                                                    'no button pressed
                                                Case > 913 Toggle(led1)DelayMS(500)
                                                Case > 750 Toggle(led2)DelayMS(500)
                                                Case > 650 Toggle(led3)DelayMS(500)
                                                Case > 550 Toggle(led4)DelayMS(500)
                                                Case > 450 Toggle(led5)DelayMS(500)
                                                Case > 350 Toggle(led6)DelayMS(500)
                                                Case > 250 Toggle(led7)DelayMS(500)
                                                Case > 150 Toggle(led8)DelayMS(500)
                                         End Select
                                             Until Switch=0
                                             DelayMS(500)
                                              counter = counter - 1    //7
                                        
            
                
                                       //7             
                                           Repeat
                                            adval = ADC.Read(0)
                                     DelayMS(50)
                                             For x = 0 To 7
                                                PORTD = Cathodes_Data(x) //rows top to bottom
                                                PORTB = Seven(x)// colums 8 (L-R the X is the scan
                                                 DelayUS(500)
                                                 Next
                                                 Select adval
                                                    Case > 1000 //Play1 = 1'value over 100
                                                        'no button pressed
                                                    Case > 913 Toggle(led1)DelayMS(500)
                                                    Case > 750 Toggle(led2)DelayMS(500)
                                                    Case > 650 Toggle(led3)DelayMS(500)
                                                    Case > 550 Toggle(led4)DelayMS(500)
                                                    Case > 450 Toggle(led5)DelayMS(500)
                                                    Case > 350 Toggle(led6)DelayMS(500)
                                                    Case > 250 Toggle(led7)DelayMS(500)
                                                    Case > 150 Toggle(led8)DelayMS(500)
                                             End Select
                                                  Until Switch=0
                                                 DelayMS(500)
                                                 counter = counter - 1       //6
                                                  
                                                
                                                 //SIX               
                                                  Repeat
                                                    adval = ADC.Read(0)
                                                     DelayMS(50)
                                                     For x = 0 To 7
                                                        PORTD = Cathodes_Data(x) //rows top to bottom
                                                        PORTB = Six(x)// colums 8 (L-R the X is the scan
                                                         DelayUS(500)
                                                         Next
                                                         Select adval
                                                            Case > 1000 //Play1 = 1'value over 100
                                                                'no button pressed
                                                             Case > 913 Toggle(led1)DelayMS(500)
                                                            Case > 750 Toggle(led2)DelayMS(500)
                                                            Case > 650 Toggle(led3)DelayMS(500)
                                                            Case > 550 Toggle(led4)DelayMS(500)
                                                            Case > 450 Toggle(led5)DelayMS(500)
                                                            Case > 350 Toggle(led6)DelayMS(500)
                                                            Case > 250 Toggle(led7)DelayMS(500)
                                                            Case > 150 Toggle(led8)DelayMS(500)
                                                     End Select
                                                          Until Switch=0
                                                         DelayMS(500)
                                                        counter = counter - 1       //5
                                                          
                                              
                                                      //5                   
                                                        Repeat
                                                        adval = ADC.Read(0)
                                                        DelayMS(50)
                                                         For x = 0 To 7
                                                            PORTD = Cathodes_Data(x) //rows top to bottom
                                                            PORTB = Five(x)// colums 8 (L-R the X is the scan
                                                             DelayUS(500)
                                                             Next
                                                             Select adval
                                                                Case > 1000 //Play1 = 1'value over 100
                                                                    'no button pressed
                                                                Case > 913 Toggle(led1)DelayMS(500)
                                                                Case > 750 Toggle(led2)DelayMS(500)
                                                                Case > 650 Toggle(led3)DelayMS(500)
                                                                Case > 550 Toggle(led4)DelayMS(500)
                                                                Case > 450 Toggle(led5)DelayMS(500)
                                                                Case > 350 Toggle(led6)DelayMS(500)
                                                                Case > 250 Toggle(led7)DelayMS(500)
                                                                Case > 150 Toggle(led8)DelayMS(500)
                                                         End Select
                                                              Until Switch=0
                                                             DelayMS(500)
                                                            counter = counter - 1       //4
                                                              
                  
                                                                //FOUR                     
                                                                 Repeat
                                                                adval = ADC.Read(0)
                                                                DelayMS(50)
                                                                 For x = 0 To 7
                                                                    PORTD = Cathodes_Data(x) //rows top to bottom
                                                                    PORTB = Four(x)// colums 8 (L-R the X is the scan
                                                                     DelayUS(500)
                                                                     Next
                                                                     Select adval
                                                                        Case > 1000 //Play1 = 1'value over 100
                                                                            'no button pressed
                                                                        Case > 913 Toggle(led1)DelayMS(500)
                                                                        Case > 750 Toggle(led2)DelayMS(500)
                                                                        Case > 650 Toggle(led3)DelayMS(500)
                                                                        Case > 550 Toggle(led4)DelayMS(500)
                                                                        Case > 450 Toggle(led5)DelayMS(500)
                                                                        Case > 350 Toggle(led6)DelayMS(500)
                                                                        Case > 250 Toggle(led7)DelayMS(500)
                                                                        Case > 150 Toggle(led8)DelayMS(500)
                                                                 End Select
                                                                      Until Switch=0
                                                                     DelayMS(500)
                                                                    counter = counter - 1       //3
                                                                      
                                                          
                                                                         //3                   
                                                                    Repeat
                                                                    adval = ADC.Read(0)
                                                                     DelayMS(50)
                                                                     For x = 0 To 7
                                                                        PORTD = Cathodes_Data(x) //rows top to bottom
                                                                        PORTB = Three(x)// colums 8 (L-R the X is the scan
                                                                         DelayUS(500)
                                                                         Next
                                                                         Select adval
                                                                            Case > 1000 //Play1 = 1'value over 100
                                                                                'no button pressed
                                                                            Case > 913 Toggle(led1)DelayMS(500)
                                                                            Case > 750 Toggle(led2)DelayMS(500)
                                                                            Case > 650 Toggle(led3)DelayMS(500)
                                                                            Case > 550 Toggle(led4)DelayMS(500)
                                                                            Case > 450 Toggle(led5)DelayMS(500)
                                                                            Case > 350 Toggle(led6)DelayMS(500)
                                                                            Case > 250 Toggle(led7)DelayMS(500)
                                                                            Case > 150 Toggle(led8)DelayMS(500)
                                                                     End Select
                                                                          Until Switch=0
                                                                         DelayMS(500)
                                                                         counter = counter - 1       //1
                                                                          
                                                            
          
                                                                //2                         
                                                             Repeat
                                                            adval = ADC.Read(0)
                                                            DelayMS(50)
                                                             For x = 0 To 7
                                                                PORTD = Cathodes_Data(x) //rows top to bottom
                                                                PORTB = Two(x)// colums 8 (L-R the X is the scan
                                                                 DelayUS(500)
                                                                 Next
                                                                 Select adval
                                                                    Case > 1000 //Play1 = 1'value over 100
                                                                        'no button pressed
                                                                     Case > 913 Toggle(led1)DelayMS(500)
                                                                        Case > 750 Toggle(led2)DelayMS(500)
                                                                        Case > 650 Toggle(led3)DelayMS(500)
                                                                        Case > 550 Toggle(led4)DelayMS(500)
                                                                        Case > 450 Toggle(led5)DelayMS(500)
                                                                        Case > 350 Toggle(led6)DelayMS(500)
                                                                        Case > 250 Toggle(led7)DelayMS(500)
                                                                        Case > 150 Toggle(led8)DelayMS(500)
                                                             End Select
                                                                  Until Switch=0
                                                                 DelayMS(500)
                                                                 counter = counter - 1       //2
                                                                  
                      
                                                                        Repeat
                                                                        adval = ADC.Read(0)
                                                                        DelayMS(50)
                                                                         For x = 0 To 7
                                                                            PORTD = Cathodes_Data(x) //rows top to bottom
                                                                            PORTB = One(x)// colums 8 (L-R the X is the scan
                                                                             DelayUS(500)
                                                                             Next
                                                                             Select adval
                                                                                Case > 1000 //Play1 = 1'value over 100
                                                                                    'no button pressed
                                                                                Case > 913 Toggle(led1)DelayMS(500)
                                                                                Case > 750 Toggle(led2)DelayMS(500)
                                                                                Case > 650 Toggle(led3)DelayMS(500)
                                                                                Case > 550 Toggle(led4)DelayMS(500)
                                                                                Case > 450 Toggle(led5)DelayMS(500)
                                                                                Case > 350 Toggle(led6)DelayMS(500)
                                                                                Case > 250 Toggle(led7)DelayMS(500)
                                                                                Case > 150 Toggle(led8)DelayMS(500)
                                                                         End Select
                                                                              Until Switch=0
                                                                             DelayMS(500)
                                                                             counter = counter - 1       //0
                                                                              
                                                                    End Sub
                                                                    
                                                                                      Repeat
                                                                        adval = ADC.Read(0)
                                                                        DelayMS(50)
                                                                         For x = 0 To 7
                                                                            PORTD = Cathodes_Data(x) //rows top to bottom
                                                                            PORTB = Z_ro(x)// colums 8 (L-R the X is the scan
                                                                             DelayUS(500)
                                                                             Next
                                                                             Select adval
                                                                                Case > 1000 //Play1 = 1'value over 100
                                                                                    'no button pressed
                                                                                Case > 913 Toggle(led1)DelayMS(500)
                                                                                Case > 750 Toggle(led2)DelayMS(500)
                                                                                Case > 650 Toggle(led3)DelayMS(500)
                                                                                Case > 550 Toggle(led4)DelayMS(500)
                                                                                Case > 450 Toggle(led5)DelayMS(500)
                                                                                Case > 350 Toggle(led6)DelayMS(500)
                                                                                Case > 250 Toggle(led7)DelayMS(500)
                                                                                Case > 150 Toggle(led8)DelayMS(500)
                                                                         End Select
                                                                              Until Switch=0
                                                                             DelayMS(500)
                                                                             'counter = counter - 1       //60
                                                                              
                                                                    End Sub
                                                                    
 Sub Player_press()
     adval = ADC.Read(0)
 DelayMS(100)
     Select adval

    Case > 1000 //Play1 = 1'value over 100
        'no button pressed
    Case > 731 Toggle(led1)DelayMS(500)
    Case > 651 Toggle(led2)DelayMS(500)
    Case > 569 Toggle(led3)DelayMS(500)
    Case > 489 Toggle(led4)DelayMS(500)
    Case > 389 Toggle(led5)DelayMS(500)
    Case > 307 Toggle(led6)DelayMS(500)
    Case > 243 Toggle(led7)DelayMS(500)
    Case > 163 Toggle(led8)DelayMS(500)
 
    
End Select
End Sub 
                            
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

//Function adinasvolt() As Word
  //       result = (ADC.Read(0)) //set adc port as porta.0
//End Function
            

// Start Of Program



TRISB = %00000000                   // Make PORTB all outputs                 // Make PORTD all outputs
TRISC = %00000000                   // Make PORTC all outputs
'TRISA = %00000000
TRISD = %00000000
x = 0
y = 0
'PORTB = %11111111//Cathodes_Data(x) rows top to bottom
'PORTD = %00000000//A_data(x) colums 8 (L-R


Output (led1)
Output (led2)
Output (led3)
Output (led4)
Output (led5)
Output (led6)
Output (led7)
Output (led8)
Output (Battery)
Output (Power)
Input (PORTA.0)
Input (Switch)  //porta.3
Switch=1
led1 =0
led2=0
led3 =0
led4=0
led5 =0
led6=0
led7 =0
led8=0
SetAllDigital()
counter = 12

While true
 adval = ADC.Read(0)
 DelayMS(100)
 Matrix_Display()        // display select which number to display

 If adval < 1000 Then
    Player_press()
    End If
{
Select adval

    Case > 1000 //Play1 = 1'value over 100
        'no button pressed
    Case > 731 Toggle(led1)DelayMS(500)
    Case > 651 Toggle(led2)DelayMS(500)
    Case > 569 Toggle(led3)DelayMS(500)
    Case > 489 Toggle(led4)DelayMS(500)
    Case > 389 Toggle(led5)DelayMS(500)
    Case > 307 Toggle(led6)DelayMS(500)
    Case > 243 Toggle(led7)DelayMS(500)
    Case > 163 Toggle(led8)DelayMS(500)
 
    
End Select
 }


    ' T_12()
   ' DelayMS(100)
    'If Switch = 0 Then
  ' Matrix_sel()
   ' EndIf
   ' DelayMS(100)
     'Matrix_sel()
     'EndIf
Wend           // Loop back to the while loop as long as we havent finished.
 

Attachments

  • Screenshot (80).png
    Screenshot (80).png
    158.6 KB · Views: 292
I have no idea how it happened, but there's a missing comma in the file ADC.bas after the line 'AN11 =$0B'
Code:
#if (_adc > 8)
public const
   AN8  = $08,
   AN9  = $09,
   AN10 = $0A,
   AN11 = $0B,
   AN12 = $0C,
   AN13 = $0D,
   AN14 = $0E,
   AN15 = $0F
#endif
 
yes I saw that as well but It won't allow to be added?
Have several coppies of same file and all have same, missing comma.
I hope it has nothing to do with the free version of Swordfish and the purchased version. I had/have both.
going to try and copy n paste but the module won't let me even add the missing comma
 
Have several coppies of same file and all have same,missing comma.
Of course you do.

I hope it has nothing to do with the free version of Swordfish and the purchased version.
No, this is a mistake, and it's in both versions so you'll have to fix each one separately.

going to try and copy n paste but the module won't let me even add the missing comma
Files that are in the Library folder are protected from changes inside the IDE.
When you open ADC.bas you should see a message at the top of the editor window stating
"adc is a compiler system file and is read only". Double click on that line and it will allow you to edit the file.
Add the comma and save it back to where it came from.

Do the same in the paid-for and free versions
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top