feriar Napisano Maj 16, 2010 Udostępnij Napisano Maj 16, 2010 Witam,napisałem pod ten schemat program http://img263.imageshack.us/i/pilotrc5.jpg/ i pytanie czy on będzie działać $regfile = "2313def.dat" $crystal = 8000000 Config Portb.3 = Input Config Portb.2 = Input Config Portb.1 = Input Config Portb.0 = Input Config Portb.4 = Output Dim Togbit As Byte , Command As Byte , Address As Byte do Debounce Portb.3 , 0 , Prosto , Sub Debounce Portb.2 , 0 , Tyl , Sub Debounce Portb.1 , 0 , Lewo , Sub Debounce Portb.0 , 0 , Prawo , Sub Prosto: Command = 1 Togbit = 0 Address = 0 Do Rc5send Togbit , Address , Command Waitms 250 Loop Until Portb.0 = 1 Return Tyl: Command = 2 Togbit = 0 Address = 0 Do Rc5send Togbit , Address , Command Waitms 250 Loop Until Portb.1 = 1 Return Prawo: Command = 3 Togbit = 0 Address = 0 Do Rc5send Togbit , Address , Command Waitms 250 Loop Until Portb.2 = 1 Return Lewo: Command = 4 Togbit = 0 Address = 0 Do Rc5send Togbit , Address , Command Waitms 250 Loop Until Portb.3 = 1 Return Rc5send Togbit , Address , Command Waitms 250 Loop Until Portb.4 = 1 Return po połączeniu z tym: $regfile = "m8def.DAT" 'deklaracja procesora, w ty wypadku Atmega8 $crystal = 8000000 'deklaracja taktowania Config Rc5 = Pinb.0 'ustawienie pinb.0 jako odbiór sygnału IR Dim Adres As Byte , Command As Byte 'deklaracje zmiennych Dim Speed As Integer Enable Interrupts 'włączenie przerwań Config Portc = Output 'port c jako wyjścia Portc = &B00000000 'wszędzie stan spoczynkowy-0 '-------konfiguracja timera do generowania sygnału PWM warunkującego prędkość pojazdu 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 'poczatek programu Getrc5(adres , Command) 'pobierz adres i komende z pilota Command = Command And &B01111111 'wyświetlanie adresu i komendy (o ile podłączony i skonfigurowany LCD) w celu dokonania ustawień zgodnie z własnym pilotem. 'W razie potrzeby zmień komendy w kodzie poniżej Cls Lcd "adres: " ; Adres 'wyświetl adres Lowerline Lcd "komenda: " ; Command 'wyświetl komendę Waitms 3 '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! 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 'koniec pętli End '--------------------------------------------------- 'podprogramy: Przod: Do Waitms 10 ' 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 1 ' 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 1 ' 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 1 ' gasienica prawa Pwm1a = Speed Set Portc.1 Reset Portc.0 ' gasienica lewa Pwm1b = Speed Set Portc.2 Reset Portc.3 If Command = 6 Then Return Return ^źródło bascomania.pl^ Cytuj Link do komentarza Share on other sites More sharing options...
Pomocna odpowiedź
Dołącz do dyskusji, napisz odpowiedź!
Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!