Code:$regfile = "m16def.dat" $crystal = 19999998 'Quarz: 3.6864 MHz $baud = 19200 Dim I As Byte Config Lcdpin = Pin , Db4 = Porta.6 , Db5 = Porta.5 , Db6 = Porta.4 , Db7 = Porta.3 , E = Porta.7 , Rs = Porta.2 ' Natürlich so wie es wirklich angeschlossen ist (4-Bit-Modus) Dim A As Byte Config Lcd = 20 * 4 'Baudrate der UART: 9600 Baud Config Pind.1 = Input Config Pind.0 = Output Config Pinb.3 = Output Config Pind.5 = Output Config Pind.2 = Input Dim Crc_l As Byte Dim Crc_h As Byte Dim New As Byte Dim Tmp As Byte Dim Bcclo As Byte Dim Bcchi As Byte Dim X As Byte Dim Crce As Word Dim Crcs As Word Dim Packets(10) As Byte Dim Packete(8) As Byte Declare Sub Sendewr Declare Sub Empfangewr Declare Sub Clc Declare Sub Lcdout Declare Sub Status Declare Sub Auswahltyp Dim Wrtyp As String * 10 Declare Sub Auswahlanzahl Dim Anzahl As Integer Dim Line1 As String * 20 Dim Line2 As String * 20 Dim Line3 As String * 20 Dim Line4 As String * 20 'PowerLED Portd.5 = 1 Portb.3 = 1 'Init Packets Packets(1) = 002 Packets(2) = 050 Packets(3) = 000 Packets(4) = 032 Packets(5) = 032 Packets(6) = 032 Packets(7) = 032 Packets(8) = 032 Packets(9) = 037 Packets(10) = 135 'Config Serialin = Buffered , Size = 8 Do 'Gosub Auswahltyp 'Taster 1 'If Pind.2 = 1 Then ' Line2 = " reset" ' Print "reset" ' Gosub Lcdout 'End If 'Taster 2 If Pind.4 = 1 Then Gosub Sendewr Gosub Empfangewr 'Gosub Status End If Loop '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'SUBs Sub Sendewr Line2 = " sende Anfrage" Printbin Packets(1) ; 10 Gosub Lcdout 'Gosub Clc Return End Sub Sendewr ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sub Empfangewr Line2 = " warte auf Daten" 'Gosub Lcdout Inputbin Packete(1) , 8 Printbin Packete(1) ; 8 Crce = Crc16(packete(1) , 6) Crc_l = Low(crce) Crc_h = High(crce) Cls Locate 1 , 1 Lcd "Empfangenes Paket:" Locate 2 , 1 Lcd "1:" ; Str(packete(1)) Locate 2 , 5 Lcd "2:" ; Str(packete(2)) Locate 2 , 9 Lcd "3:" ; Str(packete(3)) Locate 2 , 13 Lcd "4:" ; Str(packete(4)) Locate 2 , 17 Lcd "5:" ; Str(packete(5)) Locate 3 , 1 Lcd "6:" ; Str(packete(6)) Locate 3 , 5 Lcd "7:" ; Str(packete(7)) Locate 3 , 9 Lcd "8:" ; Str(packete(8)) Locate 4 , 1 Lcd "CRC_l:" ; Crc_l Locate 4 , 12 Lcd "CRC_H:" ; Crc_h 'Gosub Status Return End Sub Empfangewr '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'Checksumme berechnen Sub Clc Bcclo = &HFF Bcchi = &HFF Return End Sub Clc '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'LCD Ausgabe Sub Lcdout Cls Locate 1 , 1 '1. Zeile Lcd Line1 Locate 2 , 1 '2. Zeile Lcd Line2 Locate 3 , 1 '3. Zeile Lcd Line3 Locate 4 , 1 '4. Zeile Lcd Line4 Return End Sub Lcdout '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'Status Auswertung Sub Status If X = 6 Then Line3 = "ok" Print "kein fehler" Else Line3 = "Fehler" Print "fehler" End If Gosub Lcdout Return End Sub Status '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - End
Lesezeichen