So Leudles,
ich hab jetzt mal meinen Quick'n Dirty BASCOM-Portierung des ASUROS hier gepostet. Für alle die kein C++ können/lernen wollen
!ACHTUNG!
Der untenstehende Code lässt sich mit der DEMO-VERSION von Bascom nicht kompilieren, das Hex-File wird zu groß.
Damit es funktioniert muss ein Teil der aufgerufenen Testfunktionen mit ' ausgeklammert werden ;-(
Die Odometrie fehlt noch, funktioniert aber analog zum Abfragen des Tasters. Nur der ADC-Channel ist ein anderer...
Um rauszubekommen welcher Taster/n gedrückt ist, muss man den Wert noch umrechnen, muss ich noch mal knobeln wie die den Spannungsteiler aufgebaut haben.
Achso, hat jemand ne Ahnung warum man Getadc() einfach nicht in eine Funktion gepackt bekommt? print getadc(4) funktioniert im Hauptprogram einwandfrei, in einer Funktion geht's nicht. Klärt mich mal bitte auf 
Ansonsten viel Spaß 
Gruß, Sonic
Code:
'**********************************************************
'ASURO - Steuerungs- und Sensorikfunktionen
'**********************************************************
'Ansteuerung der Motoren
'----------------------------------------------------------
' +-------+--------+--------+-------+
' | ML-V | ML-R | MR-V | MR-R |
' +-------+--------+--------+-------+
' PORT D.4 | 0 | 1 | X | X |
' +-------+--------+--------+-------+
' PORT D.5 | 1 | 0 | X | X |
' +-------+--------+--------+-------+
' PORT D.1 | 1 | 1 | X | X | <- ML Enable
' +-------+--------+--------+-------+
' PORT B.4 | X | X | 0 | 1 |
' +-------+--------+--------+-------+
' PORT B.5 | X | X | 1 | 0 |
' +-------+--------+--------+-------+
' PORT B.2 | X | X | 1 | 1 | <- MR Enable
' +-------+--------+--------+-------+
'***********************************************************
' Begin Functions
'***********************************************************
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 2400
Config Timer0 = Timer , Prescale = 8
On Timer0 Timer_irq
Const Timervorgabe = 217
Enable Timer0
Enable Interrupts
'ADC für Taster
Config Adc = Single , Prescaler = Auto , Reference = Avcc
'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
'FrontLED
Config Pind.6 = Output
'BackLEDs
Config Pinc.0 = Output
Config Pinc.1 = Output
'FrontLED
Config Pind.6 = Output
'StatusLED
Config Pind.2 = Output
Config Pinb.0 = Output
'Taster
Config Pind.3 = Output
'Tasterwert nach Aufruf von Pollswitch (Funktioniert in einer Funktion leider nicht ;-()
Dim Switch As Word
'Pwm -zähler
Dim Pwmcounter As Integer
Dim Tout As String * 20
Dim Pwml As Byte
Dim Pwmr As Byte
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 Led As Byte)
Declare Sub Statusled(byval Led1 As Byte , Byval Led2 As Byte)
Declare Sub Pollswitch
Portb.4 = 0
Portb.5 = 1
Portd.4 = 0
Portd.5 = 1
Pwmcounter = 0
Pwml = 0 'pwmvariablen initialisieren
Pwmr = 0
Dim Temp As String * 4
Dim I As Integer
Dim Pwm As Integer
Dim Tasterval As Word
Start Adc
Portd.3 = 1
'*** Hauptprogramm **********************************
Do
Print "-- ASURO BASCOM-Routinen -- www.roboternetz.de ---"
Print "---> Testing all functions..."
Print "------> Blinking 10 times with BackLEDs..."
For I = 1 To 10
Print "---------> 0,1"
Call Backled(0 , 1)
Waitms 50
Print "---------> 1,0"
Call Backled(1 , 0)
Waitms 50
Next
Print "------> Blinking 10 times with FrontLED..."
For I = 1 To 10
Print "---------> 1"
Call Frontled(1)
Waitms 50
Print "---------> 0"
Call Frontled(0)
Waitms 50
Next
Print "------> Changing 10 times the color of the StatusLED..."
For I = 1 To 10
Print "---------> 0,0"
Call Statusled(0 , 0)
Waitms 100
Print "---------> 1,0"
Call Statusled(1 , 0)
Waitms 100
Print "---------> 0,1"
Call Statusled(0 , 1)
Waitms 100
Print "---------> 1,1"
Call Statusled(1 , 1)
Waitms 100
Next
'
Print "------> DRIVETEST: FWD(150), FWD(150), "
Call Motordir(1 , 1)
Call Motorspeed(150 , 150)
Wait 2
Call Motorspeed(0 , 0)
Print "---------> Motors Free..."
Call Motordir(0 , 0)
Wait 1
Print "------> DRIVETEST: RWD(150), RWD(150), "
Call Motordir(2 , 2)
Call Motorspeed(150 , 150)
Wait 2
Call Motorspeed(0 , 0)
Print "---------> Motors Stop..."
Call Motordir(1 , 1)
Wait 1
Print "------> Testing switches, press any switch..."
For I = 1 To 10
Call Pollswitch
Waitms 300
Print Switch
Do
loop
End 'end program
'*** Hauptprogramm Beendet ****************************************
'*** SUBs ********************************************
Sub Pollswitch()
Switch = Getadc(4)
End Sub
Sub Statusled(byval Led1 As Byte , Byval Led2 As Byte)
Portd.2 = Led1
Portb.0 = Led2
End Sub
Sub Frontled(byval Led As Byte)
If Led = 0 Then Portd.6 = 0
If Led = 1 Then Portd.6 = 1
End Sub
Sub Backled(byval Led1 As Byte , Byval Led2 As Byte)
' ****** !!! ACHTUNG !!! **************************************************
' 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 !!! **************************************************
If Led1 = 1 Then Portc.0 = 1 Else Portc.0 = 0
If Led2 = 1 Then Portc.1 = 1 Else Portc.1 = 0
End Sub
Sub Motorspeed(byval Mlspeed As Byte , Byval Mrspeed As Byte)
Pwml = Mlspeed
Pwmr = Mrspeed
End Sub
Sub Motordir(mldir As Integer , Mrdir As Integer )
If Mldir = 1 Then 'FWD
Portd.4 = 0
Portd.5 = 1
End If
If Mldir = 2 Then 'RWD
Portd.4 = 1
Portd.5 = 0
End If
If Mldir = 3 Then 'FREE
Portd.4 = 0
Portd.5 = 0
End If
If Mldir = 4 Then 'BRAKE
Portd.4 = 1
Portd.5 = 1
End If
'-----------------
If Mrdir = 1 Then 'FWD
Portb.4 = 0
Portb.5 = 1
End If
If Mrdir = 2 Then 'RWD
Portb.4 = 1
Portb.5 = 0
End If
If Mrdir = 3 Then 'FREE
Portb.4 = 0
Portb.5 = 0
End If
If Mrdir = 4 Then 'BRAKE
Portb.4 = 1
Portb.5 = 1
End If
End Sub
'Dies ist der Programmteil, der in dem von ihnen gewählten
'Intervall aufgerufen wird
Timer_irq:
Timer0 = Timervorgabe
Pwmcounter = Pwmcounter + 1
If Pwmcounter >= 255 Then Pwmcounter = 0
If Pwml > Pwmcounter Then Portb.1 = 1
If Pwml < Pwmcounter Then Portb.1 = 0
If Pwmr > Pwmcounter Then Portb.2 = 1
If Pwmr < Pwmcounter Then Portb.2 = 0
Return
Lesezeichen