Код:
$prog &HFF , &HE4 , &HD9 , &H00 ' generated. Take care that the chip supports all fuse bytes. $regfile = "m32def.dat" ' specify the used micro $crystal = 8000000 ' used crystal frequency $baud = 1200 Config Pinb.2 = Input ' если 1 то идет зарядка Config Pind.2 = Output : Portd.2 = 1 : Config Pind.2 = Input : Tsop1 Alias Pind.2 Config Pind.3 = Input : Tsop2 Alias Pind.3 Config Pinb.0 = Output : Led_ir1 Alias Portb.0 Config Pinb.1 = Output : Led_ir2 Alias Portb.1 Config Pinb.2 = Output : Led_ir3 Alias Portb.2 Config Pinc.4 = Output : Led_r1 Alias Portc.4 Config Pinc.5 = Output : Led_g1 Alias Portc.5 Config Pinc.6 = Output : Led_r2 Alias Portc.6 Config Pinc.7 = Output : Led_g2 Alias Portc.7 Config Pind.6 = Output : Old_ir_led Alias Portd.6 Config Pind.7 = Output : Portd.7 = 0 : Spik Alias Portd.7 Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Config Pinc.2 = Output : Drl Alias Portc.2 : Config Pind.4 = Output Config Pinc.3 = Output : Drr Alias Portc.3 : Config Pind.5 = Output Dim Speed As Byte : Speed = 150 Dim B As Integer : B = 0 Dim C As Integer : Print "Start" Wait 2 Led_r1 = 1 Gosub ПискВкл Led_r1 = 0 Config Rc5 = Pind.2 Enable Interrupts Dim Address As Byte , Command As Byte ' Код управления с пульта от телевизора Do Getrc5(address , Command) If Command = 32 Then Gosub Прямо If Command = 17 Then Gosub Влево If Command = 16 Then Gosub Вправо If Command = 33 Then Gosub Назад Waitms 50 Gosub Стоп Loop ' Это когда препятствия нет, едем перед, когда есть едем назад. ' Но в данном случае он не выполняется потому что из-за верхнего цикла ' мы сюда никогда не дойдем :-) Do Speed = 150 Gosub Радар1 If Tsop1 = 0 Then Gosub Назад Led_r1 = 1 : Waitms 100 Gosub ПискВкл Else Led_r1 = 0 : Gosub Прямо : Waitms 100 End If Waitus 100 Loop '============================================================================== '============================================================================== Влево: Drl = 1 : Drr = 0 : Pwm1b = Speed : Pwm1a = Speed: Return Вправо: Drl = 0 : Drr = 1 : Pwm1b = Speed : Pwm1a = Speed: Return Прямо: Drl = 0 : Drr = 0 : Pwm1b = Speed : Pwm1a = Speed: Return Назад: Drl = 1 : Drr = 1 : Pwm1b = Speed : Pwm1a = Speed: Return Стоп: Drl = 0 : Drr = 0 : Pwm1b = 0 : Pwm1a = 0: Return ПискВкл: For B = 0 To 1000 Spik = 1 Waitus 300 Spik = 0 Waitus 300 Next Return ПискВыкл: Spik = 0 Return Св_Кр_1: B = 0 For B = 0 To 5 Led_r1 = 1 Led_g2 = 0 Waitms 200 Led_r1 = 0 Led_g2 = 1 Waitms 200 Next Led_g2 = 0 Return Св_Зл_1: B = 0 For B = 0 To 5 Led_g1 = 1 Led_r2 = 0 Waitms 200 Led_g1 = 0 Led_r2 = 1 Waitms 200 Next Led_r2 = 0 Return Св_Кр_2: B = 0 For B = 0 To 5 Led_r2 = 1 Waitms 200 Led_r2 = 0 Waitms 200 Next Return Св_Зл_2: B = 0 For B = 0 To 5 Led_g2 = 1 Waitms 200 Led_g2 = 0 Waitms 200 Next Return Св_Жл_1: B = 0 For B = 0 To 5 Led_g1 = 1 Led_r1 = 1 Led_g2 = 0 Led_r2 = 0 Waitms 200 Led_g1 = 0 Led_r1 = 0 Led_g2 = 1 Led_r2 = 1 Waitms 200 Next Led_g2 = 0 Led_r2 = 0 Return Радар1: For B = 0 To 12 Led_ir1 = 0 Waitus 18 Led_ir1 = 1 Waitus 16 Next Return