Hier mal eine etwas neuere Version mit ADC und Motoransteuerrung:
Code:
$regfile = "m128def.dat"
$framesize = 42
$swstack = 32
$hwstack = 32
$crystal = 14745600
$baud = 19200
Encoderled Alias Portb.0
Config Encoderled = Output
Frontled Alias Portc.4
Config Frontled = Output
Frontlled Alias Portc.3
Config Frontlled = Output
Frontrled Alias Portc.2
Config Frontrled = Output
Backlled Alias Portc.1
Config Backlled = Output
Backrled Alias Portc.0
Config Backrled = Output
Buzzer Alias Portb.4
Config Buzzer = Output
Taster Alias Pine.4
Config Taster = Input
Porte.4 = 1
Frontled = 1
Frontlled = 1
Frontrled = 1
Backlled = 1
Backrled = 1
Encoderled = 0
Declare Sub Moveatspeed(byval Sleft As Byte , Byval Sright As Byte)
Declare Sub Lineled(byval Status As Byte)
Declare Sub Flled(byval Status As Byte)
Declare Sub Frled(byval Status As Byte)
Declare Sub Blled(byval Status As Byte)
Declare Sub Brled(byval Status As Byte)
Declare Sub Encled(byval Status As Byte)
Declare Sub Bruzzer(byval Ton As Byte , Byval Laenge As Byte)
Declare Sub Intodometrie()
Declare Sub Motorstop()
Declare Function Getmicro() As Word
Declare Function Getlsl() As Word
Declare Function Getlsr() As Word
Declare Function Getlinel() As Word
Declare Function Getliner() As Word
Declare Function Getakku() As Word
Dim Encleft As Integer
Dim Encright As Integer
Do
Call Moveatspeed(220 , 220)
Loop
End
Sub Lineled(byval Status As Byte)
If Status = 1 Then
Frontled = 0
Elseif Status = 0 Then
Frontled = 1
End If
End Sub
Sub Flled(byval Status As Byte)
If Status = 1 Then
Frontlled = 0
Elseif Status = 0 Then
Frontlled = 1
End If
End Sub
Sub Frled(byval Status As Byte)
If Status = 1 Then
Frontrled = 0
Elseif Status = 0 Then
Frontrled = 1
End If
End Sub
Sub Blled(byval Status As Byte)
If Status = 1 Then
Backlled = 0
Elseif Status = 0 Then
Backlled = 1
End If
End Sub
Sub Brled(byval Status As Byte)
If Status = 1 Then
Backrled = 0
Elseif Status = 0 Then
Backrled = 1
End If
End Sub
Sub Encled(byval Status As Byte)
If Status = 1 Then
Encoderled = 1
Elseif Status = 0 Then
Encoderled = 1
End If
End Sub
Sub Motorstop()
Call Moveatspeed(220 , 220)
End Sub
Sub Intodometrie()
Encleft = 0
Encright = 0
Call Encled(1)
On Int7 Encoleft
On Int6 Encoright
Config Int7 = Falling
Config Int6 = Falling
Enable Int7
Enable Int6
Enable Interrupts
End Sub
Sub Bruzzer(byval Ton As Byte , Laenge As Byte)
Dim Count As Byte
For Count = 1 To Laenge
Config Timer0 = Timer , Prescale = 8
Timer0 = Ton
On Ovf0 On_ovf0
Enable Ovf0
Enable Interrupts
Waitms 1
Next Laenge
End Sub
Sub Moveatspeed(byval Sleft As Byte , Byval Sright As Byte)
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 1
Config Portb.7 = Output
Portb.7 = 1
Compare1a = Sleft
Compare1b = Sright
End Sub
Function Getmicro()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getmicro = Getadc(3)
End Function
Function Getlsl()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getlsl = Getadc(4)
End Function
Function Getlsr()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getlsr = Getadc(5)
End Function
Function Getlinel()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getlinel = Getadc(1)
End Function
Function Getliner()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getliner = Getadc(2)
End Function
Function Getakku()
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Getakku = Getadc(0)
End Function
Encoleft:
Encleft = Encleft + 1
Return
Encoright:
Encright = Encright + 1
Return
On_ovf0:
Toggle Buzzer
Return
Nun möcht ich aber noch eine Funktion(Sub) schreiben die den Roboter mittels Odometrie gerade ausfahren lässt. Leider haben meine bisherigen Versuche nur Misserfolg kann mir jemand sagen wie man das in Bascom am besten umsetzt.(Der Pro-bot 128 benutzt Int7 Int6 um die 6 weißen und 6 schwarzen Segmente über Fotodioden einzulesen)
Danke
Lesezeichen