Also hier jetzt mal ein Script aus Sonics Code:
+ PWM von Timer1 wird verwendet (ext. interruptnoch frei)
+ Richtungen werden mit FWD,BWD wtc. angegeben
+ Odometrie läuft oder sollte zumindest
+ Linieverfolgung läuft oder sollte zumindest
- Odometriefunktionen sollen noch als Variablen eingführt werden: a = Odorechts()
- Linnieverfolgungsfunktionen sollen noch als Variablen eingführt werden: a = Odorechts()
- Pollswitch läuft net, da müsste mir mal jemand den Code entschlüsseln
- Interrupt für Pollswitch läuft noch nicht
Code:
'`Bereits integrierte Funktionen:
'Motordir(x,x) x: Fwd, Rwd, Break, Free
'Motorspeed(x,x) x: 0-255
'Backled(x,x) x: An, Aus
'Statusled(x) x: Aus, Green, Red, Yellow
'Frontled(x) x: An, Aus
'Odometrie()
'Linie()
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 2400
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 8
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Enable Interrupts
Declare Sub Motordir(byval Mldir As Byte , Byval Mrdir As Byte)
Declare Sub Motorspeed(byval Mlspeed As Byte , Byval Mrspeed As Byte)
Declare Sub Backled(byval Led1 As Byte , Byval Led2 As Byte)
Declare Sub Frontled(byval Led1 As Byte)
Declare Sub Statusled(byval Color As Byte)
Declare Sub Odometrie()
Declare Sub Linie()
'-----------Motoren-------------------
Const Fwd = 1
Const Rwd = 2
Const Free = 3
Const Brake = 4
'Motor Rechts
Config Pinb.1 = Output
Config Pind.4 = Output
Config Pind.5 = Output
'Motor Links
Config Pinb.2 = Output
Config Pinb.4 = Output
Config Pinb.5 = Output
'----------Led------------------------
Const Aus = 0
Const Red = 1
Const Green = 2
Const Yellow = 3
Const An = 1
'FrontLED (Odometrie)
Config Pind.6 = Output
' ****** !!! ACHTUNG !!! *******BACKLEDs***********************************
Config Pinc.0 = Output 'Rechts
Config Pinc.1 = Output 'Links
' Die BackLEDs können nicht genutzt werden wenn die Odometrie benutzt wird.
' --> BackLEDs pinc.0 und pinc.1 als Ausgang definieren
' --> Odometrie pinc.0 und pinc.1 als Eingang bzw. ADC definieren
' ****** !!! ACHTUNG !!! **************************************************
'StatusLED
Config Pind.2 = Output 'Rot?
Config Pinb.0 = Output 'Grün?
'----------Odometrie-------------------
Dim Odorechts As Word 'data geht nciht, da expression
Dim Odolinks As Word
Config Pinc.2 = Input
Config Pinc.3 = Input
'----------Line-------------------
Dim Linerechts As Word
Dim Linelinks As Word
'Config Pinc.0 = Input 'Nur aktivieren wenn Backleds aus
'Config Pinc.1 = Input
'Pollswitch
'##########################################################################
'############################### Main #####################################
'##########################################################################
Do
Loop
End
'##########################################################################
'############################### Ende #####################################
'##########################################################################
'--------Subs-------------------------
Sub Motorspeed(byval Mlspeed As Byte , Byval Mrspeed As Byte)
Pwm1a = Mlspeed
Pwm1b = Mrspeed
End Sub
Sub Frontled(byval Led1 As Byte)
Portd.6 = Led1
End Sub
Sub Motordir(byval Mldir As Byte , Byval Mrdir As Byte)
If Mldir = 1 Then 'FWD
Portd.4 = 0
Portd.5 = 1
Elseif Mldir = 2 Then 'RWD
Portd.4 = 1
Portd.5 = 0
Elseif Mldir = 3 Then 'FREE
Portd.4 = 0
Portd.5 = 0
Elseif Mldir = 4 Then 'BRAKE
Portd.4 = 1
Portd.5 = 1
End If
'-----------------
If Mrdir = 1 Then 'FWD
Portb.4 = 0
Portb.5 = 1
Elseif Mrdir = 2 Then 'RWD
Portb.4 = 1
Portb.5 = 0
Elseif Mrdir = 3 Then 'FREE
Portb.4 = 0
Portb.5 = 0
Elseif Mrdir = 4 Then 'BRAKE
Portb.4 = 1
Portb.5 = 1
End If
End Sub
Sub Backled(byval Led1 As Byte , Byval Led2 As Byte)
Portc.1 = Led1
Portc.0 = Led2
End Sub
Sub Statusled(byval Color As Byte)
If Color = 0 Then 'Aus
Portd.2 = 0
Portb.0 = 0
Elseif Color = 1 Then 'ROT?
Portd.2 = 1
Portb.0 = 0
Elseif Color = 2 Then 'Green ?
Portd.2 = 0
Portb.0 = 1
Elseif Color = 3 Then 'Yellow
Portd.2 = 1
Portb.0 = 1
End If
End Sub
Sub Linie()
Linerechts = Getadc(2)
Linelinks = Getadc(3)
End Sub
Sub Odometrie()
Odorechts = Getadc(0)
Odolinks = Getadc(1)
End Sub
Ich würde mich freuen, wenn jemand das mal testen könnte.
@ Sonic: wie siehts aus, bist du weitergekommen?
MFG Moritz
Lesezeichen