'******************************************************************************* ' ' (c) Hans Borngräber 2008 ' MAS_V1_1a.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 Lidl Messschieber ' ' 2 x 24 Bit Messwert. Messwert 1 wird gelöscht nur Messwert 2 wird ausgewertet. ' ' 2er Komplement Ganzzahl 24 Bit. Bit 0 -3 werden gelöscht. ' ' Differenz zwischen Ausgabe und Wert und Anzeige 0,08mm pro 10mm ' '******************************************************************************* $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 * 1 'Binärstring Komplement Erkennung Dim Vz_text As String * 1 'Binärstring Vorzeichentext Dim Me As String * 1 'Binärstring Masseinheit 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 = 2 '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 , 6 , 24 'erster Messwert lesen L = 0 'Messwert verwerfen Shiftin Pinc.0 , Pinc.1 , L , 6 , 24 'zweiten Messwert einlesen 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 ; " mm" ; Chr(escape) ; "[K"; Print Chr(escape) ; "[6;1H" ; Chr(escape) ; "#4" ; "X-Achse :" ; Vz_text ; Mw_zahl ; " mm" ; Chr(escape) ; "[K" ; Chr(escape) ; "[14;1H" ; ">" ; 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:" ; Bin(l) ; Chr(escape) ; Print Chr(escape) ; "[6;1H" ; "X-Achse:" ; Bin(l) ; Chr(escape) ; "[14;1H" ; ">" ; End If End If '****** Y-Achse If Yflag = 0 Then Start Watchdog Shiftin Pinc.2 , Pinc.3 , L , 6 , 24 'erster Messwert lesen L = 0 'Messwert verwerfen Shiftin Pinc.2 , Pinc.3 , L , 6 , 24 'zweiten Messwert einlesen 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 ; " mm" ; Chr(escape) ; "[K"; Print Chr(escape) ; "[9;1H" ; Chr(escape) ; "#4" ; "Y-Achse :" ; Vz_text ; Mw_zahl ; " mm" ; Chr(escape) ; "[K" ; Chr(escape) ; "[14;1H" ; ">" ; Else Print Chr(escape) ; "[8;1H" ; "Y-Achse:" ; Bin(l) ; Chr(escape) ; Print Chr(escape) ; "[9;1H" ; "Y-Achse:" ; Bin(l) ; Chr(escape) ; "[14;1H" ; ">" ; End If End If '****** Z-Achse If Zflag = 0 Then Start Watchdog Shiftin Pinc.4 , Pinc.5 , L , 6 , 24 'erster Messwert lesen L = 0 'Messwert verwerfen Shiftin Pinc.4 , Pinc.5 , L , 6 , 24 'zweiten Messwert einlesen 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 ; " mm" ; Chr(escape) ; "[K"; Print Chr(escape) ; "[12;1H" ; Chr(escape) ; "#4" ; "Z-Achse :" ; Vz_text ; Mw_zahl ; " mm" ; Chr(escape) ; "[K" ; Chr(escape) ; "[14;1H" ; ">" ; Else Print Chr(escape) ; "[11;1H" ; "Z-Achse:" ; Bin(l) ; Chr(escape) ; Print Chr(escape) ; "[12;1H" ; "Z-Achse:" ; Bin(l) ; Chr(escape) ; "[14;1H" ; ">" ; End If End If Loop '****** Ende Hauptprogrammschleife '************************************* Subroutinen ************************************* '****** Dekodierroutine für Pollin Messschieber Dekoder: Shift L , Right , 4 Mw = Bin(l) S1 = Mid(mw , 20 , 1) If S1 = "1" Then L = 1048575 - L Vz_text = "-" Else Vz_text = "+" End If Mw_zahl = L / 100 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 ; Print Chr(escape) ; "[1;10H" ; "Messschieber Auslese System V1.1a (20Bit 2er Komplement)" Print Chr(escape) ; "[2;15H" ; "© 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 '****** 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