'******************************************************************************* ' ' (c) Hans Borngräber 2008 ' MAS_V1_1.bas ' Digital-Messschieber Anzeige auf dem Hyperterminal ' 24.08.2008 '------------------------------------------------------------------------------- ' ' Einstellungen Hyperterminal ' ' Baudrate : 38400 ' Parity : None ' Bits : 8 ' Startbit : 1 ' Emulation : VT100J ' Codierung : Standard JIS ' Lokales Echo : ein ' Zeichensatz : Terminal ' Schriftgröße : 14 ' '------------------------------------------------------------------------------- ' ' Satzaufbau Pollin Messschieber ' ' Bit 28-25 : 4 Bit 1/100 Stelle Messwert ' Bit 24-21 : 4 Bit 1/10 Stelle Messwert ' Bit 20-17 : 4 Bit 1er Stelle Messwert ' Bit 16-13 : 4 Bit 10er Stelle Messwert ' Bit 12-9 : 4 Bit 100er Stelle Messwert ' Bit 7 : 1 Bit Vorzeichen (+/-) ' Bit 5 : 1 Bit Maßeinheit (mm/inch) ' '******************************************************************************* $regfile = "m8def.dat" 'Atmega 8 CPU $crystal = 16000000 '16Mhz Quarztakt $baud = 38400 'RS232 38400,8,n,1 $hwstack = 32 $swstack = 16 $framesize = 24 '****** Variable definieren Dim L As Long 'Einlesevariable Dim Mw As String * 32 'Binärstring komplett Dim S1 As String * 4 'Binärstring 1/100 Dim S2 As String * 4 'Binärstring 1/10 Dim S3 As String * 4 'Binärstring 1er Dim S4 As String * 4 'Binärstring 10er Dim S5 As String * 4 'Binärstring 100er Dim Vz As String * 1 'Binärstring Vorzeichen Dim Vz_text As String * 1 'Binärstring Vorzeichentext Dim Me As String * 1 'Binärstring Masseinheit Dim S1i As Integer 'Zahl 1/100 Dim S2i As Integer 'Zahl 1/10 Dim S3i As Integer 'Zahl 1er Dim S4i As Integer 'Zahl 10er Dim S5i As Integer 'Zahl 100er Dim Mw_text As String * 6 'Ausgabe Text Dim Term_cls As String * 4 'Sequenz Bildschirm löschen Dim Escape As Byte 'Escape Zeichen Dim Tin As Byte 'Zeichen der tastureingabe Dim Bin_flag As Byte 'Flag für Binärausgabe Dim Mw_zahl As Single 'Messwert als ganze Zahl Dim Radius_flag As Byte 'Messwert der X-Achse umgerechnet Dim Xflag As Byte 'Einschalt Flag X-Achse Dim Yflag As Byte 'Einschalt Flag Y-Achse Dim Zflag As Byte 'Einschalt Flag Z-Achse Dim Exflag As Eram Byte 'Einschalt Flag Speicherwert X-Achse Dim Eyflag As Eram Byte 'Einschalt Flag Speicherwert Y-Achse Dim Ezflag As Eram Byte 'Einschalt Flag Speicherwert Z-Achse Config Watchdog = 1024 'Watchdog Wert ca. 1sec Config Single = Scientific , Digits = 3 'Einstellen der Variable für den seriellen Messwert Config Portc.0 = Input 'Takt-Eingang X-Achse Config Portc.1 = Input 'Daten-Eingang X-Achse Config Portc.2 = Input 'Takt-Eingang Y-Achse Config Portc.3 = Input 'Daten-Eingang Y-Achse Config Portc.4 = Input 'Takt-Eingang Z-Achse Config Portc.5 = Input 'Daten-Eingang Z-Achse Config Portd.2 = Output 'Schaltport Daten X-Achse Config Portd.3 = Output 'Schaltport Takt X-Achse Config Portd.4 = Output 'Schaltport Takt Y-Achse Config Portd.5 = Output 'Schaltport Daten Y-Achse Config Portd.6 = Output 'Schaltport Takt Z-Achse Config Portd.7 = Output 'Schaltport Daten Z-Achse '**** Schaltausgänge zurücksetzen Portd.2 = 0 Portd.3 = 0 Portd.4 = 0 Portd.5 = 0 Portd.6 = 0 Portd.7 = 0 '**** Schaltflags zurücksetzen Bin_flag = 0 Radius_flag = 0 '****** Definition ANSI Steuersequenzen Escape = &H1B 'Escape Zeichen Term_cls = Chr(escape) + "[2J" 'Bildschirm löschen Gosub Screen_init '****** Einlesen der Messschieber Konfiguration aus dem EERAM Xflag = Exflag Yflag = Eyflag Zflag = Ezflag If Xflag = 255 Then If Yflag = 255 Then If Zflag = 255 Then Gosub Einrichten 'Wenn kein Daten da, Konfiguration abfragen End If End If End If Wait 2 Gosub Alle_nullen 'Alle Messschieber auf null Gosub Screen_init Gosub Tastatur '************************************* Hauptprogrammschleife Do '****** X-Achse If Xflag = 0 Then Start Watchdog Shiftin Pinc.0 , Pinc.1 , L , 7 , 32 'Daten einlesen X-Achse Reset Watchdog Gosub Dekoder 'Daten dekodieren Gosub Tastatur 'PC-Tastatur abfragen If Radius_flag = 1 Then 'Umrechnen des X-Achsen Wertes für Drehmaschinen Mw_zahl = Mw_zahl * 2 End If If Bin_flag = 0 Then Print Chr(escape) ; "[5;1H" ; Chr(escape) ; "#3" ; "X-Achse :" ; Vz_text ; Mw_zahl ; Chr(escape) ; "[K"; Gosub Masseinheit Print Chr(escape) ; "[6;1H" ; Chr(escape) ; "#4" ; "X-Achse :" ; Vz_text ; Mw_zahl ; Chr(escape) ; "[K"; Gosub Masseinheit If Radius_flag = 1 Then Print Chr(escape) ; "[22;36H" ; "aktiv" ; Chr(escape) ; "[14;1H" ; ">" ; Else Print Chr(escape) ; "[22;36H" ; Chr(escape) ; "[K" ; Chr(escape) ; "[14;1H" ; ">" ; End If Else Print Chr(escape) ; "[5;1H" ; "X-Achse :" ; Mw ; Chr(escape) ; Print Chr(escape) ; "[6;1H" ; "X-Achse :" ; Mw ; Chr(escape) ; "[14;1H" ; ">" ; End If End If '****** Y-Achse If Yflag = 0 Then Start Watchdog Shiftin Pinc.2 , Pinc.3 , L , 7 , 24 'Daten einlesen Y-Achse Reset Watchdog Gosub Dekoder 'Daten dekodieren Gosub Tastatur 'PC-Tastatur abfragen If Bin_flag = 0 Then Print Chr(escape) ; "[8;1H" ; Chr(escape) ; "#3" ; "Y-Achse :" ; Vz_text ; Mw_zahl ; Chr(escape) ; "[K"; Gosub Masseinheit Print Chr(escape) ; "[9;1H" ; Chr(escape) ; "#4" ; "Y-Achse :" ; Vz_text ; Mw_zahl ; Chr(escape) ; "[K"; Gosub Masseinheit Else Print Chr(escape) ; "[8;1H" ; "Y-Achse :" ; Mw ; Chr(escape) ; Print Chr(escape) ; "[9;1H" ; "Y-Achse :" ; Mw ; Chr(escape) ; "[14;1H" ; ">" ; End If End If '****** Z-Achse If Zflag = 0 Then Start Watchdog Shiftin Pinc.4 , Pinc.5 , L , 7 , 32 'Daten einlesen Z-Achse Reset Watchdog Gosub Dekoder 'Daten dekodieren Gosub Tastatur 'PC-Tastatur abfragen If Bin_flag = 0 Then Print Chr(escape) ; "[11;1H" ; Chr(escape) ; "#3" ; "Z-Achse :" ; Vz_text ; Mw_zahl; Gosub Masseinheit Print Chr(escape) ; "[12;1H" ; Chr(escape) ; "#4" ; "Z-Achse :" ; Vz_text ; Mw_zahl ; Gosub Masseinheit Else Print Chr(escape) ; "[8;1H" ; "Z-Achse :" ; Mw ; Chr(escape) ; Print Chr(escape) ; "[9;1H" ; "Z-Achse :" ; Mw ; Chr(escape) ; "[14;1H" ; ">" ; End If End If Loop '****** Ende Hauptprogrammschleife '************************************* Subroutinen ************************************* '****** Dekodierroutine für Pollin Messschieber Dekoder: Mw = Bin(l) 'Umwandlung in Binär String S1 = Mid(mw , 28 , 4) '1/100 Stelle S2 = Mid(mw , 24 , 4) '1/10 Stelle S3 = Mid(mw , 20 , 4) '1 er Stelle S4 = Mid(mw , 16 , 4) '10er Stelle S5 = Mid(mw , 12 , 4) '100er Stelle S1i = Binval(s1) 'Binär --> Integer S2i = Binval(s2) S3i = Binval(s3) S4i = Binval(s4) S5i = Binval(s5) Vz = Mid(mw , 7 , 1) 'Vorzeichen ermitteln If Vz = "0" Then Vz_text = "+" Else Vz_text = "-" End If Me = Mid(mw , 5 , 1) 'Masseinheit ermitteln und Anzeige Text zusammenstellen If Me = "1" Then Mw_text = Str(s5i) + Str(s4i) + Str(s3i) + "." + Str(s2i) + Str(s1i) Mw_zahl = Val(mw_text) Else Mw_text = Str(s4i) + "." + Str(s3i) + Str(s2i) + Str(s1i) Mw_zahl = Val(mw_text) End If Return '****** Tastatur Abfrage Tastatur: Tin = Inkey() If Tin > 0 Then If Tin = "b" Then Bin_flag = 1 End If If Tin = "c" Then Gosub Nullen End If If Tin = "d" Then Bin_flag = 0 Radius_flag = 0 End If If Tin = "e" Then Gosub Einrichten End If If Tin = "f" Then Gosub Fastread End If If Tin = "r" Then Radius_flag = 1 End If If Tin = &H1B Then Gosub Screen_init End If End If Print Chr(escape) ; "[14;1H" ; ">" ; Chr(escape) ; "[K"; Return '****** Bildschirm initialisieren Screen_init: Print Term_cls ; Chr(escape) ; "[41m" ; Chr(escape) ; "[37m" ; Term_cls ; Print Chr(escape) ; "[1;20H" ; "Messschieber Auslese System V1.1" Print Chr(escape) ; "[2;25H" ; "© Hans Borngraeber 2008" Print Chr(escape) ; "[5;1H" ; Chr(escape) ; "#3" ; "X-Achse :" ; Print Chr(escape) ; "[6;1H" ; Chr(escape) ; "#4" ; "X-Achse :" ; Print Chr(escape) ; "[8;1H" ; Chr(escape) ; "#3" ; "Y-Achse :" ; Print Chr(escape) ; "[9;1H" ; Chr(escape) ; "#4" ; "Y-Achse :" ; Print Chr(escape) ; "[11;1H" ; Chr(escape) ; "#3" ; "Z-Achse :" ; Print Chr(escape) ; "[12;1H" ; Chr(escape) ; "#4" ; "Z-Achse :" ; Print Chr(escape) ; "[16;2H" ; "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"; Print Chr(escape) ; "[17;2H" ; "º b = binaer º"; Print Chr(escape) ; "[18;2H" ; "º c = clear º"; Print Chr(escape) ; "[19;2H" ; "º d = dezimal º"; Print Chr(escape) ; "[20;2H" ; "º e = einrichten º"; Print Chr(escape) ; "[21;2H" ; "º f = fast read ein/aus º"; Print Chr(escape) ; "[22;2H" ; "º r = Durchmesser/Radius º"; Print Chr(escape) ; "[23;2H" ; "º ESC = Bildschirm neu aufbauen º"; Print Chr(escape) ; "[24;2H" ; "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"; Print Chr(escape) ; "[14;1H" ; ">" ; Chr(escape) ; "[K"; If Xflag = 255 Then Print Chr(escape) ; "[5;1H" ; "X-Achse : n.a." ; Print Chr(escape) ; "[6;1H" ; "X-Achse : n.a." ; Chr(escape) ; "[14;1H" ; ">" ; End If If Yflag = 255 Then Print Chr(escape) ; "[8;1H" ; "Y-Achse : n.a." ; Print Chr(escape) ; "[9;1H" ; "Y-Achse : n.a." ; Chr(escape) ; "[14;1H" ; ">" ; End If If Zflag = 255 Then Print Chr(escape) ; "[11;1H" ; "Z-Achse : n.a." ; Print Chr(escape) ; "[12;1H" ; "Z-Achse : n.a." ; Chr(escape) ; "[14;1H" ; ">" ; End If Return '****** Ausgabe der Masseinheit Masseinheit: If Me = "1" Then Print " mm " ; Chr(escape) ; "[14;1H" ; ">" ; Else Print " inch" ; Chr(escape) ; "[14;1H" ; ">" ; End If Return '****** Fastread ein / ausschalten Fastread: '**** Z-Achse Portd.2 = 1 Waitms 40 Portd.2 = 0 Waitms 200 Portd.3 = 1 Waitms 40 Portd.3 = 0 Reset Watchdog '**** Y-Achse Portd.5 = 1 Waitms 40 Portd.5 = 0 Waitms 200 Portd.4 = 1 Waitms 40 Portd.4 = 0 Reset Watchdog '**** X-Achse Portd.7 = 1 Waitms 40 Portd.7 = 0 Waitms 200 Portd.6 = 1 Waitms 40 Portd.6 = 0 Reset Watchdog Return '******* Messschieber auf Null Nullen: Print Chr(escape) ; "[14;1H" ; ">Welche Achse auf Null (x,y,z,a)? " ; Chr(escape) ; "[K"; Do Tin = Inkey() Reset Watchdog If Tin > 0 Then If Tin = "z" Then 'Z-Achse auf Null Portd.3 = 1 Waitms 300 Portd.3 = 0 Reset Watchdog End If If Tin = "y" Then 'Y-Achse auf Null Portd.4 = 1 Waitms 300 Portd.4 = 0 Reset Watchdog End If If Tin = "x" Then 'X-Achse auf Null Portd.6 = 1 Waitms 300 Portd.6 = 0 Reset Watchdog End If If Tin = "a" Then 'alle Achsen auf Null Gosub Alle_nullen End If End If Loop Until Tin > 0 Print Chr(escape) ; "[14;1H" ; ">" ; Chr(escape) ; "[K"; Reset Watchdog Return '****** Alle Achsen nullen Alle_nullen: Portd.3 = 1 Waitms 300 Portd.3 = 0 Reset Watchdog Portd.4 = 1 Waitms 300 Portd.4 = 0 Reset Watchdog Portd.6 = 1 Waitms 300 Portd.6 = 0 Reset Watchdog Return '****** Messschieber einrichten Einrichten: Print Chr(escape) ; "[14;1H" ; ">" ; Chr(escape) ; "[K" ; "Welche Achsen sind angeschlossen (xyz,l)?"; Do Tin = Inkey() If Tin > 0 Then If Tin = "x" Then Xflag = 0 Exflag = 0 End If If Tin = "y" Then Yflag = 0 Eyflag = 0 End If If Tin = "z" Then Zflag = 0 Ezflag = 0 End If If Tin = "l" Then Exflag = 255 Eyflag = 255 Ezflag = 255 End If End If Reset Watchdog Loop Until Tin = &H0D Gosub Screen_init Return End