'Erste Ideen für einen Zwischenchip, der mit den Steckdosen kommuniziert, und die Steuerung des multi-processor communication-mode übernimmt... $regfile = "m64def.dat" 'der Atmega 64 hat zwei UART-SChnittstellen für Kommunikation mit dem pc und den Steckdosen $crystal = 4000000 '$baud = 9600 'muss für beide Schnittstellen seperat eingestell werden ' USART 0= Kommunikation mit Chips ' USART 1= Kommunikation mit PC Sreg.7 = 1 'Interrupts enable 'Konfiguration USART 0: Ucsr0b = &B10011100 'Recieve Interrupt enable, 9 Bits, Reviecer, transmitter enable Ucsr0c = &B00000110 '9N1, asynchronous Ubrr0l = &B00011001 ' 9600 Baud bei4 Mhz 'Konfiguration USART 1: Ucsr1b = &B10011000 'Reciever int. enable, reciever transmitter enable, 8 Bits Ucsr1c = &B00000110 '8N1, asynchron Ubrr1l = &B00011001 '9600 Baud bei 4 Mhz 'Variablen:------------- Dim I0 As Byte 'Speicher für Befehle der UART Dim I1 As Byte Dim Hs1 As Bit 'Verbindung mit PC wird aufbegebaut Dim Dnumber1 As Byte Dim Pass As String * 15 Dim Prompt As Bit 'gültiger Befehl eingegangen? Dim Dcommandstring As String * 10 Dim Dcommand1 As Byte 'eigentlicher Befehl Dim Passchr As Byte At Pass Overlay Dim Transmit As Byte 'Anzahl der im Passwortstring gesendeten Bits Dim N As Word ' Für For-Schleifen Dim Befehlpos As Byte Dim Passzeit As Word Dim Rec As Bit Dim Passteil As Byte Dim Ausgabe As String * 20 Dim Hs As Bit Dim Recr As Bit '----------------- Mcucr = Mcucr And &B11000011 On Urxc Onempfangchip On Urxc1 Onempfangpc Main: Do Enable Interrupts Gicr = Gicr And &B00111111 Mcucr.se = 1 !sleep Loop 'Interrupts:--------- Onempfangpc: If Hs1 = 0 Then 'falls Handshake noch nicht erfolgt... I1 = Udr1 If I1 = &H25 Then 'Handshake: H:25 Udr1 = &H2B Hs1 = 1 Else Udr1 = I1 Goto Endpc End If Print #1 , "Nummer der Dose? (1-8) " For N = 1 To 20 If Ucsr1a.rxc = 1 Then 'neues Byte empfangen:Nummer Dnumber1 = Udr1 If Dnumber1 < 9 Then Hs1 = 1 Goto Befehl1 End If End If Waitms 500 Next N Hs1 = 0 Portb.0 = 0 Print #1 , "Zeit überschritten" Goto Resetvariablen Befehl1: Print #1 , "Befehl?" Tccr0 = &B00000101 'Timer 0 ein /1024 Timsk.toie0 = 1 'Timer0-Interrupt ein Hs1 = 1 Goto Endpc 'Jetzt wieder in die Hauptschleife, warten auf Passwort, Steckdose bleibt hier so lange außen ansprechbar End If If Prompt = 0 Then Dcommandstring = Dcommandstring + Chr(udr1) Befehlpos = Instr(dcommandstring , "unlock") If Befehlpos <> 0 Then Dcommand1 = &HEF Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "Unlock") If Befehlpos <> 0 Then Dcommand1 = &HEF Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "lock") If Befehlpos <> 0 Then Dcommand1 = &HCD Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "Lock") If Befehlpos <> 0 Then Dcommand1 = &HCD Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "open") If Befehlpos <> 0 Then Dcommand1 = &H6F Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "Open") If Befehlpos <> 0 Then Dcommand1 = &H6F Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "state") If Befehlpos <> 0 Then Dcommand1 = &HDE Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "State") If Befehlpos <> 0 Then Dcommand1 = &HDE Prompt = 1 Goto Pass End If Befehlpos = Instr(dcommandstring , "stop") If Befehlpos <> 0 Then Dcommand1 = &H8A Prompt = 1 Goto Exec End If Befehlpos = Instr(dcommandstring , "Stop") If Befehlpos <> 0 Then Dcommand1 = &H8A Prompt = 1 Goto Exec End If If Len(dcommandstring) > 9 Then Print "falscher Befehl" Goto Resetvariablen End If Pass: Print #1 , "Pass?" 'Timer0 für Zeit in der das Passwort akzeptiert wird, aktivieren: Passzeit = 0 Goto Endpc 'Jetzt wieder in die Hauptschleife, warten auf Passwort, Steckdose bleibt hier so lange außen ansprechbar End If If Rec = 0 Then I1 = Udr1 If I1 = &H99 Then Print #1 , "wird ausgeführt" Goto Exec End If Pass = Pass + Chr(udr1) Goto Endpc Exec: Tccr0 = &B00000000 'Timer 0 aus Timer aus Timsk.toie0 = 0 'Timer0-Interrupt aus Ucsr0b.txb8 = 1 'Adress-Byte: 9. Bit =1 I1 = Dnumber1 Printbin I1; Ucsr0b.txb8 = 0 'neue Bytes: Daten For N = 1 To 30 If Ucsr0a.rxc0 = 1 Then I1 = Udr If I1 = &HFF Then Goto Transmitr End If End If Waitms 5 Next N Print #1 , "Keine Verbindung?" Goto Resetvariablen Transmitr: I1 = Dcommand1 Printbin I1; For N = 1 To 30 If Ucsr0a.rxc0 = 1 Then I1 = Udr If I1 = &HFE Then Goto Passr End If End If Waitms 5 Next N Print #1 , "Befehl kann nicht übermittelt werden" Goto Resetvariablen Passr: Transmit = 0 For N = 1 To 2 I0 = "A" 'besser Zufallsbits? Printbin I0; Incr Transmit Waitms 50 Next N For N = 1 To Len(pass) I0 = Passchr Printbin I0; Incr Transmit Pass = Mid(pass , 2) 'ersten Buchstaben wegschneiden Waitms 50 Next N For N = Transmit To 20 I0 = "A" 'besser Zufallsbits? Printbin I0; Incr Transmit Waitms 50 Next N For N = 1 To 30 If Ucsr0a.rxc0 = 1 Then I1 = Udr If I1 = &HFD Then Rec = 1 Goto Recr End If End If Waitms 5 Next N Print #1 , "Passwort kann nicht übermittelt werden" Goto Resetvariablen End If Recr: For N = 1 To 255 If Ucsr0a.rxc0 = 1 Then I0 = Udr If I0 = &H99 Then Print #1 , Ausgabe Goto Label Else Ausgabe = Ausgabe + Chr(i0) End If End If Next N Label: Print &H00 For N = 1 To 30 If Ucsr0a.rxc0 = 1 Then I1 = Udr If I1 = &H00 Then Goto Endr End If End If Waitms 5 Next N Print #1 , "Kommunikation wurde nicht ordnungsgemäß beendet" Goto Resetvariablen Endr: Print #1 , "Erfolgreich" Goto Resetvariablen Resetvariablen: Hs = 0 Prompt = 0 Recr = 0 Passteil = 0 Pass = "" Dcommand1 = 0 Befehlpos = 0 Endpc: Return '---------------------------------------------------------- Onempfangchip: Return