Может кому пригодится. Хорошая штука:
К сожалению с исходником что-то случилось и я решил выложить его сюда пока полностью неразрушил.
Почему-то цикл не повторяется, а микроконтроллер перезагружается. Хотя есть уверенность что я его додыр протёр прошивкой:
$regfile = "m328pbdef.dat" $crystal = 8000000 $hwstack = 64 $swstack = 128 $framesize = 288 '=================== Шаговые двигателя=============== Config Porte.0 = Output Config Portb.6 = Output Config Portb.7 = Output Config Portb.1 = Output Config Portb.2 = Output Stp2 Alias Portb.6 Dir2 Alias Portb.7 Stp1 Alias Portb.1 Dir1 Alias Portb.2 'Powermoto Alias Porte.0 'Config Porte.0 = Output 'Концевики Kny Alias Pinc.4 Knx Alias Pinc.5 Config Portc.5 = Input Config Portc.4 = Input Clapan Alias Portd.6 Config Portd.6 = Output Const Offclapan = 1 Const Onclapan = 0 '==================================================== 'Powermoto = 0 Dim P As Byte Dim O As Byte 'Dim I As Byte Dim Tm As Byte Dim Vrw As Word 'Dim Vrw2 As Word Dim Ogrx As Word 'Const Ogrx = 300 Dim Ogry As Word 'Const Ogry = 300 Dim Tmpx As Word Dim Tmpy As Word 'Числовая система координат INTEGER Dim X As Integer Dim Y As Integer Dim Tmx As Integer Dim Tmy As Integer '=================================== Dim Vr_speed As Byte Dim Tmpausy As Byte Dim Tmpausx As Byte Dim Speed As Byte Dim Speed_sys As Byte Dim Tm_null As Word Dim Gx As Byte Dim Gy As Byte Dim Ciklix As Word Dim Cikliy As Word 'Dim Tm_cikli As Byte Dim Trigx As Byte Dim Trigy As Byte Dim X_a As Integer Dim Y_a As Integer Dim X_b As Integer Dim Y_b As Integer Dim Vri As Integer Dim Pozicia As Byte Dim Adrs As Byte Adrs = 3 Goto Prog: '======================== Программа цикличного полива Programma: Select Case Adrs Case 1 X_a = 405 X_b = 460 Y_a = -260 Y_b = -355 Ciklix = 10 Cikliy = 0 Tmpausx = 200 Tmpausy = 40 Speed_sys = 25 'Adrs = 1 'Case 1 Case 2 'Клумба у 3 подъезда X_a = 80 X_b = 380 Y_a = -560 Y_b = -640 Ciklix = 10 Cikliy = 0 Tmpausx = 80 Tmpausy = 12 Speed_sys = 25 Case 3 'Распрыскивание над черёмухой X_a = 15 X_b = 370 Y_a = -70 Y_b = -170 Ciklix = 10 Cikliy = 0 Tmpausx = 15 Tmpausy = 15 Speed_sys = 30 Case 4 'Первая часть под черёмухой X_a = 50 X_b = 235 Y_a = -430 Y_b = -510 Ciklix = 10 Cikliy = 0 Tmpausx = 200 Tmpausy = 10 Speed_sys = 25 Case 5 'Вторая часть под черёмухой X_a = 40 X_b = 130 Y_a = -450 Y_b = -400 Ciklix = 15 Cikliy = 0 Tmpausx = 80 Tmpausy = 40 Speed_sys = 40 Case 6 'Кусты у 2 подъезда 'Gosub Null Vri = 0 X_a = -210 X_b = -40 Y_a = -270 Y_b = -370 Ciklix = 20 Cikliy = 0 Tmpausx = 100 Tmpausy = 30 Speed_sys = 25 Case 7 'куст у подъезда X_a = -300 X_b = -310 Y_a = -65 Y_b = -155 Ciklix = 15 Cikliy = 0 Tmpausx = 100 Tmpausy = 40 Speed_sys = 80 Case 8 'Папортник X_a = -250 X_b = -120 Y_a = -505 Y_b = -565 Ciklix = 25 Cikliy = 0 Tmpausx = 40 Tmpausy = 100 Speed_sys = 25 Case 9 'Куст у урны у 3 подъезда X_a = -180 X_b = -50 Y_a = -135 Y_b = -200 Ciklix = 20 Cikliy = 0 Tmpausx = 80 Tmpausy = 100 Speed_sys = 25 Case 10 'Два куста у папортника X_a = -190 X_b = -260 Y_a = -430 Y_b = -570 Ciklix = 20 Cikliy = 0 Tmpausx = 250 Tmpausy = 20 Speed_sys = 25 Case 11 'Дождь X_a = 310 X_b = -200 Y_a = -50 Y_b = -210 Ciklix = 15 Cikliy = 0 Tmpausx = 30 Tmpausy = 10 Speed_sys = 20 Case 12 'переход перед выходом в ноль X_a = 100 X_b = 100 Y_a = -20 Y_b = -20 Ciklix = 1 Cikliy = 0 Tmpausx = 60 Tmpausy = 80 Speed_sys = 30 Adrs = 0 End Select Return Prog: X_b = 0 Y_b = 0 X_a = 0 Y_a = 0 'Gosub Null Pozicia = 0 Clapan = Offclapan Speed_sys = 100 Speed = 80 Ciklix = 0 Cikliy = 0 Do If Speed > 0 Then Decr Speed Else Speed = Speed_sys If Tmpx = 0 Then If X > Tmx Then Dir1 = 0 Incr Tmx Gx = 0 Stp1 = Not Stp1 Tmpx = Tmpausx Elseif X < Tmx Then Dir1 = 1 Gx = 0 Stp1 = Not Stp1 Decr Tmx Tmpx = Tmpausx Else Gx = 1 Trigx = Not Trigx If Trigx = 0 Then X = X_a Else X = X_b If Pozicia = 0 Then Pozicia = 1 If Ciklix > 0 And Pozicia = 2 Then Decr Ciklix 'Цикли шагов двигателей End If End If Else If Tmpx > 0 Then Decr Tmpx End If If Tmpy = 0 Then If Y > Tmy Then Dir2 = 0 Incr Tmy Stp2 = Not Stp2 Gy = 0 Tmpy = Tmpausy Elseif Y < Tmy Then Dir2 = 1 Stp2 = Not Stp2 Decr Tmy Gy = 0 Tmpy = Tmpausy Else Gy = 1 Trigy = Not Trigy If Trigy = 0 Then Y = Y_a Else Y = Y_b If Pozicia = 1 Then Pozicia = 2 Clapan = Onclapan End If If Cikliy > 0 And Pozicia = 2 Then Decr Cikliy 'Цикли шагов двигателей End If Tmpy = Tmpausy End If Else If Tmpy > 0 Then Decr Tmpy End If '=================================================================== Задатчик цикла If Ciklix = 0 And Cikliy = 0 Then Clapan = Offclapan Wait 1 Gosub Null 'Получение новых координат Gosub Programma: Adrs = Adrs + 1 Pozicia = 0 Trigx = 0 Trigy = 0 X = X_a Y = Y_a Gx = 0 Gy = 0 End If End If Loop Do Loop End Null: Clapan = Offclapan If Knx = 0 Then Dir1 = 0 For P = 1 To 100 Stp1 = Not Stp1 Waitms 10 Next P End If If Knx = 1 Then Do If Tmx > 0 Then Dir1 = 1 Elseif Tmx < 0 Then Dir1 = 0 Else Dir1 = 1 End If Vrw = 0 Do Stp1 = Not Stp1 Waitms 2 If Knx = 0 Then If Dir1 = 0 Then Dir1 = 0 For P = 1 To 150 Stp1 = Not Stp1 Waitms 20 Next P End If Exit Do End If Incr Vrw Loop Until Vrw = 1450 Dir1 = Not Dir1 Vrw = 0 If Knx = 1 Then Do Stp1 = Not Stp1 Waitms 2 If Knx = 0 Then If Dir1 = 0 Then Dir1 = 0 For P = 1 To 150 Stp1 = Not Stp1 Waitms 20 Next P End If If Knx = 1 Then Dir1 = 0 Vrw = 0 Do Stp1 = Not Stp1 Waitms 10 If Knx = 0 Then Exit Do Incr Vrw Loop Until Vrw = 1450 End If Exit Do End If Incr Vrw Loop Until Vrw = 1450 End If Loop Until Knx = 0 End If If Kny = 0 Then Dir2 = 1 For P = 1 To 100 Stp2 = Not Stp2 Waitms 10 Next P End If If Kny = 1 Then Do If Tmy > 0 Then Dir2 = 1 Elseif Tmy < 0 Then Dir2 = 0 Else Dir2 = 0 End If Vrw = 0 Do Stp2 = Not Stp2 Waitms 2 If Kny = 0 Then If Dir2 = 1 Then For P = 1 To 150 Stp2 = Not Stp2 Waitms 20 Next P End If Exit Do End If Incr Vrw Loop Until Vrw = 1200 Dir2 = Not Dir2 Vrw = 0 If Kny = 1 Then Do Stp2 = Not Stp2 Waitms 2 If Kny = 0 Then Exit Do Incr Vrw Loop Until Vrw = 1200 End If Loop Until Kny = 0 End If 'X_a = 0 'Y_a = 0 'X = 0 'Y = 0 'X_b = 0 'Y_b = 0 Tmx = 0 Tmy = 0 'X = 0 'Y = 0 'Gx = 0 'Gy = 0 Tmpausx = 100 Tmpausy = 100 Speed_sys = 100 'Powermoto = 0 Return