- Labornetzteil AliExpress         
Seite 2 von 2 ErsteErste 12
Ergebnis 11 bis 13 von 13

Thema: rs232 und i2c gleichzeitig in einem programm???

  1. #11
    Super-Moderator Robotik Visionär Avatar von PicNick
    Registriert seit
    23.11.2004
    Ort
    Wien
    Beiträge
    6.842
    Anzeige

    Powerstation Test
    Wieso verwendest du Soft-UART ?

    Ich wette, dein Porgramm steckt hier:
    Code:
    Inputbin #2 , Hib , Lob 'Warte auf Ergebnis
    mfg robert
    Wer glaubt zu wissen, muß wissen, er glaubt.

  2. #12
    Neuer Benutzer Öfters hier
    Registriert seit
    01.01.2011
    Beiträge
    11
    ok.warum? ich hab den teil aus der demo übernommen-die demo ist gleiche die auch kampi gepostet hat.

    mfg jörg
    Geändert von highblackbon (12.12.2011 um 10:00 Uhr)

  3. #13
    Neuer Benutzer Öfters hier
    Registriert seit
    01.01.2011
    Beiträge
    11
    hallo

    um das thema mal hier abzuschliessen:
    ich hab den srf02 und das rn motorcontrol über I2C mit dem rn control verbunden.
    mit diesem ersten einfachen code läuft das ganze:

    Declare Function Srf02_firmware(byval Slaveid As Byte) As Byte
    Declare Function Srf02_entfernung(byval Slaveid As Byte) As Integer


    $regfile = "m32def.dat"
    $framesize = 60
    $swstack = 60
    $hwstack = 60

    $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





    Dim Entfernung As Integer
    Dim V As Byte

    Cls
    Locate 2 , 3
    Lcd "moin chef"
    Waitms 900
    Cls
    Locate 1 , 1
    Lcd "RN-CONTROL V1.4 "
    Cls
    Waitms 800
    Locate 2 , 6
    Lcd "Fahrprog1"
    Wait 1


    I2cinit
    Const Srf02_slaveid = &HE2

    Cls
    Locate 1 , 1
    Lcd "SRF02 Ultraschall-Firmware Version:" ; Srf02_firmware(srf02_slaveid)
    Wait 1

    V = 1
    Do

    I2cinit
    I2cwbyte &HE2 'Standard I2C Adresse von SRF02
    Entfernung = Srf02_entfernung(srf02_slaveid)
    Cls
    Locate 2 , 1
    Lcd "Entfernung:" ; Entfernung ; "cm"
    Waitms 65
    If Entfernung < 27 Then Gosub Hind

    Cls
    Locate 2 , 5
    Lcd "vorwaerts..."


    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 5 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 1 'Richtung
    I2cstop
    Waitms 500
    I2cstart 'Motor 1 starten (Geschwindigkeit=45
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 1 'Motorwahl
    I2cwbyte 195 'Geschwindigkeit
    I2cstop
    Waitms 250

    I2cstart 'Motor 2 starten (Geschwindigkeit=45
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 2 'Motorwahl
    I2cwbyte 175 'Geschwindigkeit
    I2cstop







    Loop


    End

    '''''''''''''''''''''
    Hind:


    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 0 'Geschwindigkeit
    I2cstop

    Waitms 500
    I2cstart 'Motor Rechts drehen
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 5 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 0 'Richtung
    I2cstop
    Waitms 100
    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 175 'Geschwindigkeit
    I2cstop
    Wait 2
    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 0 'Geschwindigkeit
    I2cstop
    'motor2 starten andersrum
    I2cstart 'Motor Rechts drehen
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 5 'Befehl
    I2cwbyte 1 'Motorwahl
    I2cwbyte 0 'Richtung
    I2cstop

    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 1 'Motorwahl
    I2cwbyte 185 'Geschwindigkeit
    I2cstop
    Waitms 250
    I2cstart 'Beide Motoren Rechts drehen
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 5 'Befehl
    I2cwbyte 2 'Motorwahl
    I2cwbyte 1 'Richtung
    I2cstop
    Waitms 250
    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 2 'Motorwahl
    I2cwbyte 195 'Geschwindigkeit
    I2cstop
    Wait 4
    I2cstart
    I2cwbyte &H58
    I2cwbyte 35 'Kennung
    I2cwbyte 2 'Befehl
    I2cwbyte 3 'Motorwahl
    I2cwbyte 0 'Geschwindigkeit
    I2cstop
    Wait 1




    Return
    '------------- Hilfsfunktionen für SRF02 ----------


    Function Srf02_firmware(byval Slaveid As Byte) As Byte
    Local Firmware As Byte
    Local Slaveid_read As Byte

    Slaveid_read = Slaveid + 1

    I2cstart
    I2cwbyte Slaveid
    I2cwbyte 0 'Leseregister festlegen
    I2cstop

    I2cstart
    I2cwbyte Slaveid_read
    I2crbyte Firmware , Nack
    I2cstop

    Srf02_firmware = Firmware
    End Function



    Function Srf02_entfernung(byval Slaveid As Byte) As Integer
    Local Lob As Byte
    Local Hib As Byte
    Local Firmware As Byte
    Local Temp As Byte
    Local Slaveid_read As Byte

    Slaveid_read = Slaveid + 1

    'Messvorgang in starten
    I2cstart
    I2cwbyte Slaveid
    I2cwbyte 0
    I2cwbyte 81 'in Zentimetern messen
    I2cstop


    Waitms 65 'minimale Wartezeit für Messung bei SRF02

    I2cstart
    I2cwbyte Slaveid
    I2cwbyte 2 'Leseregister festlegen
    I2cstop


    I2cstart
    I2cwbyte Slaveid_read
    I2crbyte Hib , Ack
    I2crbyte Lob , Nack
    I2cstop


    Srf02_entfernung = Makeint(lob , Hib)
    End Function

    mfg jörg

Seite 2 von 2 ErsteErste 12

Ähnliche Themen

  1. Antworten: 3
    Letzter Beitrag: 15.02.2009, 16:46
  2. Antworten: 8
    Letzter Beitrag: 30.06.2008, 20:54
  3. Antworten: 7
    Letzter Beitrag: 10.01.2008, 00:51
  4. RS485 UND RS232 gleichzeitig an ATMega32??
    Von dl1akp im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 1
    Letzter Beitrag: 23.11.2006, 15:47
  5. Antworten: 4
    Letzter Beitrag: 28.01.2004, 12:35

Stichworte

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Solar Speicher und Akkus Tests