'*******************************************************************************
'Send a Index byte and a command word
'*******************************************************************************
Sub Lcd_write_reg(byval Index As Byte , Daten As Word)
Call Lcd_write_index(index)
Call Lcd_write_data(daten)
End Sub
'*******************************************************************************
' Sends a Index byte to the display
'*******************************************************************************
Sub Lcd_write_index(byval Index As Byte)
Rs = 0 'Index
Lcdd = 0
Wr = 0
Wr = 1
Lcdd = Index
Wr = 0
Wr = 1
End Sub
'*******************************************************************************
'Sends a double byte command to the display
'*******************************************************************************
Sub Lcd_write_data(byval Daten As Word)
Temph = High(daten)
Templ = Low(daten)
Rs = 1 'data
Lcdd = Temph
Wr = 0
Wr = 1
Lcdd = Templ
Wr = 0
Wr = 1
Lcdd = 0 'Reset port
End Sub
'*******************************************************************************
'*******************************************************************************
'Clear LCD with color
'*******************************************************************************
Sub Lcd_clear(byval Color As Word)
Local Tem As Long
Call Set_cursor(0 , 0)
Call Lcd_write_index(&H22)
For Tem = 1 To 76799
Call Lcd_write_data(color)
Next
End Sub
'*******************************************************************************
'Set Cursor on X on Y
'*******************************************************************************
Sub Set_cursor(byval X As Word , Y As Word )
Local Xpos As Word
Local Ypos As Word
'Xpos = 240 - X
'Ypos = 320 - Y
Call Lcd_write_reg(&H20 , X)
Call Lcd_write_reg(&H21 , Y)
End Sub
'*******************************************************************************
'Set a Window
'*******************************************************************************
Sub Lcd_reset_window(byval X1 As Word , Byval X2 As Word , Byval Y1 As Word , Byval Y2 As Word)
Call Lcd_write_reg(&H50 , X1) 'Horizontal Address Start Position (0)
Call Lcd_write_reg(&H51 , X2) 'Horizontal Address end Position (239)
Call Lcd_write_reg(&H52 , Y1) 'Vertical Address Start Position
Call Lcd_write_reg(&H53 , Y2) 'Vertical Address end Position (319)
End Sub
'*******************************************************************************
' Set a pixel on X on Y color
'*******************************************************************************
Sub Lcd_set_pixel(byval X1 As Word , Y1 As Word , Color As Word)
Call Set_cursor(x1 , Y1)
Call Lcd_write_index(&H22)
Call Lcd_write_data(color)
End Sub
'*******************************************************************************
'Draw Horizonal line from x to x on y color
'*******************************************************************************
Sub Lcd_h_line(byval X1 As Word , X2 As Word , Y As Word , Col As Word)
Local L As Word
L = X2 - X1
Call Set_cursor(x1 , Y)
Call Lcd_fill(l , Col)
End Sub
'*******************************************************************************
'
'*******************************************************************************
'Draw a Vertical line from Y to Y on x color
'*******************************************************************************
Sub Lcd_v_line(byval Y1 As Word , Y2 As Word , X As Word , Col As Word)
Local Yla As Word , Za As Word
Yla = Y2 - Y1
For Za = Y1 To Y2
Call Set_cursor(x , Za)
Call Lcd_write_index(&H22)
Call Lcd_write_data(col)
Next
End Sub
'*******************************************************************************
'Draw a Box from X to X from Y to Y color
'*******************************************************************************
Sub Draw_box(byval X3 As Word , X4 As Word , Y4 As Word , Y5 As Word , Colo As Word)
Local La As Word , Ly As Word
La = X4 - X3 'länge der Line
For Ly = Y4 To Y5
Call Set_cursor(x3 , Ly)
Call Lcd_fill(la , Colo)
Next
End Sub
'*******************************************************************************
'Fülle LCD mit einer Farbe
'*******************************************************************************
Sub Lcd_fill(byval Lang As Word , Col As Word)
Local Z As Long
Call Lcd_write_index(&H22)
For Z = 1 To Lang
Call Lcd_write_data(col)
Next
End Sub
'*******************************************************************************
' By Evert Dekker 2009 GraphicFont@Evertdekker dotje com
' thanks to Evert Dekker
'*******************************************************************************
Sub Lcdtext(byval S As String , Xoffset As Word , Yoffset As Word , Fontset As Byte , Forecolor As Word , Backcolor As Word ) 'Print text on the display
Local Tempstring As String * 1 , Temp As Byte 'Dim local the variables
Local A As Word , Pixels As Byte , Count As Byte , Carcount As Byte , Lus As Byte
Local Row As Byte , Byteseach As Byte , Blocksize As Byte , Dummy As Byte
Local Colums As Byte , Columcount As Byte , Rowcount As Byte , Stringsize As Byte
Local Xpos As Word , Ypos As Word , Pixel As Word , Pixelcount As Byte
Stringsize = Len(s) - 1 'Size of the text string -1 because we must start with 0
For Carcount = 0 To Stringsize 'Loop for the numbers of caracters that must be displayed
If Fontset = 1 Then Restore Font8x8 'Add or remove here fontset's that you need or not,
If Fontset = 2 Then Restore Font16x16 'this is the name that you gave to the font, NOT the filename
' If Fontset = 3 Then Restore Font6x8 'If you dont know the name, open the font file in wordpad, and there it is,
' If Fontset = 4 Then Restore Font5x5 'right on top.
If Fontset = 5 Then Restore 12x16
Temp = Carcount + 1 'Cut the text string in seperate caracters
Tempstring = Mid(s , Temp , 1)
Read Row : Read Byteseach : Read Blocksize : Read Dummy 'Read the first 4 bytes from the font file
Temp = Asc(tempstring) - 32 'Font files start with caracter 32
For Lus = 1 To Temp 'Do dummie read to point to the correct line in the fontfile
For Count = 1 To Blocksize
Read Pixels
Next Count
Next Lus
Colums = Blocksize / Row 'Calculate the numbers of colums
Row = Row * 8 'Row is always 8 pixels high = 1 byte, so working with row in steps of 8.
Row = Row - 1 'Want to start with row=0 instead of 1
Colums = Colums - 1 'Same for the colums
For Rowcount = 0 To Row Step 8 'Loop for numbers of rows
A = Rowcount + Yoffset
For Columcount = 0 To Colums 'Loop for numbers of Colums
Read Pixels
Xpos = Columcount 'Do some calculation to get the caracter on the correct Xposition
Temp = Carcount * Byteseach
Xpos = Xpos + Temp
Xpos = Xpos + Xoffset
For Pixelcount = 0 To 7 'Loop for 8 pixels to be set or not
Ypos = A + Pixelcount 'Each pixel on his own spot
Pixel = Pixels.0 'Set the pixel (or not)
If Pixel = 1 Then
Pixel = Forecolor
Else
Pixel = Backcolor
End If
Lcd_set_pixel Xpos , Ypos , Pixel
' S65_pset Xpos , Ypos , Pixel 'Finaly we can set the pixel
Shift Pixels , Right 'Shift the byte 1 bit to the right so the next pixel comes availible
Next Pixelcount
Next Columcount
Next Rowcount
Next Carcount
End Sub 'End of this amazing subroutine
'*******************************************************************************
'End of Sub from Evert Dekker
'*******************************************************************************
'*******************************************************************************
'*******************************************************************************
'LCD Initialisierung
'*******************************************************************************
Sub Lcd_init()
Print "Sub lcd Init start"
'//************* Reset LCD Driver ****************//
Res = 1
Waitms 1 '// Delay 1ms
Res = 0
Waitms 10 '// Delay 10ms // This delay time is necessary
Res = 1
Waitms 50 '// Delay 50 ms
'//************* Start Initial Sequence **********//
'Call Lcd_write_reg(&He3 , &H3008) '// Set internal timing
'Call Lcd_write_reg(&He7 , &H0012) '// Set internal timing
'Call Lcd_write_reg(&Hef , &H1231) '// Set internal timing
Call Lcd_write_reg(&H01 , &H0100) '// set SS and SM bit
'Call Lcd_write_reg(&H02 , &H0700) '// set 1 line inversion
'TRI DFM 0 BGR 0 0 HWM 0 ORG 0 I/D1 I/D0 AM 0 0 0
Call Lcd_write_reg(&H03 , &H1030) '// set GRAM write direction and BGR=1.1028/1030 1 0 0 0 0 0 0 1 0 1 0 0 0
Call Lcd_write_reg(&H04 , &H0000) '// Resize register
'Call Lcd_write_reg(&H08 , &H0207) '// set the back porch and front porch
'Call Lcd_write_reg(&H09 , &H0000) '// set non-display area refresh cycle ISC[3:0]
Call Lcd_write_reg(&H0a , &H000D) 'geändert von 0000 27.11. // FMARK function
Call Lcd_write_reg(&H0d , &H0000) '// Frame marker Position
'//*************Power On sequence ****************//
Call Lcd_write_reg(&H10 , &H0000) '// SAP, BT[3:0], AP, DSTB, SLP, STB
Call Lcd_write_reg(&H11 , &H0007) '// DC1[2:0], DC0[2:0], VC[2:0]
Call Lcd_write_reg(&H12 , &H0000) '// VREG1OUT voltage
Call Lcd_write_reg(&H13 , &H0000) '// VDV[4:0] for VCOM amplitude
Waitms 200 '// Dis-charge capacitor power voltage
Call Lcd_write_reg(&H10 , &H1490) '// SAP, BT[3:0], AP, DSTB, SLP, STB
Call Lcd_write_reg(&H11 , &H0227) '// DC1[2:0], DC0[2:0], VC[2:0] 1000100111
Waitms 50 '// Delay 50ms
Call Lcd_write_reg(&H12 , &H001C) '// Internal reference voltage= Vci;
Waitms 50 '// Delay 50ms
Call Lcd_write_reg(&H13 , &H1A00) '// Set VDV[4:0] for VCOM amplitude
Call Lcd_write_reg(&H29 , &H0025) '// Set VCM[5:0] for VCOMH
Call Lcd_write_reg(&H2b , &H000E) '// Set Frame Rate /orig C / d ok
Waitms 50 ' // Delay 50ms
Call Lcd_write_reg(&H20 , &H0000) '// GRAM horizontal Address
Call Lcd_write_reg(&H21 , &H0000) '// GRAM Vertical Address
'// ----------- Adjust the Gamma Curve ----------//
Call Lcd_write_reg(&H30 , &H0007)
Call Lcd_write_reg(&H31 , &H0403)
Call Lcd_write_reg(&H32 , &H0404)
Call Lcd_write_reg(&H35 , &H0002)
Call Lcd_write_reg(&H36 , &H0707)
Call Lcd_write_reg(&H37 , &H0606)
Call Lcd_write_reg(&H38 , &H0106)
Call Lcd_write_reg(&H39 , &H0007)
Call Lcd_write_reg(&H3c , &H0700)
Call Lcd_write_reg(&H3d , &H0707)
Waitms 50
'//------------------ Set GRAM area ---------------//
Call Lcd_write_reg(&H50 , &H0000) '// Horizontal GRAM Start Address
Call Lcd_write_reg(&H51 , &H00EF) '// Horizontal GRAM End Address
Call Lcd_write_reg(&H52 , &H0000) '// Vertical GRAM Start Address
Call Lcd_write_reg(&H53 , &H013F) '// Vertical GRAM Start Address
Call Lcd_write_reg(&H60 , &HA700) '// Gate Scan Line 'Backlight an
Call Lcd_write_reg(&H61 , &H0001) '// NDL,VLE, REV
Call Lcd_write_reg(&H6a , &H0000) '// set scrolling line
'//-------------- Partial Display Control ---------//
Call Lcd_write_reg(&H80 , &H0000)
Call Lcd_write_reg(&H81 , &H0000)
Call Lcd_write_reg(&H82 , &H0000)
Call Lcd_write_reg(&H83 , &H0000)
Call Lcd_write_reg(&H84 , &H0000)
Call Lcd_write_reg(&H85 , &H0000)
'//-------------- Panel Control -------------------//
Call Lcd_write_reg(&H90 , &H0010) '00000000 00010000 vorher 10 , 21.12 auf 18 geändert
Call Lcd_write_reg(&H92 , &H0600)
Call Lcd_write_reg(&H07 , &H0001)
Waitms 50
Call Lcd_write_reg(&H07 , &H0133)
End Sub