Code:
'###################################################
''''''''''''''''''' FAHRPROG 2.1 '''''''''''''''''''
'###################################################
Declare Function Srf02_firmwarel(byval Slaveid As Byte) As Byte
Declare Function Srf02_entfernungl(byval Slaveid As Byte) As Integer
Declare Function Srf02_firmwarer(byval Slaveid As Byte) As Byte
Declare Function Srf02_entfernungr(byval Slaveid As Byte) As Integer
$regfile = "m32def.dat"
$framesize = 100
$swstack = 100
$hwstack = 100
$crystal = 16000000 'Quarzfrequenz
'''''''''''''''''''''lcd''''''''''''''''''
Config Lcd = 20 * 4 'wir verwenden ein 4 x 20 Zeichen Display
Cursor On
' Im I/O Mode wird jeder Prozessor Pin einzeln angegeben
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Config Adc = Single , Prescaler = Auto , Reference = Internal 'Für Tastenabfrage und Spannungsmessung
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Declare Sub Ind
Declare Sub Batteriespannung
Declare Sub Notstopp
'''''''''''''''''''''''''''''''''''''''''''
Declare Sub Fahrt1()
Declare Sub Rechtsfahrn()
Declare Sub Linksfahrn()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const Ref = 5 / 1024 'Für Batteriespannungsberechnung
Const Entf = -1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Entfernungl As Integer
Dim Entfernungr As Integer
Dim Volt1 As Integer
Dim Volt2 As Integer
Dim Grad As Integer
Dim Grad2 As Integer
Dim I As Integer
Dim N As Integer
Dim Ind As Integer
Dim Zentrum As Single
Dim Zentrum2 As Single
Dim Volt As Single
Dim Grad3 As Single
Dim Akku As Single
Dim Akku1 As Single
Dim Himmelsrichtung As Word
Dim Temperatur As Word
Dim Zentrum1 As Word
Dim Strom1 As Word
Dim Strom2 As Word
Dim Strom3 As Word
Dim Wsl As Word
Dim Wsr As Word
Dim W1 As Word
Dim Wertlow As Byte
Dim Werthigh As Byte
Dim I2cdaten(6) As Byte
Dim V As Byte
Deflcdchar 1 , 31 , 31 , 31 , 31 , 31 , 31 , 31 , 31 ' replace ? with number (0-7)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Cls
I2cinit
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
Cls
Locate 2 , 1
Lcd Chr(1)
Waitms 200
Locate 2 , 2
Lcd Chr(1)
Waitms 200
Locate 2 , 3
Lcd Chr(1)
Waitms 200
Locate 2 , 4
Lcd Chr(1)
Waitms 200
Locate 2 , 5
Lcd Chr(1)
Waitms 200
Locate 2 , 6
Lcd Chr(1)
Waitms 200
Locate 2 , 7
Lcd Chr(1)
Waitms 200
Locate 2 , 8
Lcd Chr(1)
Waitms 200
Locate 2 , 9
Lcd Chr(1)
Waitms 200
Locate 2 , 10
Lcd Chr(1)
Waitms 200
Locate 2 , 11
Lcd Chr(1)
Waitms 200
Locate 2 , 12
Lcd Chr(1)
Waitms 200
Locate 2 , 13
Lcd Chr(1)
Waitms 200
Locate 2 , 14
Lcd Chr(1)
Waitms 200
Locate 2 , 15
Lcd Chr(1)
Waitms 200
Locate 2 , 16
Lcd Chr(1)
Waitms 200
Locate 2 , 17
Lcd Chr(1)
Waitms 200
Locate 2 , 18
Lcd Chr(1)
Waitms 200
Locate 2 , 19
Lcd Chr(1)
Waitms 200
Locate 2 , 20
Lcd Chr(1)
Wait 1
Cls
Locate 2 , 3
Lcd " moin =) "
Wait 1
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
Wait 1
I2cstart
I2cwbyte &H5A
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
Sound Portd.7 , 400 , 350
Waitus 500
Sound Portd.7 , 500 , 650
Waitus 700
Sound Portd.7 , 300 , 650
For I = 0 To 1 ' interne Pullup Widerständ ein,bis auf Batteriespannungsmessungsport
Wait 1
Cls
Locate 1 , 1
Lcd "SRF02 L Ultraschall-Firmware Version:" ; Srf02_firmwarel(&He2)
Wait 1
'Temperatur abrufen
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 44 'Befehl
I2cstop
Waitms 200
I2cstart
I2cwbyte &H59
I2crbyte Wertlow , Ack
I2crbyte Werthigh , Nack
I2cstop
Temperatur = Makeint(wertlow , Werthigh )
Grad = Temperatur / 1.6
Grad2 = Grad + 5
Cls
Locate 2 , 3
Lcd "BOARD Temperatur: "
Locate 3 , 10
Lcd ; Grad2 ; " C"
Wait 2
Call Batteriespannung()
Cls
Locate 1 , 1
Lcd "AKKU Spannung : " ; Volt ; " Volt"
Wait 2
Sound Portd.7 , 600 , 150
Waitus 500 'BEEP
Sound Portd.7 , 200 , 350
Waitms 200 'BEEP
Sound Portd.7 , 400 , 650
Waitms 200
Sound Portd.7 , 200 , 350 'BEEP
Sound Portd.7 , 400 , 250
Sound Portd.7 , 600 , 300
Waitms 500
Sound Portd.7 , 200 , 600
Waitms 500
Sound Portd.7 , 400 , 800
Sound Portd.7 , 500 , 250
Wait 1
Config Pina.0 = Input
Config Pina.1 = Input
Config Pina.2 = Input
Cls
Locate 3 , 3
Lcd "WALL-E 2.0 ;) "
Wait 2
V = 1
Start Adc
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do
Entfernungr = Srf02_entfernungr(&He0)
Entfernungl = Srf02_entfernungl(&He2)
For I = 0 To 4
Start:
Wsr = Getadc(0)
Volt = Wsr * Ref
Wsl = Getadc(1)
Volt = Wsl * Ref
For I = 2 To 500
Ind = Getadc(2)
Volt1 = Ind * Ref
Volt2 = Volt1 * 10000
''''''''''''''''''''''''''''''''''
Next I
Cls
Locate 1 , 1
Lcd "r " ; 0 ; "ADC: " ; Wsr ;
Locate 2 , 9
Lcd "l" ; 1 ; "ADC: " ; Wsl ;
Waitms 100
Locate 3 , 1
Lcd ": " ; Ind
If Ind > 5 Then Gosub Ind
If Entfernungl > 50 Then Gosub Fahrt1
If Strom2 > 1000 Then Gosub Hind3
If Strom1 > 1000 Then Gosub Hind4
If Strom3 > 900 Then Gosub Notstopp
If Entfernungl < 25 And Entfernungr > Entfernungl And Entfernungl > -1 Then Gosub Linksturn
If Entfernungr < 25 And Entfernungr < Entfernungl And Entfernungr > -1 Then Gosub Rechtsturn
If Entfernungr < 50 And Entfernungr < Entfernungl And Entfernungr > -1 And Wsl < 80 Then Call Linksfahrn
If Entfernungl < 50 And Entfernungl < Entfernungr And Wsr < 80 Then Call Rechtsfahrn
If Entfernungl = -1 And Entfernungr = -1 Then Gosub Fahrt1
If Wsr > 500 Then Gosub Rechtsturn
If Wsl > 500 Then Gosub Linksturn
If Wsl > 100 Then Gosub Schnellrechtsfahrn
If Wsr > 400 And Wsl > 400 Then Gosub Hind3
If Wsr > 100 Then Gosub Schnelllinksfahrn
Next I
Loop
Lesezeichen