Code:
$regfile = "8535def.dat" 'definieren des verwendeten Chips
$crystal = 8000000 'definieren des verwendeten externen Quarz (8MHz)
'Funktionen zur Display-Ansteuerung 4-Bit
'========================================
'Anschluss Konfiguration
Const Lcd_port = Portb
Const Lcd_ddr = Ddrb
Const Lcd_pin = Pinb
Const Lcd_d4 = 0
Const Lcd_d5 = 1
Const Lcd_d6 = 2
Const Lcd_d7 = 3
Const Lcd_rs = 4
Const Lcd_rw = 5
Const Lcd_e1 = 6
Const Lcd_e2 = 7
'Hauptfunktionen
Declare Sub Lcd_init()
Declare Sub Lcd_send(byval Cnr As Integer , Byval Cmd As Byte , Byval Rs As Integer)
'Declare Sub Lcd_command(byval Cnr As Integer , Byval Cmd As Byte)
'Declare Sub Lcd_char(byval Nr As Integer , Byval Char As String)
'Declare Sub Lcd_text(byval Txt As String)
'Declare Sub Lcd_busy(byval Cnr As Integer)
'-------------------------------------------------------------------------------
'Dim Lcd_zeile(1 To 4) As String * 27
Dim Ausgabe As String * 27
'im Res As Integer
Dim Test As Byte
Ddrd = &B11100000 'definieren der verwendeten Ports ( 1 = ausgang; 0= eingang)
Portd = &B00000000 'definieren der einzelnen Pins an einem Port ( 0= low level; 1= high level)
'Hauptprogramm
'Startbeep
'Portd = &B10000000
Waitms 100
Portd = &B00000000
Portd = &B01000000
Call Lcd_init
Portd = &B01100000
Ausgabe = "Hallo Raphael"
'Call Lcd_text( "Hallo!!!")
Test = &B11111111
Call Lcd_send(0, Test, 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B01000100 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B01000100 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Call Lcd_send(0 , &B00100010 , 1)
Call Lcd_send(0 , &B11111111 , 1)
Portd = &B00000000
Wait 5
End 'end program
Sub Lcd_init():
'Initialisiert beide Controller, mit je zwei Zeilen
Ddrb = &B11111111
Portb = &B00000000
'3?h ins Steuerregister
Portb = &B11000011
Waitms 1
Portb = &B00000011
Waitms 5
Portb = &B11000011
Waitms 1
Portb = &B00000011
Waitms 5
Portb = &B11000011
Waitms 1
Portb = &B00000011
Waitms 5
'4 Bit Modus anschalten
Portb = &B11000010
Waitms 1
Portb = &B00000010
Waitms 200
'send command verwenden
'system set -> Betriebsart festlegen
Portb = &B11000010
Waitms 1
Portb = &B00000010
Waitms 5
Portb = &B11001000
Waitms 1
Portb = &B00001000
Waitms 5
'Call Lcd_send(0 , &B00101000 , 0)
'display on
Portb = &B11000000
Waitms 1
Portb = &B00000000
Waitms 5
Portb = &B11001111
Waitms 1
Portb = &B00001111
Waitms 5
'display clear
Portb = &B11000000
Waitms 1
Portb = &B00000000
Waitms 5
Portb = &B11000001
Waitms 1
Portb = &B00000001
Waitms 5
'Cursor Home
Portb = &B11000000
Waitms 1
Portb = &B00000000
Waitms 5
Portb = &B11000010
Waitms 1
Portb = &B00000010
Waitms 5
'Set Ddram
Portb = &B11001000
Waitms 1
Portb = &B00001000
Waitms 5
Portb = &B11000000
Waitms 1
Portb = &B00000000
Waitms 5
End Sub
Sub Lcd_send(ByVal Cnr As Integer, ByVal Cmd As Byte, ByVal Rs As Integer)
Local Nr1 As Integer
Local Nr2 As Integer
Local Tmp As Byte
'Cmd = &B00111000
'Cnr = 1
'Rs = 1
If Cnr = 0 Then
Nr1 = 1
Nr2 = 1
End If
If Cnr = 1 Then
Nr1 = 1
Nr2 = 0
End If
If Cnr = 2 Then
Nr1 = 0
Nr2 = 1
End If
'Bits 7...4 einstellen
Tmp = &B00000000
Tmp.0 = Cmd.4
Tmp.1 = Cmd.5
Tmp.2 = Cmd.6
Tmp.3 = Cmd.7
Tmp 0.4 = Rs
Tmp 0.6 = 1
Tmp 0.7 = Nr2
Portb = Tmp
Waitms 1
Tmp 0.6 = 0
Tmp 0.7 = 0
Portb = Tmp
Waitms 5
'Dasselbe mit Bits 0 bis 3
Tmp = &B00000000
Tmp.0 = Cmd.0
Tmp.1 = Cmd.1
Tmp.2 = Cmd.2
Tmp.3 = Cmd.3
Tmp 0.4 = Rs
Tmp 0.6 = 1
Tmp 0.7 = Nr2
Portb = Tmp
Waitms 1
Tmp 0.6 = 0
Tmp 0.7 = 0
Portb = Tmp
Waitms 5
End Sub
Lesezeichen