Hi Daniel,
auch dir Danke für deine Hilfe.
Puh, da bin ich aber Froh das der Max232 überflüssig ist. Habe die Platine gestern fertig gefräst.
Quellcode für den Sender Atmega8 (das wichtige steht ganz unten)
Code:
'*******************************************************************************
'*******************************************************************************
'******************************* CyBot V1.0 ************************************
'*******************************************************************************
'************************** 01.10.2012 by CYBORG *******************************
'*******************************************************************************
'*******************************************************************************
'****************************** Allgemein **************************************
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
'**************************** LCD - Anzeige ************************************
Declare Sub Print_out()
$baud = 19200
Dim Lcdcount As Integer
'**************************** LED - Anzeige ************************************
Declare Sub Led_mode()
Led Alias Portc.1
Config Led = Output
Dim Led_in As Integer
Dim Led_out As Integer
Dim Led_count As Integer
Dim Led_modus As String * 16
Led_modus = "Stop"
'******************************* Sensoren **************************************
Declare Sub Sensor_check()
Smfront Alias Pind.3
Srfront Alias Pind.4
Slfront Alias Pinb.6
Smback Alias Pind.6
Srback Alias Pinc.4
Slback Alias Pind.7
S1 Alias Pind.5
S2 Alias Pinb.7
Config Smfront = Input
Config Srfront = Input
Config Slfront = Input
Config Smback = Input
Config Srback = Input
Config Slback = Input
Config S1 = Input
Config S2 = Input
Portb.7 = 1 'PullUp-Widerstand einschalten
Portb.6 = 1 'PullUp-Widerstand einschalten
Portc.4 = 1 'PullUp-Widerstand einschalten
Portd.3 = 1 'PullUp-Widerstand einschalten
Portd.4 = 1 'PullUp-Widerstand einschalten
Portd.5 = 1 'PullUp-Widerstand einschalten
'***************************** RC5 - Sensor ************************************
Declare Sub Rc5_check()
'Config Rc5 = Pind.2
'$lib "mcsbyte.lbx"
'Enable Interrupts
'Dim Rc5count As Integer
'Dim Address As Byte , Command As Byte
Rc5 Alias Pind.2
Config Rc5 = Input
Portd.2 = 1
Config Timer0 = Timer , Prescale = 1
On Timer0 Timer_irq
Const Timervorgabe = 34
Enable Timer0
Enable Interrupts
Dim Rc5bit As Bit
'*************************** Motor - Antrieb ***********************************
Declare Sub M_move()
Mrfront Alias Portb.0
Mrback Alias Portc.3
Mrspeed Alias Portb.1
Mlfront Alias Portb.5
Mlback Alias Portb.4
Mlspeed Alias Portb.2
Config Mrfront = Output
Config Mrback = Output
Config Mrspeed = Output
Config Mlfront = Output
Config Mlback = Output
Config Mlspeed = Output
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 1
Compare1a = 0
Compare1b = 0
Dim Mfast As Integer
Dim Mmedium As Integer
Dim Mslow As Integer
Dim Mstop As Integer
Dim Mtimer As Integer
Dim Mmodus As String * 16
Mfast = 255
Mmedium = 205
Mslow = 155
Mstop = 0
'*************************** Motor - Lüfter ************************************
Cleaner Alias Portb.3
Config Cleaner = Output
Cleaner = 0
'Config Timer0 = Pwm , Prescale = 1
'**************************** DC - Messung *************************************
Declare Sub Adc_check()
Const Adc_const = 0.0048828125 ' = 5.0 / 1024.0
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Dim Adc_value As Word
Dim Adc_volt As Single
Dim Adc_count As Integer
'*********************** Start - Hauptprogramm *********************************
Do
'LED Anzeigemodus setzen
Led_mode
'Spannung messen
Adc_check
'Sensoren abfragen
Sensor_check
'IR abfragen
Rc5_check
'Motoren steuern
M_move
'Display ausgabe
Print_out
Loop
'************************ Start - LED Anzeige **********************************
Sub Led_mode()
'Modus setzen
Select Case Led_modus
Case "Normal"
Led_in = 6000
Led_out = 6000
Case "Srfront"
Led_in = 500
Led_out = 500
Case "Slfront"
Led_in = 500
Led_out = 500
Case "Srback"
Led_in = 500
Led_out = 500
Case "Slback"
Led_in = 500
Led_out = 500
Case Else
Led_in = 1
Led_out = 0
End Select
'Led anzeige
If Led = 0 Then
If Led_count >= Led_out Then
Led = 1
Led_count = 0
Else
Led_count = Led_count + 1
End If
Elseif Led = 1 Then
If Led_count >= Led_in Then
Led = 0
Led_count = 0
Else
Led_count = Led_count + 1
End If
End If
End Sub
'********************* Start - Spannungsmessung ********************************
Sub Adc_check()
If Adc_count = 500 Then
Adc_value = Getadc(5)
Adc_volt = Adc_value * Adc_const
Adc_count = 0
Else
Adc_count = Adc_count + 1
End If
End Sub
'************************ Start - Sensorcheck **********************************
Sub Sensor_check()
Select Case 1
Case Srfront
Led_modus = "Srfront"
Case Slfront
Led_modus = "Slfront"
Case Srback
Led_modus = "Srback"
Case Slback
Led_modus = "Slback"
Case Else
Led_modus = "Normal"
End Select
End Sub
'********************* Start - Antriebssteuerung *******************************
Sub M_move()
'Auf neue Sensorauslösung reagieren, ggf. Timer abbrechen
If Led_modus <> Mmodus And Led_modus <> "Normal" Then
Mmodus = Led_modus
Mtimer = 0
Else
'Modus bis Timerende durchlaufen
If Mtimer > 0 Then
Mmodus = Mmodus
Else
Mmodus = Led_modus
Mtimer = 0
End If
End If
Select Case Mmodus
Case "Stop"
Mrfront = 0
Mrback = 0
Mlfront = 0
Mlback = 0
Compare1a = Mstop
Compare1b = Mstop
Case "Normal"
Mrfront = 1
Mrback = 0
Mlfront = 1
Mlback = 0
Compare1a = Mmedium
Compare1b = Mmedium
Case "Srfront"
If Mtimer <= 15000 Then
'Zurück fahren
Mrfront = 0
Mrback = 1
Mlfront = 0
Mlback = 1
Compare1a = Mmedium
Compare1b = Mmedium
Elseif Mtimer <= 32000 Then
'rechts drehen
Mrfront = 0
Mrback = 1
Mlfront = 1
Mlback = 0
Compare1a = Mmedium
Compare1b = Mmedium
Else
Mtimer = 0
Mmodus = "Normal"
End If
Case "Slfront"
If Mtimer <= 15000 Then
'Zurück fahren
Mrfront = 0
Mrback = 1
Mlfront = 0
Mlback = 1
Compare1a = Mmedium
Compare1b = Mmedium
Elseif Mtimer <= 32000 Then
'rechts drehen
Mrfront = 1
Mrback = 0
Mlfront = 0
Mlback = 1
Compare1a = Mmedium
Compare1b = Mmedium
Else
Mtimer = 0
Mmodus = "Normal"
End If
Case "Srback"
If Mtimer <= 15000 Then
'Zurück fahren
Mrfront = 1
Mrback = 0
Mlfront = 1
Mlback = 0
Compare1a = Mmedium
Compare1b = Mmedium
Elseif Mtimer <= 32000 Then
'rechts drehen
Mrfront = 1
Mrback = 0
Mlfront = 0
Mlback = 1
Compare1a = Mmedium
Compare1b = Mmedium
Else
Mtimer = 0
Mmodus = "Normal"
End If
Case "Slback"
If Mtimer <= 15000 Then
'Zurück fahren
Mrfront = 1
Mrback = 0
Mlfront = 1
Mlback = 0
Compare1a = Mmedium
Compare1b = Mmedium
Elseif Mtimer <= 32000 Then
'rechts drehen
Mrfront = 0
Mrback = 1
Mlfront = 1
Mlback = 0
Compare1a = Mmedium
Compare1b = Mmedium
Else
Mtimer = 0
Mmodus = "Normal"
End If
End Select
End Sub
'*********************** Start - IR-Aktion ********************************
Sub Rc5_check()
'If Rc5count = 8 Then
' Getrc5(address , Command)
' If Address <> 255 Then
' Print Address ; Command
' End If
' Rc5count = 0
'Else
' Rc5count = Rc5count + 1
'End If
End Sub
Timer_irq:
Timer0 = Timervorgabe
'Motorlaufzeit zählen
If Mmodus <> "Normal" Then
Mtimer = Mtimer + 1
End If
'IR-Schnittstelle abfragen
If Rc5 = 0 Then
Rc5bit = 0
End If
Return
'*********************** Start - DisplayAusgabe ********************************
Sub Print_out()
If Lcdcount = 5000 Then
Print "HalloDu!"
Lcdcount = 0
Else
Lcdcount = Lcdcount + 1
End If
End Sub
End
Und eine Variante für den Attiny2313 (Empfänger)
Code:
'*******************************************************************************
'*******************************************************************************
'************************** LCD to TXD/RXD V1.0 ********************************
'*******************************************************************************
'************************** 12.10.2012 by CYBORG *******************************
'*******************************************************************************
'*******************************************************************************
'****************************** Allgemein **************************************
$regfile = "attiny2313.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 19200
'************************************ Buzzer ***********************************
Buzzer Alias Portd.6
Config Buzzer = Output
'************************************* LCD *************************************
Config Lcdpin = Pin , Db4 = Portd.5 , Db5 = Portb.0 , Db6 = Portd.4 , _
Db7 = Portd.3 , E = Portb.1 , Rs = Portb.2
Config Lcd = 16 * 1a
Initlcd
Cls
Locate 1 , 1
Lcd " SYSTEM "
Locate 2 , 1
Lcd "loading!"
'******************************** Taster ***************************************
Tfor Alias Pind.2
Tmode Alias Pina.0
Tback Alias Pina.1
Config Tfor = Input
Config Tmode = Input
Config Tback = Input
Portd.2 = 1 'PullUp-Widerstand einschalten
Porta.0 = 1 'PullUp-Widerstand einschalten
Porta.1 = 1 'PullUp-Widerstand einschalten
'******************************** TXD/RXD **************************************
Dim My_string As String * 1
'*********************** Start - Hauptprogramm *********************************
Do
If Ischarwaiting() = 1 Then
My_string = Inkey()
Cls
Lcd My_string
End If
Loop
End
-die Leitungen habe ich nochmal geprüft, die sollten passen.
-das Programm für die Attiny habe ich auch mal aufs nötigste gekürzt hat nichts gebracht.
-FuseBits kontrolliere ich jetzt nochmal
mfG
Mario
Lesezeichen