'============================================= ' LCD-Test 8-Datenbit ' für Pollin LCD GC-1602GO ' viele Subroutines zur Initialisierung und Ausgabe ' '========================================= $regfile = "m8def.dat" $crystal = 8000000 '$baud = 9600 ' Initialisierung für 8-Bit Daten ' Anschluss an Port D ' Steuerleitungen Port C Config Portd = Output Config Portc = Output 'Steuerbits festlegen Rw Alias Portc.1 Rs Alias Portc.3 E Alias Portc.5 Port Alias Portd 'hier kann der Alias für den Port geändert werden Dim A As Byte , I As Byte , Istring As Byte , Z As Single , S1 As String * 16 Dim S As String * 16 At $400 'Beide Variablen, String und Byte() liegen Dim B(16) As Byte At $400 Overlay 'an der gleichen Stelle im Speicher Declare Sub Ini_lcd Declare Sub Wr_inibyte(byval D As Byte) Declare Sub Wr_chr(byval D As Byte) Declare Sub Clr_lcd Declare Sub Line1 Declare Sub Line2 Declare Sub Wr_string Declare Sub Wr_z(byval Zahl As Single , Byval Stellen As Byte) Call Ini_lcd Call Line1 '1. Ausgabezeile festlegen For A = 65 To 70 Call Wr_chr(32) Call Wr_chr(a) Next A Call Line2 '2. Ausgabezeile festlegen For A = 75 To 80 'und weitere Buchstaben ausgeben Call Wr_chr(a) Next A Wait 1 S = "Textausgabe" Call Wr_string Wait 1 Line1 'Zeilenwechsel S = "1. Zeile" Call Wr_string Wait 1 Line2 S = "2.Zeile bis Ende" Wr_string Wait 1 Line1 Z = -123.1234567890 'Zahlenausgabe als String S = Str(z) Wr_string 'Sub-Aufruf ohne "Call" wenn parameterlos Wait 1 Line2 Z = -123.123 'Zahlenausgabe als String S = Str(z) Wr_string 'Sub-Aufruf ohne "Call" wenn parameterlos S = String(16 , 32) '16 Leerzeichen Wr_string 'Rest der Zeile löschen Wait 1 Clr_lcd Wait 1 'Zahl mit angegebener Stellenzahl schreiben Line1 Z = 12.4987654 A = 6 Call Wr_z(z , A) 'Ausgabe von 6 Stellen 'funktioniert nicht Do Loop End 'end program '========================================================== Sub Ini_lcd ' Beginn der Initialisierung Rs = 0 'Rs = 0 ins Steuerregister Rw = 0 'Rw = 0 schreiben E = 0 Waitms 50 'Anfangspause Call Wr_inibyte(&H38) 'System Set (8 Bit Datenbus, 2 Zeilen) Waitms 10 Call Wr_inibyte(&H0e) 'LCD und Cursor einschalten Waitms 1 Call Wr_inibyte(&H06) 'Cursor springt nach dem Schreiben eine Position nach rechts Waitms 1 Call Clr_lcd 'Display löschen End Sub '=========================================================== Sub Wr_inibyte(byval D As Byte) Rs = 0 ' Steuerregister auswählen Rw = 0 E = 1 Waitus 1 ' Datenbits an den Datenbus Port = D Waitus 1 E = 0 'Daten übernehmen Waitus 100 '40us warten End Sub '========================================================== Sub Wr_chr(byval D As Byte) Rs = 1 'Datenregister auswählen Rw = 0 'Write enable E = 1 Waitus 1 Port = D 'Datenbits an den Datenbus Waitus 1 E = 0 'Daten übernehmen Waitus 80 '40us warten (bei Q=8MHz) End Sub '========================================================== Sub Clr_lcd 'CLEAR_LCD: Dim D As Byte Rs = 0 E = 1 Waitus 1 Port = &H01 'Datenbits an den Datenbus Waitus 1 E = 0 Waitms 10 'Pause erforderlich End Sub '========================================================== Sub Line1 Call Wr_inibyte(&H80) 'Anfang 1. Zeile End Sub '&H81 = nächste Position '========================================================== Sub Line2 Call Wr_inibyte(&Hc0) 'Anfang 2. Zeile End Sub '&HC1 = nächste Position '========================================================== Sub Wr_string 'String ganz ausgeben For Istring = 1 To Len(s) Call Wr_chr(b(istring)) Next Istring End Sub '========================================================== Sub Wr_z(byval Zahl As Single , Byval Stellen As Byte) S = Str(zahl) 'Übertragung auf die Ausgabevariable S B(stellen + 1) = 0 For Istring = 1 To 16 If B(istring) <> 0 Then Call Wr_chr(b(istring)) Else Istring = 16 End If Next Istring End Sub