Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $regfile = "m8def.DAT"
- $crystal = 8000000
- Config Rc5 = Pinb.0 'pinb.0 - odbiór sygnału IR
- Dim Adres As Byte , Command As Byte
- Dim Speed As Integer
- Enable Interrupts
- Config Portc = Output
- Portc = &B00000000
- Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 1
- Speed = 255 'prędkośc na maksa
- Do
- Getrc5(adres , Command) 'pobierz adres i komende z pilota
- Command = Command And &B01111111
- Waitms 50
- 'warunki i odwołania do podprogramów
- If Command = 2 Then
- Gosub Przod
- End If
- If Command = 8 Then
- Gosub Tyl
- End If
- If Command = 4 Then
- Gosub Lewo
- End If
- If Command = 6 Then
- Gosub Prawo
- End If
- 'regulacja prędkości , dostosuj wartosci komend do swojego pilota :P
- If Command = 32 Then
- Incr Speed
- If Speed = 251 Then
- Speed = 250
- End If
- End If
- If Command = 33 Then
- Decr Speed
- If Speed = 1 Then
- Speed = 2
- End If
- End If
- 'koniec regulacji prędkości
- If Command = 127 Then Pwm1a = 0 'komenda 127 podawana jest kiedy
- If Command = 127 Then Pwm1b = 0 'procesor nie odbiera sygnału z nadajnika
- 'przy tej komendzie stój!
- Loop
- End
- 'podprogramy:
- Przod:
- Do
- Waitms 50
- ' gasienica prawa
- Pwm1a = Speed
- Set Portc.0
- Reset Portc.1
- ' gasienica lewa
- Pwm1b = Speed
- Set Portc.2
- Reset Portc.3
- If Command = 2 Then Return
- Loop
- End
- Tyl:
- Do
- Waitms 50
- ' gasienica prawa
- Pwm1a = Speed
- Set Portc.1
- Reset Portc.0
- ' gasienica lewa
- Pwm1b = Speed
- Set Portc.3
- Reset Portc.2
- If Command = 8 Then Return
- Loop
- End
- Lewo:
- Do
- Waitms 50
- ' gasienica prawa
- Pwm1a = Speed
- Set Portc.0
- Reset Portc.1
- ' gasienica lewa
- Pwm1b = Speed
- Set Portc.3
- Reset Portc.2
- If Command = 4 Then Return
- Loop
- End
- Prawo:
- Waitms 50
- ' gasienica lewa
- Pwm1a = Speed
- Set Portc.1
- Reset Portc.0
- ' gasienica lewa
- Pwm1b = Speed
- Set Portc.2
- Reset Portc.3
- If Command = 6 Then Return
- Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement