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.

implementing an INTERRUPT using SF

THE code in post 1 and 7 both fail.
here is an abbreviated
Code:
//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 "utils.bas"
Include "ISRTimer.bas"   
Include "HiLowVolts"   
//Include "adc.bas"  //xxxxx
Dim y As Byte
Dim x As Byte
Dim counter As Byte
Dim Switch As PORTE.0 //counter
'Dim led1a As PORTD.3
'Dim led1c As PORTB.3
Dim adval As Word
Dim adcout As Word
//PLAYER LEDS
Dim led1 As PORTA.0
Dim led2 As PORTA.1
Dim led3 As PORTA.2
Dim led4 As PORTA.3
Dim led5 As PORTA.4
Dim led6 As PORTA.5
Dim led7 As PORTA.6
Dim led8 As PORTA.7
//PLAYER BUTTONS
Dim swt1 As PORTB.0
Dim swt2 As PORTB.1
Dim swt3 As PORTB.2
Dim swt4 As PORTB.3
Dim swt5 As PORTB.4
Dim swt6 As PORTB.5
Dim swt7 As PORTB.6
Dim swt8 As PORTB.7
//Dim player1 As PORTA.0
Dim KEY_BOUNCE_DELAY As Byte
Dim battery_power As PORTE.1  'hlvd

Interrupt Low_battery()
   // If PIR2.bits(2) = 1 Then                         
            battery_power = 1
            PIR2.bits(2) = 0         
      //  Else
           // PORTA.7 = 0
   // End If
End Interrupt


 




// 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 Zero(8)As Byte = (%00000000,
                         %00111100,
                         %01000010,
                         %10000001,
                         %01000010,
                         %00111100,
                         %00100000,                                 
                         %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,
                         %00000001,
                         %00000000)
                                        
 Const Four(8) As Byte =(%10000001,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)                                       
                                
 
Const Five(8) As Byte = (%10000001,
                         %00000000,
                         %00000000,
                         %00010000,
                         %00000000,
                         %00000000,
                         %10000001,
                         %00000000)   

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)
// Const KEY_BOUNCE_DELAY(0) = 50     // msec delay for key bounce
Sub Debounce( )
    DelayMS(300)
    End Sub




                                                                              
// Arrays
//
 
// Arrays                           
 Sub T_12()
 //12
         Repeat
         For x = 0 To 7
            PORTC = Cathodes_Data(x) //rows top to bottom
            PORTD = Tweleve(x)// colums 8 (L-R the X is the scan
             DelayUS(300)
             Next
                   If (swt1 = 0) Then
            Toggle(led1) DelayUS(300)
        ElseIf (swt2 = 0) Then
            Toggle(led2)  DelayUS(300)
        ElseIf (swt3 = 0) Then
            Toggle(led3)  DelayUS(300)
        ElseIf (swt4 = 0) Then
            Toggle(led4)   DelayUS(300)
        ElseIf (swt5 = 0) Then
            Toggle(led5)   DelayUS(300)
        ElseIf (swt6 = 0) Then
            Toggle(led6)  DelayUS(300)
        ElseIf (swt7 = 0) Then
            Toggle(led7)  DelayUS(300)
        ElseIf (swt8 = 0) Then
            Toggle(led8)  DelayUS(300)
            End If
       Until
                Switch = 0
                DelayUS(300)     
    End Sub
                                
        

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
 Sub E_11()   
  //11
   Repeat
         For x = 0 To 7
            PORTC = Cathodes_Data(x) //rows top to bottom
            PORTD = Eleven(x)// colums 8 (L-R the X is the scan
             DelayUS(300)
             Next
                   If (swt1 = 0) Then
            Toggle(led1)  DelayUS(500)
        ElseIf (swt2 = 0) Then
            Toggle(led2)  DelayUS(500)
        ElseIf (swt3 = 0) Then
            Toggle(led3)  DelayUS(500)
        ElseIf (swt4 = 0) Then
            Toggle(led4)   DelayUS(500)
        ElseIf (swt5 = 0) Then
            Toggle(led5)   DelayUS(500)
        ElseIf (swt6 = 0) Then
            Toggle(led6)  DelayUS(500)
        ElseIf (swt7 = 0) Then
            Toggle(led7)  DelayUS(500)
        ElseIf (swt8 = 0) Then
            Toggle(led8)   DelayUS(500)
            End If
         Until
                Switch = 0
                DelayUS(300)
 
    End Sub
//SUB (Matrix select) is used to select which led matrix to display using the correct array (sub ARRAYS) THERE ARE 12 13 DIFFERENT ARRAYS (1 - 0)
//THE hlvd IS SUPPOSED TO MONITOR THE BATTERY VOLTAGE AND ENABLE THE LED ON PORTE.1        

        
Sub Matrix_sel()             //select number to display
//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
If PIR2.bits(2) = 1 Then          'check HLVD interrupt
         battery_power = 1                'LED = ON
          DelayMS(1000)
          PIR2.bits(2) = 0          'clear HVLD interrupt
          Else
          battery_power = 0                'LED = OFF
    End If
//nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
        If counter = 12 Then  //12
        Repeat
        T_12()
        Until
        Switch = 0
        Debounce()
        End If
        counter = 11
//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
If PIR2.bits(2) = 1 Then          'check HLVD interrupt
         battery_power = 1                'LED = ON
          DelayMS(1000)
          PIR2.bits(2) = 0          'clear HVLD interrupt
          Else
          battery_power = 0                'LED = OFF
    End If
    //nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
    END SUB
// Start Of Program


TRISB = $FF             // SWt port - all inputs
WPUB = $FF              // PORTB pullup mask - all PORTB pullups
INTCON2.bits(7) = 0     // RBPU bit - turn on pullups
//TRISB = %00000000                   // Make PORTB all outputs                 // Make PORTD all outputs
TRISC = %00000000                   // Make PORTC all outputs cathodes
TRISA = %00000000                   //player leds
TRISD = %00000000                  //anodes
TRISE = $0000
x = 0
y = 0
// HLVDCON =%00011011      'see section 22.0 for setup and table 26-4 for voltage setting
                        'set to 4 volts in this case

                                

//Output (player1)     //player leds ON PORT C
Output (led1)
Output (led2)
Output (led3)
Output (led4)
Output (led5)
Output (led6)
Output (led7)
Output (led8)
Output (battery_power)
//Output (Power)
Input (PORTE.0)         //counter press
//Input (Switch)  //porta.3
//ALL ON PORT B
Input(swt1)
Input(swt2)
Input(swt3)
Input(swt4)
Input(swt5)
Input(swt6)
Input(swt7)
Input(swt8)
led1=0
led2=0
led3=0
led4=0
led5=0
led6=0
led7=0
led8=0
battery_power = 0 //led off
SetAllDigital()
 counter = 12
 HLVDCON =%00011011      'see section 22.0 for setup and table 26-4 for voltage setting
                        'set to 4 volts in this case
 
While true
 
Matrix_sel()  //start out with 12

Wend
code that I am experimenting with
 

Latest threads

New Articles From Microcontroller Tips

Back
Top