'T13_KT0837_LCD07.bas
'In Anlehnung an Programmbeispiel I2C.BAS in
'"Messen-Steuern-Regeln mit dem C-Control/Basic-System" von B. Kainka
'LCD-Display im 8-Bit-Modus
$regfile = "attiny13.dat"
$crystal = 1200000
'T25-KT0837_LCD2.bas
$hwstack = 16
$swstack = 16
$framesize = 16
Declare Sub Read_reg()
Declare Sub Lcd_write()
Declare Sub Lcd_char()
Declare Sub Lcd_cmd()
Declare Sub Nullausbl()
'Dim Lcd_param As Byte
Dim Ziffer As Word
Dim Dat_byte As Byte
Dim R As Byte
Dim Hi As Byte
Dim F As Word
Dim Lo As Byte
Config Sda = Portb.4
Config Scl = Portb.3
Config I2cdelay = 40
I2cinit
E Alias Portb.0 'an Pin E des Displays
Rs Alias Portb.1 'an Pin RS des Displays
Config Portb.0 = Output
Config Portb.1 = Output
Lcd_init:
Reset E
Dat_byte = &H38
Lcd_cmd 'Initialisierung, zwei Zeilen
Dat_byte = &H0E ' Display ein, nicht blinkender Cursor
Lcd_cmd
Waitms 200
Do
R = &H13
Read_reg
'Frequenz
F = Hi * 256
F = F + Lo
F = F * 5
F = F + 6400
Ausgabe:
Dat_byte = 1 'Löschen
Lcd_cmd
Dat_byte = 2 'Cursor home
Lcd_cmd
Dat_byte = &H80 'Zeile1
Lcd_cmd
Ziffer = F \ 10000
Nullausbl
F = F Mod 10000
Ziffer = F \ 1000
Dat_byte = Ziffer + 48
Lcd_char
F = F Mod 1000
Ziffer = F \ 100
Dat_byte = Ziffer + 48
Lcd_char
F = F Mod 100
Dat_byte = 46 'Dezimalpunkt.
Lcd_char
Ziffer = F \ 10
Dat_byte = Ziffer + 48
Lcd_char
Dat_byte = 32 'Blank
Lcd_char
Dat_byte = 77 'M
Lcd_char
Dat_byte = 72 'H
Lcd_char
Dat_byte = 122 'z
Lcd_char
Dat_byte = 192 'in 2. Zeile wechseln
Lcd_cmd
Dat_byte = 32 'Blank
Lcd_char
Dat_byte = 76 'L
Lcd_char
Dat_byte = 58 ' Doppelpunkt
Lcd_char
R = &H04
'Lautstaerke
Read_reg
Ziffer = Lo \ 10 ' Wert für Lautstärke
Nullausbl
Ziffer = Lo Mod 10 ' Wert für Lautstärke
Dat_byte = Ziffer + 48
Lcd_char
Waitms 100
Loop
Sub Lcd_write()
I2cstart
'Adresse des PCF8574:64
I2cwbyte 64
I2cwbyte Dat_byte ' Auszugebende Daten
I2cstop
End Sub
Sub Read_reg()
I2cstart
I2cwbyte &H6E
I2cwbyte R
I2cstart
I2cwbyte &H6F
I2crbyte Hi , Ack
I2crbyte Lo , Nack
I2cstop
End Sub
Sub Nullausbl()
If Ziffer = 0 Then
Dat_byte = 32
Else
Dat_byte = Ziffer + 48
End If
Lcd_char
End Sub
Sub Lcd_cmd()
Reset Rs
'RW=0, da an GND
Lcd_write
Gosub Togglen
End Sub
Sub Lcd_char()
'RW=0, da an GND
Set Rs
Lcd_write
Gosub Togglen
End Sub
Togglen:
Set E
Reset E
Set E
Reset E
Return