$regfile = "m8def.dat" $crystal = 16000000 $baud = 19200 Config Portc = Input Config Portb = Output Config Adc = Single , Prescaler = Auto , Reference = Avcc Config Int0 = Falling Config Watchdog = 2048 Declare Sub Benzin() Declare Sub Gaz() Dim A As Integer A = 0 Dim Econ As Integer Econ = 0 Dim Econtime As Word Dim Econtime1 As Byte Dim Ind As Byte Dim T As Integer Dim Term As Integer Dim Term1 As Integer Dim Rz As Byte Rz = 0 Dim Temper As Byte Dim R As Byte R = 0 Dim Pausebenz As Integer Dim Pausebenz1 As Byte Dim Pausegaz As Integer Dim Pausegaz1 As Byte Dim Startgaz As Word Dim Startgaz1 As Byte Dim P As Byte Dim P1 As Byte Dim G As Integer Dim S As Byte S = 0 Dim Pedalbenz As Integer Dim Pedalbenz1 As Byte Dim Pedalgaz As Integer Dim Pedalgaz1 As Byte Dim Attuator As Byte Dim Attuator1 As Byte Dim Ri As Byte Ri = 0 Dim Rr As Byte Rr = 1 On Int0 Ekonomizer Econtime = 350 Term = 500 Term1 = 550 Pedalbenz = 700 Pedalgaz = 300 Startgaz = 700 Pausebenz = 5 Pausegaz = 250 P = 1 Attuator = 1 Enable Interrupts Enable Int0 If Pinc.4 = 0 Then Waitms 3 If Pinc.4 = 0 Then Portb.3 = 1 Portb.4 = 0 Portb.5 = 0 Portb.1 = 0 Portb.2 = 0 Portd.7 = 0 Waitms 20 End If End If If Pinc.3 = 0 Then Waitms 3 If Pinc.3 = 0 Then Portb.3 = 0 Portb.5 = 0 Portb.1 = 1 Portb.4 = 1 Portd.7 = 1 Portb.2 = 1 If Startgaz > 0 Then Portb.2 = 1 Waitms Startgaz Portb.2 = 0 End If End If End If If Pinc.2 = 0 Then Waitms 3 If Pinc.2 = 0 Then Portb.5 = 1 Start Adc T = Getadc(0) Stop Adc If T < Term Then Portb.1 = 1 Portb.3 = 0 Portb.4 = 1 Portd.7 = 1 If Startgaz > 0 Then Portb.2 = 1 Waitms Startgaz Portb.2 = 0 End If Else Portb.1 = 0 Portb.4 = 0 Portb.2 = 0 Portd.7 = 0 Portb.3 = 1 Waitms 20 End If End If End If Start Watchdog Do Reset Watchdog A = A + 1 If A > 500 And Portb.0 = 0 Then Portb.0 = 1 A = 0 End If If A > 800 And Portb.0 = 1 Then Portb.0 = 0 A = 0 End If If Pinc.4 = 0 Then Waitms 2 If Pinc.4 = 0 Then Call Benzin() End If End If If Pinc.3 = 0 Then Waitms 2 If Pinc.3 = 0 Then Call Gaz() End If End If If Pinc.2 = 0 Then Waitms 2 If Pinc.2 = 0 Then Gosub Automat End If End If Loop Sub Benzin() If Pausebenz > 0 Then If R = 1 Then R = 0 Portb.2 = 0 Waitms Pausebenz End If End If Portb.4 = 0 If Pinc.2 = 0 Then Portb.5 = 1 Else Portb.5 = 0 End If Portd.7 = 0 Portb.1 = 0 Portb.2 = 0 If Econtime1 > 0 Then Econ = Econ + 1 If Econ > Econtime Then Econ = Econtime + 1 Ind = Ind + 1 If Ind > 35 And Portb.3 = 1 Then Ind = 0 Portb.3 = 0 End If If Ind > 35 And Portb.3 = 0 Then Ind = 0 Portb.3 = 1 End If Else Portb.3 = 1 End If End If End Sub Sub Gaz() If Pausegaz > 0 Then If R = 0 Then R = 1 Portb.2 = 1 Portb.1 = 0 Waitms Pausegaz Portb.1 = 1 End If End If Portb.3 = 0 If Pinc.2 = 0 Then Portb.5 = 1 Else Portb.5 = 0 End If Portb.1 = 1 Portd.7 = 1 If Econtime1 > 0 Then Econ = Econ + 1 If Econ <= Econtime Then Portb.2 = 1 Portb.4 = 1 Else Portb.2 = 0 Econ = Econtime + 1 Ind = Ind + 1 If Ind > 35 And Portb.4 = 1 Then Ind = 0 Portb.4 = 0 End If If Ind > 35 And Portb.4 = 0 Then Ind = 0 Portb.4 = 1 End If End If End If If Attuator = 1 Then Start Adc T = Getadc(0) Stop Adc If T < 100 Then Ri = Ri + 1 If Ri > 20 Then Ri = 0 If Pinc.5 = 1 Then Rr = Rr + 1 If Rr > 4 Then Rr = 1 Gosub Around Else Rr = Rr - 1 If Rr < 1 Then Rr = 4 Gosub Around End If End If End If End If End Sub Automat: Portb.5 = 1 Portd.7 = 1 Start Adc T = Getadc(0) G = Getadc(1) Stop Adc If T < Term Then Rz = 1 If Rz = 1 And T > Term1 Then Rz = 0 If Rz = 1 Then If P = 1 Then If G > Pedalbenz Then S = 1 If G < Pedalgaz Then S = 0 If S = 1 And G > Pedalgaz Then Call Benzin() Else Call Gaz() End If End If Else Call Benzin() End If Return Ekonomizer: Econ = 0 Gifr = 64 Return Around: Select Case Rr Case 1: Portd.3 = 1 Portd.4 = 0 Portd.5 = 0 Portd.6 = 0 Case 2: Portd.3 = 0 Portd.4 = 1 Portd.5 = 0 Portd.6 = 0 Case 3: Portd.3 = 0 Portd.4 = 0 Portd.5 = 1 Portd.6 = 0 Case 4: Portd.3 = 0 Portd.4 = 0 Portd.5 = 0 Portd.6 = 1 End Select Waitms 5 Portd.3 = 0 Portd.4 = 0 Portd.5 = 0 Portd.6 = 0 Return