ich kann dir mal mein musterrobbi-code geben. ich empfange die seriellen daten über interrupt. der code funktioniert auf dem AVR32 :
Code:
$Regfile = "M32def.dat"
$Crystal = 8000000
$HWStack = 32
$SWStack = 32
$FrameSize = 64
$Baud = 19200
Dim M_wert_a As Byte , M_wert_b As Byte
Dim Text As String * 16
Declare Sub Robby_vor()
Declare Sub Robby_zurueck()
Declare Sub Robby_links()
Declare Sub Robby_rechts()
Declare Sub Robby_links_drehen()
Declare Sub Robby_rechts_drehen()
Declare Sub Robby_aus()
Declare Sub L293_pin()
declare sub empfang()
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear down , Compare B Pwm = Clear down , Prescale = 256
Start Timer1
config int2=rising
On Int2 Int2_int
Enable Interrupts
Enable Int2
Open "comb.2:9600,8,n,1" For Input As #1
Open "comd.6:9600,8,n,1" For Output As #2
Call L293_pin()
do
waitms 300
loop
End
Int2_int:
Disable Int2
Enable Interrupts
input #1, text
waitms 10
call empfang()
enable int2
Return
sub empfang()
If Text = "vor" Then
M_wert_a = 100
M_wert_b = 100
Call Robby_vor()
End If
If Text = "zurueck" Then
M_wert_a = 100
M_wert_b = 100
Call Robby_zurueck()
End If
If Text = "links" Then
M_wert_a = 60
M_wert_b = 60
Call Robby_links()
End If
If Text = "rechts" Then
M_wert_a = 60
M_wert_b = 60
Call Robby_rechts()
End If
If Text = "stop" Then
Call Robby_aus()
End If
end sub
Sub L293_pin()
Ddrc.2 = 1
Ddrc.3 = 1
Ddrc.4 = 1
Ddrc.5 = 1
Ddrd.4 = 1
Ddrd.5 = 1
End Sub
Sub Robby_vor()
Portc.2 = 0 'rechter motor
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0 'linker motor
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_zurueck()
Portc.2 = 1 'rechter motor
Portc.3 = 0
Portd.5 = 1
Portc.4 = 1 'linker motor
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0
Portc.5 = 0
Portd.4 = 0
Pwm1a = M_wert_a
Pwm1b = 0
End Sub
Sub Robby_rechts()
Portc.2 = 0
Portc.3 = 0
Portd.5 = 0
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = 0
Pwm1b = M_wert_b
End Sub
Sub Robby_aus()
Portc.2 = 0
Portc.3 = 0
Portd.4 = 0
Portc.4 = 0
Portc.5 = 0
Portd.5 = 0
Pwm1a = 0
Pwm1b = 0
End Sub
Sub Robby_rechts_drehen()
Portc.2 = 1
Portc.3 = 0
Portd.5 = 1
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links_drehen()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 1
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Lesezeichen