'-----------------Chip select M2560----------------------- $regfile = "m2560def.dat" $crystal = 8000000 'F=8Mhz intern '--------------------------------------------------- Const Pv = "2.00.00" 'Versionsnummer als Konstante deklarieren '--------Konfiguration der I/O-Ports´s-------------- Config Portf = &B11011111 'PortF einstellen F0 Eingang Config Porth = &B11111100 'PortH einstellen Config Portj = &B11111100 'PortJ einstellen Config Portk = &B00000011 'PortK einstellen Config Pinf.5 = Input 'Start TTL Pinf.5 = 1 'Pullup-Widerstand aktivieren Config Pind.0 = Input 'Notaus Pind.0 = 1 'Pullup-Widerstand aktivieren Config Pind.1 = Input 'Sonderfreigabe TTL Pind.1 = 1 'Pullup-Widerstand aktivieren Config Pind.6 = Input 'Eingang PWREN Pind.6 = 1 'Pullup-Widerstand aktivieren Config Pind.5 = Input 'DTR vom Terminal Pind.5 = 1 'Pullup Config Portd.4 = Output 'DSR zum Terminal Config Porte.2 = Output 'RS485 Tx '--------------------------------------------------- Dim Temp1 As Byte '-----------------------UART Anfang--------------------------------------------- $baud = 38400 'Definieren einer allgemeinen Schnittstelle 'RS485 $baud1 = 38400 'definieren von Com2(muss sein sonst lässt sich Com2-4 nicht definieren Config Com2 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Debugging(FTDI) Config Com3 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Powersource Config Com4 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Display '-----------------------UART Ende----------------------------------------------- Config Serialin0 = Buffered , Size = 15 , Bytematch = 13 'RS485 Config Serialin2 = Buffered , Size = 15 , Bytematch = 10 'RS232 - Powersource Config Serialin3 = Buffered , Size = 15 , Bytematch = 10 'RS232 - LCD $framesize = 100 'Stackanweisungen $swstack = 200 $hwstack = 100 '--------------------------------------------------- Open "com1:" For Binary As #1 'öffne Port für Binary Open "com2:" For Binary As #2 'öffne Port für Binary Open "com3:" For Binary As #3 'öffne Port für Binary Open "com4:" For Binary As #4 'öffne Port für Binary Enable Interrupts 'aktiviere Interrupts in SREG Register Declare Sub Serial0charmatch() Declare Sub Serial2charmatch() Declare Sub Serial3charmatch() Declare Sub O_port_test() Declare Sub Rs232_ps_test() Declare Sub Rs232_lcd_test() Declare Sub Led_test() Dim Tmp As Byte Dim New_command As String * 15 Dim Command_array(3) As String * 5 Dim New_status As Bit Dim Auto_flag As Byte Dim X As Integer , A As Byte Dim New_command_str As String * 15 Dim Test_init_flag As Byte Dim Test_begin_flag As Byte Dim S As String * 20 Dim I As Integer '-------Konfigurieren Alias------------------------- Rs485 Alias Porte.2 'Tx Leitung vom RS485 auf senden bei high Rs485 = 0 'Rx Leitung an Dtr Alias Pind.5 'DTR vom Terminal Dsr Alias Portd.4 'DSR zum Terminal Notaus Alias Pind.0 'Notaus Start_imp Alias Pinf.5 'Startimpuls Sonder Alias Pind.1 'Sonderfreigabe Pic_reset Alias Porth.2 'PIC Reset P_up Alias Porth.3 'Phase_up oder PH1 P_down Alias Porth.4 'Phase_down oder PH2 Main: Do Porte.2 = 1 Waitms 100 Print #1 , "main gestartet" Wait 10 Porte.2 = 0 Wait 10 Loop Sub O_port_test() Porte.2 = 1 Waitms 100 Print #1 , "Test der Outputs/roten LEDs?" Print #1 , "'j' fuer ja; 'n' fuer nein" Mv1 = 1 Print #1 , "Leuchtet LED 7?" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Temp1 = Waitkey(#1) 'Warte Auf Daten ' If Temp1 = &H6A Then 'wenn sync Byte dann weiter, ansonsten Start Porte.2 = 1 Waitms 100 Print #1 , "Test ok" Else Porte.2 = 1 Waitms 100 Print #1 , "Bitte fehlerhafte LED tauschen" End If Waitms 100 Porte.2 = 0 Mv1 = 0 End Sub Sub Rs232_ps_test() Porte.2 = 1 Waitms 100 Print #1 , "Verbindung c24 und c25 gebrueckt?" Print #1 , "bitte mit 'j' bestätigen" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Temp1 = Waitkey(#1) 'Warte Auf Daten ' If Temp1 = &H6A Then 'wenn sync Byte dann weiter, ansonsten Start Porte.2 = 1 Waitms 100 Print #1 , "Signal wird an Powersource gesendet" Waitms 100 Porte.2 = 0 Print #3 , "PS" ; Printbin #3 , &H0A Else Porte.2 = 1 Waitms 100 Print #1 , "fehlerhafte Eingabe" End If Waitms 100 Porte.2 = 0 End Sub Sub Rs232_lcd_test() Porte.2 = 1 Waitms 100 Print #1 , "Verbindung c18 und c19 gebrueckt?" Print #1 , "bitte mit 'j' bestätigen" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Temp1 = Waitkey(#1) 'Warte Auf Daten ' If Temp1 = &H6A Then 'wenn sync Byte dann weiter, ansonsten Start Porte.2 = 1 Waitms 100 Print #1 , "Signal wird an LCD gesendet" Waitms 100 Porte.2 = 0 Print #4 , "LCD" ; Printbin #4 , &H0A Else Porte.2 = 1 Waitms 100 Print #1 , "fehlerhafte Eingabe" End If Waitms 100 Porte.2 = 0 End Sub Sub Serial0charmatch() 'wenn CARRIAGE RETURN empfangen wird. (Mainboard/Measurementboard) New_command = "" 'String leeren S = "" 'String leeren Do A = Inkey(#1) 'UART Zeichen einlesen If A > 31 Then S = S + Chr(a) 'alle Buchstaben einlesen Loop Until A = &H0D 'bis CR New_command = S For I = 1 To Len(new_command) 'Schleife bis String_Ende If Left(new_command , I) = Chr(10) Then New_command = Mid(new_command , 2) 'wenn LF dann eine Pos weiter Next I A = Val(new_command) 'aus String new_command --> byte If New_command <> "" Then 'neu empfangen den letzten String löschen New_command_str = "" 'String löschen For I = 1 To Len(new_command) 'Schleife bis String_Ende If Mid(new_command , I , 1) = "_" Then 'Unterstrich erkannt New_command_str = New_command_str + " " 'ersetzen durch Leerzeichen Else New_command_str = New_command_str + Mid(new_command , I , 1) 'alles andere wird übergeben End If Next I New_command = New_command_str 'neuen String übergeben End If New_command = Ucase(new_command) 'Alles in Großbuchstaben Tmp = Split(new_command , Command_array(1) , " ") 'Anweisung aufteilen Select Case Command_array(1) 'nicht mehr als 5 Buchstaben verwendbar Case "VER" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , "Version: " ; Pv Waitms 100 Porte.2 = 0 Case "OUT" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " Test der outputs startet" Waitms 100 Porte.2 = 0 Gosub O_port_test Case "PS" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " RS 232 PS Test" Waitms 100 Porte.2 = 0 Gosub Rs232_ps_test Case "LCD" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " RS 232 LCD Test" Waitms 100 Porte.2 = 0 Gosub Rs232_lcd_test Case "LED" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " led test" Waitms 100 Porte.2 = 0 Gosub Led_test Case Else Porte.2 = 1 Waitms 100 Print #1 , "ERROR: unknown command RS485" Waitms 100 Porte.2 = 0 End Select New_command = "" End Sub Sub Serial2charmatch() 'wenn CARRIAGE RETURN empfangen wird.(Powersource) 'If Debug_flag = 1 Then Print #2 , "Serial Powersource Interrupt" New_command = "" 'String leeren S = "" 'String leeren Do A = Inkey(#3) 'UART Zeichen einlesen If A > 31 Then S = S + Chr(a) 'alle Buchstaben einlesen Loop Until A = &H0A 'bis LF New_command = S For I = 1 To Len(new_command) 'Schleife bis String_Ende If Left(new_command , I) = Chr(10) Then New_command = Mid(new_command , 2) 'wenn LF dann eine Pos weiter Next I A = Val(new_command) 'aus String new_command --> byte If New_command <> "" Then 'neu empfangen den letzten String löschen New_command_str = "" 'String löschen For I = 1 To Len(new_command) 'Schleife bis String_Ende If Mid(new_command , I , 1) = "_" Then 'Unterstrich erkannt New_command_str = New_command_str + " " 'ersetzen durch Leerzeichen Else New_command_str = New_command_str + Mid(new_command , I , 1) 'alles andere wird übergeben End If Next I New_command = New_command_str 'neuen String übergeben End If New_command = Ucase(new_command) 'Alles in Großbuchstaben Tmp = Split(new_command , Command_array(1) , " ") 'Anweisung aufteilen Select Case Command_array(1) 'nicht mehr als 5 Buchstaben verwendbar Case "PS" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , "PS funktioniert" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Case "LCD" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , "LCD funktioniert" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Case "OUT" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " Test der outputs startet" Waitms 100 Porte.2 = 0 Gosub O_port_test Case Else Porte.2 = 1 Waitms 100 Print #1 , "ERROR: unknown command RS232-PS" Waitms 100 Porte.2 = 0 End Select New_command = "" End Sub Sub Serial3charmatch() 'wenn CARRIAGE RETURN empfangen wird.(LCD) 'If Debug_flag = 1 Then Print #2 , "Serial Powersource Interrupt" New_command = "" 'String leeren S = "" 'String leeren Do A = Inkey(#4) 'UART Zeichen einlesen If A > 31 Then S = S + Chr(a) 'alle Buchstaben einlesen Loop Until A = &H0A 'bis LF New_command = S For I = 1 To Len(new_command) 'Schleife bis String_Ende If Left(new_command , I) = Chr(10) Then New_command = Mid(new_command , 2) 'wenn LF dann eine Pos weiter Next I A = Val(new_command) 'aus String new_command --> byte If New_command <> "" Then 'neu empfangen den letzten String löschen New_command_str = "" 'String löschen For I = 1 To Len(new_command) 'Schleife bis String_Ende If Mid(new_command , I , 1) = "_" Then 'Unterstrich erkannt New_command_str = New_command_str + " " 'ersetzen durch Leerzeichen Else New_command_str = New_command_str + Mid(new_command , I , 1) 'alles andere wird übergeben End If Next I New_command = New_command_str 'neuen String übergeben End If New_command = Ucase(new_command) 'Alles in Großbuchstaben Tmp = Split(new_command , Command_array(1) , " ") 'Anweisung aufteilen Select Case Command_array(1) 'nicht mehr als 5 Buchstaben verwendbar Case "LCD" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , "LCD funktioniert" 'Print #1 , Bin(sreg) Waitms 100 Porte.2 = 0 Case "OUT" 'Programm Infos ausgeben Porte.2 = 1 Waitms 100 Print #1 , " Test der outputs startet" Waitms 100 Porte.2 = 0 Gosub O_port_test Case Else Porte.2 = 1 Waitms 100 Print #1 , "ERROR: unknown command RS232-PS" Waitms 100 Porte.2 = 0 End Select New_command = "" End Sub