Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Display TFT ST7789 (OshonSoft Basic).

DogFlu66

Member
I leave the library to use ST7789 TFT display, I have translated one that is in C language. But unfortunately I have not been able to get it to work yet. I leave the files in case someone with more experience with these displays can review it.
 

Attachments

  • Main_ST7789.bas
    1.5 KB · Views: 170
  • ST7789_240X240.bas
    15 KB · Views: 154
  • _SPI_Library.bas
    6 KB · Views: 163
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 153
  • _SetUpAmicus18.bas
    2.9 KB · Views: 143
Its in the INIT routine just above the INVON call..
Hi I,
I posted earlier that I had changed INVON to INVOFF to get the correct colours

Just above INVON is:
Call LCD_WRITE_COM(ILI9341_MADCTL)
Call LCD_WRITE_DATA(0x8)
Call LCD_WRITE_COM(ILI9341_INVOFF)'(ILI9341_INVON)

But I don't see any of the ILI9341_MADCTL_?? section used within the program itself, but there is ILI9341_MADCTL used within the program.

Also in #164 there is no ILI9341_MADCTL_MH.

Could you post your latset working program please.

P.S, An alarm has just gone off in the house, and I can smell electrical smoke. It maybe the central heating pump :(
C
 
Hi,
Re P.S on #202

I found the problem, it was the starting cap of the central heating pump. Luckily I had a spare, changed it and the heating is back on :)

Now where was I.
C
Capacitor.jpg
 
Hi,
Some of the colours were wrong so this is correct for my screen:
C
Code:
Const LCD_BLACK = 0x0000
Const LCD_RED = 0xf800 '0x001f
Const LCD_BLUE =  0x001f' 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0xffe0'0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0x07ff '0xffe0
Const LCD_WHITE = 0xffff
 
Is you screen still square?

here is my st7789V code.
Code:
'Fuses definition.

#define CONFIG1L = 0x00
#define CONFIG1H = 0x38
#define CONFIG2L = 0x1E
#define CONFIG2H = 0x3C
#define CONFIG3L = 0x00
#define CONFIG3H = 0x3D
#define CONFIG4L = 0x80
#define CONFIG4H = 0x00
#define CONFIG5L = 0x0F
#define CONFIG5H = 0xC0
#define CONFIG6L = 0x0F
#define CONFIG6H = 0xE0
#define CONFIG7L = 0x0F
#define CONFIG7H = 0x40

#define CLOCK_FREQUENCY = 32 'Clock 64Mhz
#define STRING_MAX_LENGTH = 60

'#define SIMULATION_WAITMS_VALUE = 1
'************************************************


'*****************************************************
'lcd driver

Const ST7789_NOP = 0x00
Const ST7789_SWRESET = 0x01
Const ST7789_RDDID = 0x04
Const ST7789_RDDST = 0x09

Const ST7789_SLPIN = 0x10
Const ST7789_SLPOUT = 0x11
Const ST7789_PTLON = 0x12
Const ST7789_NORON = 0x13

Const ST7789_INVOFF = 0x20
Const ST7789_INVON = 0x21
Const ST7789_DISPOFF = 0x28
Const ST7789_DISPON = 0x29
Const ST7789_CASET = 0x2a
Const ST7789_RASET = 0x2b
Const ST7789_RAMWR = 0x2c
Const ST7789_RAMRD = 0x2e

Const ST7789_PTLAR = 0x30
Const ST7789_COLMOD = 0x3a
Const ST7789_MADCTL = 0x36
Const ST7789_DISP_FUNC = 0xB6


Const ST7789_MADCTL_MY = 0x80
Const ST7789_MADCTL_MX = 0x40
Const ST7789_MADCTL_MV = 0x20
Const ST7789_MADCTL_ML = 0x10
Const ST7789_MADCTL_RGB = 0x00

Const ST7789_RDID1 = 0xda
Const ST7789_RDID2 = 0xdb
Const ST7789_RDID3 = 0xdc
Const ST7789_RDID4 = 0xdd


Const LCD_BLACK = 0x0000
Const LCD_RED = 0x001f
Const LCD_BLUE = 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0xffe0
Const LCD_WHITE = 0xffff

Dim LCD_width As Word  ///< Display width as modified by current rotation
Dim LCD_height As Word  ///< Display height as modified by current rotation

Dim LCD_rotation As Byte  ///< Display rotation (0 thru 3)

Symbol TFT_RST = LATC.0  'RST RESET pin
Symbol TFT_DC = LATC.1  'DC (SS) Data/Command pin
Symbol TFT_CS = LATC.2  'CS Chip Select pin
Symbol TFT_SCK = LATC.3  'SCK as output
Symbol TFT_SDI = LATC.4  'SDI as input -> SDO
Symbol TFT_SDO = LATC.5  'SDO as output -> SDI
'*************************************************
Dim str As String
Dim x As Byte
OSCCON = 0x60

OSCTUNE.PLLEN = 1
TRISA.1 = 0
TRISC = 0
ADCON1 = 15
Call SPI_init()
Call LCD_init()

str = "MAXIMUM!"
Main:

    x = 1
    While x = 1
    WaitMs 300
    LATA.1 = 1
    Call fillScreen(LCD_RED)

    WaitMs 300
    LATA.1 = 0
    Call fillwindow(10,10,310,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,310,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,310,230,LCD_BLACK)
    Call LCD_DrawLine(310,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,310,120,LCD_BLACK)
    Call LCD_DrawLine(160,10,160,230,LCD_BLACK)

    Call LCD_Circle(160,120,100,LCD_BLUE)
    Call fillwindow(100,50,220,190, LCD_WHITE)
    Call LCD_DrawRectangle(100,50,220,190,LCD_BLUE)
    Call LCD_String( str,90,110, LCD_BLACK, LCD_WHITE)

    WaitMs 2000

Wend
End

Proc SPI_init()

SSPSTAT = 0x40
SSPCON1 = 0x30


End Proc

Proc LCD_WRITE_COM(dat As Byte)
    TFT_CS = 0
    TFT_DC = 0
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_WRITE_DATA(dat As Byte)
    TFT_CS = 0
    TFT_DC = 1
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_init()

Dim idx As Byte
Dim cmd As Byte
    High TFT_RST
    'ConfigPin TFT_RST = Output
    WaitMs 100
    Low TFT_RST
    WaitMs 100
    High TFT_RST
    WaitMs 200

    Call LCD_WRITE_COM(ST7789_SWRESET)
    WaitMs 150
    Call LCD_WRITE_COM(ST7789_DISPOFF)
    Call LCD_WRITE_COM(0xCB)     //Power control a
    Call LCD_WRITE_DATA(0x39)
    Call LCD_WRITE_DATA(0x2C)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x34)
    Call LCD_WRITE_DATA(0x02)
    WaitMs 1
    Call LCD_WRITE_COM(0xCF)    //Power control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0XC1)
    Call LCD_WRITE_DATA(0X30)
    WaitMs 1
    Call LCD_WRITE_COM(0xE8)    //Timing control a
    Call LCD_WRITE_DATA(0x85)
    Call LCD_WRITE_DATA(0x10)
    Call LCD_WRITE_DATA(0x78)
    WaitMs 1
    Call LCD_WRITE_COM(0xEA)    //Timing control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x00)
    WaitMs 1
    Call LCD_WRITE_COM(0xED)    //Power on seq control
    Call LCD_WRITE_DATA(0x64)
    Call LCD_WRITE_DATA(0x03)
    Call LCD_WRITE_DATA(0X12)
    Call LCD_WRITE_DATA(0X81)

    //WaitMs 1
    Call LCD_WRITE_COM(0xC0)    //Power control 1
    Call LCD_WRITE_DATA(0x26)  //VRH[5:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC1)    //Power control 2
    Call LCD_WRITE_DATA(0x11)   //SAP[2:0];BT[3:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC5)    //VCM control
    Call LCD_WRITE_DATA(0x3e)   //Contrast
    Call LCD_WRITE_DATA(0x28)
   // WaitMs 1
    Call LCD_WRITE_COM(0xF7)
    Call LCD_WRITE_DATA(0x20)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_MADCTL)
    Call LCD_WRITE_DATA(0x8)
    Call LCD_WRITE_COM(ST7789_INVOFF)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_NORON)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_COLMOD )
    Call LCD_WRITE_DATA(0x55)
    //WaitMs 1
    Call LCD_WRITE_COM(0xB7) //emtry mode
    Call LCD_WRITE_DATA(0x07)
    Call LCD_WRITE_COM(ST7789_DISP_FUNC)    // Display Function Control
    Call LCD_WRITE_DATA(0x08)
    Call LCD_WRITE_DATA(0x82)
    Call LCD_WRITE_DATA(0x27)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_SLPOUT)
    WaitMs 120
    Call LCD_WRITE_COM(ST7789_DISPON)
    WaitMs 1

    LCD_height = 240
    LCD_width = 320

End Proc

'/**************************************************************************/
'@brief  SPI displays set an address window rectangle For blitting pixels
'@param  x  Top left corner x coordinate
'@param  y  Top left corner x coordinate
'@param  W  Width of window
'@param  h  Height of window
'/**************************************************************************/
Proc setAddrWindow(x1 As Word, y1 As Word, x2 As Word, y2 As Word)

Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
Call LCD_WRITE_DATA(x1.HB)
Call LCD_WRITE_DATA(x1.LB)
Call LCD_WRITE_DATA(x2.HB)
Call LCD_WRITE_DATA(x2.LB)
Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
Call LCD_WRITE_DATA(y1.HB)
Call LCD_WRITE_DATA(y1.LB)
Call LCD_WRITE_DATA(y2.HB)
Call LCD_WRITE_DATA(y2.LB)

Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM
End Proc
Proc LCD_DrawLine(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim t As Word
    Dim xerr, yerr, delta_x, delta_y, distance As Integer
    Dim incx, incy, xPix, yPix As Integer
    xerr = 0
    yerr = 0

    delta_x = x2 - x1
    delta_y = y2 - y1
    xPix = x1
    yPix = y1

    If delta_x > 0 Then    incx = 1
    If delta_x = 0 Then incx = 0
    If delta_x < 0 Then
        incx = -1
        delta_x = -delta_x
    Endif

    If delta_y > 0 Then    incy = 1
    If delta_y = 0 Then incy = 0
    If delta_y < 0 Then
        incy = -1
        delta_y = -delta_y
    Endif


    If delta_x > delta_y Then
        distance = delta_x
    Else
        distance = delta_y
    Endif

    For t = 0 To distance + 1 Step 1
         Call LCD_DrawPoint(xPix, yPix, color)
        xerr = xerr + delta_x
        yerr = yerr + delta_y
        If xerr > distance Then
            xerr = xerr - distance
            xPix = xPix + incx
        Endif
        If  yerr > distance Then
            yerr = yerr - distance
            yPix = yPix + incy
        Endif
    Next t
End Proc
Proc LCD_Char( char As Byte, x As Word, y As Word, fcol As Word , bcol As Word)

    Dim  x0 As Integer
    Dim idx, idx2 As Byte
    Dim mask As Byte

    For idx = 0 To 9 Step 1
        mask = _LCDFnt(char, idx)
        For idx2 = 0 To 13 Step 2
            If mask And 0x80 Then
                Call LCD_DrawPoint(x+idx2, y, fcol)
                Call LCD_DrawPoint(x+idx2+1, y, fcol)
                Call LCD_DrawPoint(x+idx2, y+1, fcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, fcol)
            Else
                Call LCD_DrawPoint(x+idx2, y, bcol)
                Call LCD_DrawPoint(x+idx2+1, y, bcol)
                Call LCD_DrawPoint(x+idx2, y+1, bcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, bcol)
            Endif
            mask = ShiftLeft(mask,1)
        Next idx2
        y = y + 2
    Next idx

End Proc
Proc LCD_String( str As String, x As Word, y As Word, fcol As Word , bcol As Word)

Dim idx As Byte
Dim x0 As Word
idx = 0

    While str(idx) <> 0
        Call LCD_Char(str(idx), x, y,fcol,bcol)
        x = x+18
        idx = idx + 1
    Wend

End Proc
// Rectangle

Proc LCD_DrawRectangle( x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Word)

    Call LCD_DrawLine(x1, y1, x2, y1, color)
    Call LCD_DrawLine(x1, y1, x1, y2, color)
    Call LCD_DrawLine(x1, y2, x2, y2, color)
    Call LCD_DrawLine(x2, y1, x2, y2, color)

End Proc
//   Circle routine

Proc LCD_Circle(x1 As Word, y1 As Word, rad As Word, color As Word)
Dim xPix, yPix, di As Integer
xPix = 0
yPix = rad
di = 3 - ShiftLeft(rad,1)
    While xPix <= yPix

    Call LCD_DrawPoint(x1+xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1+yPix, y1-xPix, color)
    Call LCD_DrawPoint(x1+yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1+xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1-xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1-xPix, color)
    xPix = xPix + 1

    If di < 0 Then
        di= (4 * xPix + 6) + di
    Else
        di= (10 + 4 * (xPix-yPix)) + di
        yPix = yPix - 1
    Endif
    Wend

End Proc
// line drawing

Proc LCD_DrawPoint(x1 As Word, y1 As Word ,color As Word)

    Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x1.HB)
    Call LCD_WRITE_DATA(x1.LB)
    Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y1.HB)
    Call LCD_WRITE_DATA(y1.LB)
    Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM

    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc

'/**************************************************************************/
Proc fillRect(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)
Dim px As Long
Dim tmp As Word
If x2 > 0 And y2 > 0 Then      //Nonzero width and height?

    Call setAddrWindow(x1, y1, x2, y2)

    px = x2
    px = px * y2
    TFT_CS = 0
    TFT_DC = 1
    While px > 1
        SSPBUF = color.HB
        While SSPSTAT.BF = 0
        Wend
        SSPBUF = color.LB
        While SSPSTAT.BF = 0
        Wend
        px = px - 1
    Wend
    TFT_DC = 1
    TFT_CS = 1
    Endif
End Proc

'/**************************************************************************/
'@brief    Fill the screen completely with one color. Update in subclasses If desired!
'@param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillScreen(color As Word)
Call fillRect(0, 0, LCD_width, LCD_height, color)
End Proc
Proc fillwindow(x1 As Word,y1 As Word,x2 As Word,y2 As Word,color As Word)
Call fillRect(x1, y1, x2, y2, color)
End Proc
Function _LCDFnt(ch As Byte, idx As Byte) As Byte
    Symbol Retval = _LCDFnt

            Select Case ch
                Case " "
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //SPACE
                Case "!"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //!
                Case 34
                    Retval = LookUp(0x00, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  // "
                Case "#"
                    Retval = LookUp(0x00, 0x12, 0x12, 0x7f, 0x24, 0x24, 0xfe, 0x48, 0x48, 0x00), idx  //#
                Case "$"
                    Retval = LookUp(0x00, 0x10, 0x7c, 0x92, 0x70, 0x1c, 0x92, 0x7c, 0x10, 0x00), idx  //$
                Case "%"
                    Retval = LookUp(0x00, 0x41, 0xa2, 0x44, 0x08, 0x10, 0x22, 0x45, 0x82, 0x00), idx  //%
                Case "&"
                    Retval = LookUp(0x00, 0x10, 0x28, 0x10, 0x28, 0x44, 0x43, 0x42, 0x39, 0x00), idx  //&
                Case "'"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //'
                Case "("
                    Retval = LookUp(0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00), idx  //(
                Case ")"
                    Retval = LookUp(0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x20, 0x04, 0x08, 0x00), idx  //)
                Case "*"
                    Retval = LookUp(0x00, 0x08, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x08, 0x00, 0x00), idx  //*
                Case "+"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x00, 0x00), idx  //+
                Case ","
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //,
                Case "-"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00), idx  //-
                Case "."
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00), idx  //.
                Case "/"
                    Retval = LookUp(0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00), idx  ///
                Case "0"
                    Retval = LookUp(0x00, 0x3c, 0x46, 0x4a, 0x4a, 0x52, 0x52, 0x62, 0x3c, 0x00), idx  //0
                Case "1"
                    Retval = LookUp(0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00), idx  //1
                Case "2"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x30, 0x40, 0x40, 0x7e, 0x00), idx  //2
                Case "3"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //3
                Case "4"
                    Retval = LookUp(0x00, 0x09, 0x18, 0x28, 0x48, 0x48, 0x7e, 0x08, 0x08, 0x00), idx  //4
                Case "5"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x7c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //5
                Case "6"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //6
                Case "7"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00), idx  //7
                Case "8"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //8
                Case "9"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //9
                Case ":"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00), idx  //:
                Case ";"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //;
                Case "<"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x10, 0x20, 0x20, 0x10, 0x08, 0x04, 0x00), idx  //<
                Case "="
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00), idx  //=
                Case ">"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x00), idx  //>
                Case "?"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //?
                Case "@"
                    Retval = LookUp(0x00, 0x7e, 0x81, 0x9b, 0xa5, 0xa6, 0x9c, 0x81, 0x7e, 0x00), idx  //@
                Case "A"
                    Retval = LookUp(0x00, 0x18, 0x24, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00), idx  //A
                Case "B"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //B
                Case "C"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00), idx  //C
                Case "D"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //D
                Case "E"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //E
                Case "F"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //F
                Case "G"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x46, 0x42, 0x42, 0x3c, 0x00), idx  //G
                Case "H"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //H
                Case "I"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7e, 0x00), idx  //I
                Case "J"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x30, 0x00), idx  //J
                Case "K"
                    Retval = LookUp(0x00, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //K
                Case "L"
                    Retval = LookUp(0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //L
                Case "M"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //M
                Case "N"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0x42, 0x00), idx  //N
                Case "O"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //O
                Case "P"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //P
                Case "Q"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x46, 0x3e, 0x00), idx  //Q
                Case "R"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //R
                Case "S"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x3c, 0x00), idx  //S
                Case "T"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //T
                Case "U"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //U
                Case "V"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00), idx  //V
                Case "W"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0x00), idx  //W
                Case "X"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00), idx  //X
                Case "Y"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x05, 0x08, 0x08, 0x08, 0x00), idx  //Y
                Case "Z"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7e, 0x00), idx  //Z
                Case "["
                    Retval = LookUp(0x00, 0x3c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x00), idx  //[
                Case "\"
                    Retval = LookUp(0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00), idx  //\
                Case "]"
                    Retval = LookUp(0x00, 0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, 0x00), idx  //]
                Case "^"
                    Retval = LookUp(0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //^
                Case "_"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00), idx  //_
                Case "`"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //`
                Case "a"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x02, 0x1e, 0x22, 0x22, 0x1e, 0x00), idx  //a
                Case "b"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x00), idx  //b
                Case "c"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x20, 0x20, 0x22, 0x1c, 0x00), idx  //c
                Case "d"
                    Retval = LookUp(0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x00), idx  //d
                Case "e"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x20, 0x22, 0x1c, 0x00), idx  //e
                Case "f"
                    Retval = LookUp(0x00, 0x0c, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x10, 0x10, 0x00), idx  //f
                Case "g"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //g
                Case "h"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //h
                Case "i"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //i
                Case "j"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30), idx  //j
                Case "k"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x22, 0x24, 0x38, 0x24, 0x22, 0x22, 0x00), idx  //k
                Case "l"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x00), idx  //l
                Case "m"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x36, 0x2a, 0x22, 0x22, 0x22, 0x00), idx  //m
                Case "n"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //n
                Case "o"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //o
                Case "p"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00), idx  //p
                Case "q"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20), idx  //q
                Case "r"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x2e, 0x30, 0x20, 0x20, 0x20, 0x20, 0x00), idx  //r
                Case "s"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x10, 0x0c, 0x22, 0x1c, 0x00), idx  //s
                Case "t"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x38, 0x10, 0x10, 0x10, 0x12, 0x0c, 0x00), idx  //t
                Case "u"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //u
                Case "v"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x14, 0x08, 0x00), idx  //v
                Case "w"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x36, 0x22, 0x00), idx  //w
                Case "x"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00), idx  //x
                Case "y"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //y
                Case "z"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3e, 0x02, 0x04, 0x08, 0x10, 0x3e, 0x00), idx  //z
                Case "{"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x08, 0x08, 0x10, 0x08, 0x08, 0x08, 0x04), idx  //{
                Case "|"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //|
                Case "}"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x08, 0x08, 0x04, 0x08, 0x08, 0x08, 0x10), idx  //}
                Case "~"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0xcc, 0x33, 0x00, 0x00, 0x00, 0x00), idx  //~
                Case 165 '"Ñ" + chr(165) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7e, 0x05, 0x09, 0x11, 0x7e), idx  //Ñ
                Case 164'"ñ" + chr(164) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x78, 0x12, 0x0a, 0x0a, 0x70), idx  //ñ
            EndSelect

End Function
 
Is you screen still square?

here is my st7789V code.
Code:
'Fuses definition.

#define CONFIG1L = 0x00
#define CONFIG1H = 0x38
#define CONFIG2L = 0x1E
#define CONFIG2H = 0x3C
#define CONFIG3L = 0x00
#define CONFIG3H = 0x3D
#define CONFIG4L = 0x80
#define CONFIG4H = 0x00
#define CONFIG5L = 0x0F
#define CONFIG5H = 0xC0
#define CONFIG6L = 0x0F
#define CONFIG6H = 0xE0
#define CONFIG7L = 0x0F
#define CONFIG7H = 0x40

#define CLOCK_FREQUENCY = 32 'Clock 64Mhz
#define STRING_MAX_LENGTH = 60

'#define SIMULATION_WAITMS_VALUE = 1
'************************************************


'*****************************************************
'lcd driver

Const ST7789_NOP = 0x00
Const ST7789_SWRESET = 0x01
Const ST7789_RDDID = 0x04
Const ST7789_RDDST = 0x09

Const ST7789_SLPIN = 0x10
Const ST7789_SLPOUT = 0x11
Const ST7789_PTLON = 0x12
Const ST7789_NORON = 0x13

Const ST7789_INVOFF = 0x20
Const ST7789_INVON = 0x21
Const ST7789_DISPOFF = 0x28
Const ST7789_DISPON = 0x29
Const ST7789_CASET = 0x2a
Const ST7789_RASET = 0x2b
Const ST7789_RAMWR = 0x2c
Const ST7789_RAMRD = 0x2e

Const ST7789_PTLAR = 0x30
Const ST7789_COLMOD = 0x3a
Const ST7789_MADCTL = 0x36
Const ST7789_DISP_FUNC = 0xB6


Const ST7789_MADCTL_MY = 0x80
Const ST7789_MADCTL_MX = 0x40
Const ST7789_MADCTL_MV = 0x20
Const ST7789_MADCTL_ML = 0x10
Const ST7789_MADCTL_RGB = 0x00

Const ST7789_RDID1 = 0xda
Const ST7789_RDID2 = 0xdb
Const ST7789_RDID3 = 0xdc
Const ST7789_RDID4 = 0xdd


Const LCD_BLACK = 0x0000
Const LCD_RED = 0x001f
Const LCD_BLUE = 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0xffe0
Const LCD_WHITE = 0xffff

Dim LCD_width As Word  ///< Display width as modified by current rotation
Dim LCD_height As Word  ///< Display height as modified by current rotation

Dim LCD_rotation As Byte  ///< Display rotation (0 thru 3)

Symbol TFT_RST = LATC.0  'RST RESET pin
Symbol TFT_DC = LATC.1  'DC (SS) Data/Command pin
Symbol TFT_CS = LATC.2  'CS Chip Select pin
Symbol TFT_SCK = LATC.3  'SCK as output
Symbol TFT_SDI = LATC.4  'SDI as input -> SDO
Symbol TFT_SDO = LATC.5  'SDO as output -> SDI
'*************************************************
Dim str As String
Dim x As Byte
OSCCON = 0x60

OSCTUNE.PLLEN = 1
TRISA.1 = 0
TRISC = 0
ADCON1 = 15
Call SPI_init()
Call LCD_init()

str = "MAXIMUM!"
Main:

    x = 1
    While x = 1
    WaitMs 300
    LATA.1 = 1
    Call fillScreen(LCD_RED)

    WaitMs 300
    LATA.1 = 0
    Call fillwindow(10,10,310,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,310,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,310,230,LCD_BLACK)
    Call LCD_DrawLine(310,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,310,120,LCD_BLACK)
    Call LCD_DrawLine(160,10,160,230,LCD_BLACK)

    Call LCD_Circle(160,120,100,LCD_BLUE)
    Call fillwindow(100,50,220,190, LCD_WHITE)
    Call LCD_DrawRectangle(100,50,220,190,LCD_BLUE)
    Call LCD_String( str,90,110, LCD_BLACK, LCD_WHITE)

    WaitMs 2000

Wend
End

Proc SPI_init()

SSPSTAT = 0x40
SSPCON1 = 0x30


End Proc

Proc LCD_WRITE_COM(dat As Byte)
    TFT_CS = 0
    TFT_DC = 0
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_WRITE_DATA(dat As Byte)
    TFT_CS = 0
    TFT_DC = 1
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_init()

Dim idx As Byte
Dim cmd As Byte
    High TFT_RST
    'ConfigPin TFT_RST = Output
    WaitMs 100
    Low TFT_RST
    WaitMs 100
    High TFT_RST
    WaitMs 200

    Call LCD_WRITE_COM(ST7789_SWRESET)
    WaitMs 150
    Call LCD_WRITE_COM(ST7789_DISPOFF)
    Call LCD_WRITE_COM(0xCB)     //Power control a
    Call LCD_WRITE_DATA(0x39)
    Call LCD_WRITE_DATA(0x2C)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x34)
    Call LCD_WRITE_DATA(0x02)
    WaitMs 1
    Call LCD_WRITE_COM(0xCF)    //Power control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0XC1)
    Call LCD_WRITE_DATA(0X30)
    WaitMs 1
    Call LCD_WRITE_COM(0xE8)    //Timing control a
    Call LCD_WRITE_DATA(0x85)
    Call LCD_WRITE_DATA(0x10)
    Call LCD_WRITE_DATA(0x78)
    WaitMs 1
    Call LCD_WRITE_COM(0xEA)    //Timing control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x00)
    WaitMs 1
    Call LCD_WRITE_COM(0xED)    //Power on seq control
    Call LCD_WRITE_DATA(0x64)
    Call LCD_WRITE_DATA(0x03)
    Call LCD_WRITE_DATA(0X12)
    Call LCD_WRITE_DATA(0X81)

    //WaitMs 1
    Call LCD_WRITE_COM(0xC0)    //Power control 1
    Call LCD_WRITE_DATA(0x26)  //VRH[5:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC1)    //Power control 2
    Call LCD_WRITE_DATA(0x11)   //SAP[2:0];BT[3:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC5)    //VCM control
    Call LCD_WRITE_DATA(0x3e)   //Contrast
    Call LCD_WRITE_DATA(0x28)
   // WaitMs 1
    Call LCD_WRITE_COM(0xF7)
    Call LCD_WRITE_DATA(0x20)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_MADCTL)
    Call LCD_WRITE_DATA(0x8)
    Call LCD_WRITE_COM(ST7789_INVOFF)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_NORON)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_COLMOD )
    Call LCD_WRITE_DATA(0x55)
    //WaitMs 1
    Call LCD_WRITE_COM(0xB7) //emtry mode
    Call LCD_WRITE_DATA(0x07)
    Call LCD_WRITE_COM(ST7789_DISP_FUNC)    // Display Function Control
    Call LCD_WRITE_DATA(0x08)
    Call LCD_WRITE_DATA(0x82)
    Call LCD_WRITE_DATA(0x27)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_SLPOUT)
    WaitMs 120
    Call LCD_WRITE_COM(ST7789_DISPON)
    WaitMs 1

    LCD_height = 240
    LCD_width = 320

End Proc

'/**************************************************************************/
'@brief  SPI displays set an address window rectangle For blitting pixels
'@param  x  Top left corner x coordinate
'@param  y  Top left corner x coordinate
'@param  W  Width of window
'@param  h  Height of window
'/**************************************************************************/
Proc setAddrWindow(x1 As Word, y1 As Word, x2 As Word, y2 As Word)

Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
Call LCD_WRITE_DATA(x1.HB)
Call LCD_WRITE_DATA(x1.LB)
Call LCD_WRITE_DATA(x2.HB)
Call LCD_WRITE_DATA(x2.LB)
Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
Call LCD_WRITE_DATA(y1.HB)
Call LCD_WRITE_DATA(y1.LB)
Call LCD_WRITE_DATA(y2.HB)
Call LCD_WRITE_DATA(y2.LB)

Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM
End Proc
Proc LCD_DrawLine(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim t As Word
    Dim xerr, yerr, delta_x, delta_y, distance As Integer
    Dim incx, incy, xPix, yPix As Integer
    xerr = 0
    yerr = 0

    delta_x = x2 - x1
    delta_y = y2 - y1
    xPix = x1
    yPix = y1

    If delta_x > 0 Then    incx = 1
    If delta_x = 0 Then incx = 0
    If delta_x < 0 Then
        incx = -1
        delta_x = -delta_x
    Endif

    If delta_y > 0 Then    incy = 1
    If delta_y = 0 Then incy = 0
    If delta_y < 0 Then
        incy = -1
        delta_y = -delta_y
    Endif


    If delta_x > delta_y Then
        distance = delta_x
    Else
        distance = delta_y
    Endif

    For t = 0 To distance + 1 Step 1
         Call LCD_DrawPoint(xPix, yPix, color)
        xerr = xerr + delta_x
        yerr = yerr + delta_y
        If xerr > distance Then
            xerr = xerr - distance
            xPix = xPix + incx
        Endif
        If  yerr > distance Then
            yerr = yerr - distance
            yPix = yPix + incy
        Endif
    Next t
End Proc
Proc LCD_Char( char As Byte, x As Word, y As Word, fcol As Word , bcol As Word)

    Dim  x0 As Integer
    Dim idx, idx2 As Byte
    Dim mask As Byte

    For idx = 0 To 9 Step 1
        mask = _LCDFnt(char, idx)
        For idx2 = 0 To 13 Step 2
            If mask And 0x80 Then
                Call LCD_DrawPoint(x+idx2, y, fcol)
                Call LCD_DrawPoint(x+idx2+1, y, fcol)
                Call LCD_DrawPoint(x+idx2, y+1, fcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, fcol)
            Else
                Call LCD_DrawPoint(x+idx2, y, bcol)
                Call LCD_DrawPoint(x+idx2+1, y, bcol)
                Call LCD_DrawPoint(x+idx2, y+1, bcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, bcol)
            Endif
            mask = ShiftLeft(mask,1)
        Next idx2
        y = y + 2
    Next idx

End Proc
Proc LCD_String( str As String, x As Word, y As Word, fcol As Word , bcol As Word)

Dim idx As Byte
Dim x0 As Word
idx = 0

    While str(idx) <> 0
        Call LCD_Char(str(idx), x, y,fcol,bcol)
        x = x+18
        idx = idx + 1
    Wend

End Proc
// Rectangle

Proc LCD_DrawRectangle( x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Word)

    Call LCD_DrawLine(x1, y1, x2, y1, color)
    Call LCD_DrawLine(x1, y1, x1, y2, color)
    Call LCD_DrawLine(x1, y2, x2, y2, color)
    Call LCD_DrawLine(x2, y1, x2, y2, color)

End Proc
//   Circle routine

Proc LCD_Circle(x1 As Word, y1 As Word, rad As Word, color As Word)
Dim xPix, yPix, di As Integer
xPix = 0
yPix = rad
di = 3 - ShiftLeft(rad,1)
    While xPix <= yPix

    Call LCD_DrawPoint(x1+xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1+yPix, y1-xPix, color)
    Call LCD_DrawPoint(x1+yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1+xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1-xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1-xPix, color)
    xPix = xPix + 1

    If di < 0 Then
        di= (4 * xPix + 6) + di
    Else
        di= (10 + 4 * (xPix-yPix)) + di
        yPix = yPix - 1
    Endif
    Wend

End Proc
// line drawing

Proc LCD_DrawPoint(x1 As Word, y1 As Word ,color As Word)

    Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x1.HB)
    Call LCD_WRITE_DATA(x1.LB)
    Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y1.HB)
    Call LCD_WRITE_DATA(y1.LB)
    Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM

    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc

'/**************************************************************************/
Proc fillRect(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)
Dim px As Long
Dim tmp As Word
If x2 > 0 And y2 > 0 Then      //Nonzero width and height?

    Call setAddrWindow(x1, y1, x2, y2)

    px = x2
    px = px * y2
    TFT_CS = 0
    TFT_DC = 1
    While px > 1
        SSPBUF = color.HB
        While SSPSTAT.BF = 0
        Wend
        SSPBUF = color.LB
        While SSPSTAT.BF = 0
        Wend
        px = px - 1
    Wend
    TFT_DC = 1
    TFT_CS = 1
    Endif
End Proc

'/**************************************************************************/
'@brief    Fill the screen completely with one color. Update in subclasses If desired!
'@param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillScreen(color As Word)
Call fillRect(0, 0, LCD_width, LCD_height, color)
End Proc
Proc fillwindow(x1 As Word,y1 As Word,x2 As Word,y2 As Word,color As Word)
Call fillRect(x1, y1, x2, y2, color)
End Proc
Function _LCDFnt(ch As Byte, idx As Byte) As Byte
    Symbol Retval = _LCDFnt

            Select Case ch
                Case " "
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //SPACE
                Case "!"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //!
                Case 34
                    Retval = LookUp(0x00, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  // "
                Case "#"
                    Retval = LookUp(0x00, 0x12, 0x12, 0x7f, 0x24, 0x24, 0xfe, 0x48, 0x48, 0x00), idx  //#
                Case "$"
                    Retval = LookUp(0x00, 0x10, 0x7c, 0x92, 0x70, 0x1c, 0x92, 0x7c, 0x10, 0x00), idx  //$
                Case "%"
                    Retval = LookUp(0x00, 0x41, 0xa2, 0x44, 0x08, 0x10, 0x22, 0x45, 0x82, 0x00), idx  //%
                Case "&"
                    Retval = LookUp(0x00, 0x10, 0x28, 0x10, 0x28, 0x44, 0x43, 0x42, 0x39, 0x00), idx  //&
                Case "'"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //'
                Case "("
                    Retval = LookUp(0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00), idx  //(
                Case ")"
                    Retval = LookUp(0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x20, 0x04, 0x08, 0x00), idx  //)
                Case "*"
                    Retval = LookUp(0x00, 0x08, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x08, 0x00, 0x00), idx  //*
                Case "+"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x00, 0x00), idx  //+
                Case ","
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //,
                Case "-"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00), idx  //-
                Case "."
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00), idx  //.
                Case "/"
                    Retval = LookUp(0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00), idx  ///
                Case "0"
                    Retval = LookUp(0x00, 0x3c, 0x46, 0x4a, 0x4a, 0x52, 0x52, 0x62, 0x3c, 0x00), idx  //0
                Case "1"
                    Retval = LookUp(0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00), idx  //1
                Case "2"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x30, 0x40, 0x40, 0x7e, 0x00), idx  //2
                Case "3"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //3
                Case "4"
                    Retval = LookUp(0x00, 0x09, 0x18, 0x28, 0x48, 0x48, 0x7e, 0x08, 0x08, 0x00), idx  //4
                Case "5"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x7c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //5
                Case "6"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //6
                Case "7"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00), idx  //7
                Case "8"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //8
                Case "9"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //9
                Case ":"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00), idx  //:
                Case ";"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //;
                Case "<"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x10, 0x20, 0x20, 0x10, 0x08, 0x04, 0x00), idx  //<
                Case "="
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00), idx  //=
                Case ">"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x00), idx  //>
                Case "?"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //?
                Case "@"
                    Retval = LookUp(0x00, 0x7e, 0x81, 0x9b, 0xa5, 0xa6, 0x9c, 0x81, 0x7e, 0x00), idx  //@
                Case "A"
                    Retval = LookUp(0x00, 0x18, 0x24, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00), idx  //A
                Case "B"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //B
                Case "C"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00), idx  //C
                Case "D"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //D
                Case "E"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //E
                Case "F"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //F
                Case "G"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x46, 0x42, 0x42, 0x3c, 0x00), idx  //G
                Case "H"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //H
                Case "I"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7e, 0x00), idx  //I
                Case "J"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x30, 0x00), idx  //J
                Case "K"
                    Retval = LookUp(0x00, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //K
                Case "L"
                    Retval = LookUp(0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //L
                Case "M"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //M
                Case "N"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0x42, 0x00), idx  //N
                Case "O"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //O
                Case "P"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //P
                Case "Q"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x46, 0x3e, 0x00), idx  //Q
                Case "R"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //R
                Case "S"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x3c, 0x00), idx  //S
                Case "T"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //T
                Case "U"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //U
                Case "V"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00), idx  //V
                Case "W"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0x00), idx  //W
                Case "X"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00), idx  //X
                Case "Y"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x05, 0x08, 0x08, 0x08, 0x00), idx  //Y
                Case "Z"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7e, 0x00), idx  //Z
                Case "["
                    Retval = LookUp(0x00, 0x3c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x00), idx  //[
                Case "\"
                    Retval = LookUp(0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00), idx  //\
                Case "]"
                    Retval = LookUp(0x00, 0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, 0x00), idx  //]
                Case "^"
                    Retval = LookUp(0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //^
                Case "_"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00), idx  //_
                Case "`"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //`
                Case "a"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x02, 0x1e, 0x22, 0x22, 0x1e, 0x00), idx  //a
                Case "b"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x00), idx  //b
                Case "c"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x20, 0x20, 0x22, 0x1c, 0x00), idx  //c
                Case "d"
                    Retval = LookUp(0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x00), idx  //d
                Case "e"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x20, 0x22, 0x1c, 0x00), idx  //e
                Case "f"
                    Retval = LookUp(0x00, 0x0c, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x10, 0x10, 0x00), idx  //f
                Case "g"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //g
                Case "h"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //h
                Case "i"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //i
                Case "j"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30), idx  //j
                Case "k"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x22, 0x24, 0x38, 0x24, 0x22, 0x22, 0x00), idx  //k
                Case "l"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x00), idx  //l
                Case "m"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x36, 0x2a, 0x22, 0x22, 0x22, 0x00), idx  //m
                Case "n"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //n
                Case "o"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //o
                Case "p"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00), idx  //p
                Case "q"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20), idx  //q
                Case "r"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x2e, 0x30, 0x20, 0x20, 0x20, 0x20, 0x00), idx  //r
                Case "s"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x10, 0x0c, 0x22, 0x1c, 0x00), idx  //s
                Case "t"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x38, 0x10, 0x10, 0x10, 0x12, 0x0c, 0x00), idx  //t
                Case "u"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //u
                Case "v"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x14, 0x08, 0x00), idx  //v
                Case "w"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x36, 0x22, 0x00), idx  //w
                Case "x"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00), idx  //x
                Case "y"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //y
                Case "z"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3e, 0x02, 0x04, 0x08, 0x10, 0x3e, 0x00), idx  //z
                Case "{"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x08, 0x08, 0x10, 0x08, 0x08, 0x08, 0x04), idx  //{
                Case "|"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //|
                Case "}"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x08, 0x08, 0x04, 0x08, 0x08, 0x08, 0x10), idx  //}
                Case "~"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0xcc, 0x33, 0x00, 0x00, 0x00, 0x00), idx  //~
                Case 165 '"Ñ" + chr(165) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7e, 0x05, 0x09, 0x11, 0x7e), idx  //Ñ
                Case 164'"ñ" + chr(164) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x78, 0x12, 0x0a, 0x0a, 0x70), idx  //ñ
            EndSelect

End Function
Hi I,
My screen is 240X320

Your CODE jams at: Call LCD_WRITE_COM(ILI9341_SWRESET)
Can you post your DIMS also please?
C
 
TFT GMT020-02 (ST7789):

To operate the SPI at 16 MHz SCL, I need to set it to Mode 2.
_SPI1_Init(_SPI_MODE2, _SPI_MASTER_SPEED0 | _SPI_ENABLE) 'SCL 16Mhz (64Mhz).

On my LCD, I must keep the command LCD_WRITE_COM(ST7789_INVON) active to ensure the colors display correctly.

However on the GMT320 (ST7789) it has to be: LCD_WRITE_COM(ST7789_INVOFF).

Everything seems to work fine in full screen. :)
 
Last edited:
The MADCTRL is only different on the ILI9341 The rotaion is not right out of the box..

I have set the rotation using the MV only ( horiz / vert ) swap and it works as expected.

This is bit 6.. However! I have to set the RGB as I couldn't be bothered working out the colours..

RRRR|RGGG|GGGB|BBBB is 565 format BBBB|BGGG|GGGR|RRRR is how I have it..
 
The MADCTRL is only different on the ILI9341 The rotaion is not right out of the box..

I have set the rotation using the MV only ( horiz / vert ) swap and it works as expected.

This is bit 6.. However! I have to set the RGB as I couldn't be bothered working out the colours..

RRRR|RGGG|GGGB|BBBB is 565 format BBBB|BGGG|GGGR|RRRR is how I have it..
Hi I and D,
How are you actually changing these settings?
Can you give me an example of before and after? please?
I keep changing settings and nothing is happening, apart from
[ Call LCD_WRITE_COM(ILI9341_INVOFF)'(ILI9341_INVON) ]
which did reverse the colours.
C
 
Code:
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_MADCTL)
    Call LCD_WRITE_DATA(0x8)

    Call LCD_WRITE_COM(ST7789_INVOFF)

Look at the code above.. It only need doing once ( Until I do a complete rotation)

The way the system works is:- You issue the command write to the MADCTRL then the LCD waits for the data.. The second write is data. the third write is the command to swap inversion.

The LCD_WRITE_DATA above is the data for that command.
____________________________________________
| MY | MX | MV | ML | BGR | MH | XX | XX | << 1 byte DATA for MADCTRL

You see above that I have bit 4 switched on which swaps RGB to BGR

If you set bit 6 MV it swaps from Horizontal to vertical and back..

My ST7789V is working fine with the code I sent in #208
 
Code:
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_MADCTL)
    Call LCD_WRITE_DATA(0x8)

    Call LCD_WRITE_COM(ST7789_INVOFF)

Look at the code above.. It only need doing once ( Until I do a complete rotation)

The way the system works is:- You issue the command write to the MADCTRL then the LCD waits for the data.. The second write is data. the third write is the command to swap inversion.

The LCD_WRITE_DATA above is the data for that command.
____________________________________________
| MY | MX | MV | ML | BGR | MH | XX | XX | << 1 byte DATA for MADCTRL

You see above that I have bit 4 switched on which swaps RGB to BGR

If you set bit 6 MV it swaps from Horizontal to vertical and back..

My ST7789V is working fine with the code I sent in #208
Hi I,
Thanks.
If I change Call LCD_WRITE_COM(ST7789_INVOFF) to ON, it changes, but if I change Call LCD_WRITE_DATA(0x8) to a varety of settings, nothing changes?
C
 
Is you screen still square?

here is my st7789V code.
Code:
'Fuses definition.

#define CONFIG1L = 0x00
#define CONFIG1H = 0x38
#define CONFIG2L = 0x1E
#define CONFIG2H = 0x3C
#define CONFIG3L = 0x00
#define CONFIG3H = 0x3D
#define CONFIG4L = 0x80
#define CONFIG4H = 0x00
#define CONFIG5L = 0x0F
#define CONFIG5H = 0xC0
#define CONFIG6L = 0x0F
#define CONFIG6H = 0xE0
#define CONFIG7L = 0x0F
#define CONFIG7H = 0x40

#define CLOCK_FREQUENCY = 32 'Clock 64Mhz
#define STRING_MAX_LENGTH = 60

'#define SIMULATION_WAITMS_VALUE = 1
'************************************************


'*****************************************************
'lcd driver

Const ST7789_NOP = 0x00
Const ST7789_SWRESET = 0x01
Const ST7789_RDDID = 0x04
Const ST7789_RDDST = 0x09

Const ST7789_SLPIN = 0x10
Const ST7789_SLPOUT = 0x11
Const ST7789_PTLON = 0x12
Const ST7789_NORON = 0x13

Const ST7789_INVOFF = 0x20
Const ST7789_INVON = 0x21
Const ST7789_DISPOFF = 0x28
Const ST7789_DISPON = 0x29
Const ST7789_CASET = 0x2a
Const ST7789_RASET = 0x2b
Const ST7789_RAMWR = 0x2c
Const ST7789_RAMRD = 0x2e

Const ST7789_PTLAR = 0x30
Const ST7789_COLMOD = 0x3a
Const ST7789_MADCTL = 0x36
Const ST7789_DISP_FUNC = 0xB6


Const ST7789_MADCTL_MY = 0x80
Const ST7789_MADCTL_MX = 0x40
Const ST7789_MADCTL_MV = 0x20
Const ST7789_MADCTL_ML = 0x10
Const ST7789_MADCTL_RGB = 0x00

Const ST7789_RDID1 = 0xda
Const ST7789_RDID2 = 0xdb
Const ST7789_RDID3 = 0xdc
Const ST7789_RDID4 = 0xdd


Const LCD_BLACK = 0x0000
Const LCD_RED = 0x001f
Const LCD_BLUE = 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0xffe0
Const LCD_WHITE = 0xffff

Dim LCD_width As Word  ///< Display width as modified by current rotation
Dim LCD_height As Word  ///< Display height as modified by current rotation

Dim LCD_rotation As Byte  ///< Display rotation (0 thru 3)

Symbol TFT_RST = LATC.0  'RST RESET pin
Symbol TFT_DC = LATC.1  'DC (SS) Data/Command pin
Symbol TFT_CS = LATC.2  'CS Chip Select pin
Symbol TFT_SCK = LATC.3  'SCK as output
Symbol TFT_SDI = LATC.4  'SDI as input -> SDO
Symbol TFT_SDO = LATC.5  'SDO as output -> SDI
'*************************************************
Dim str As String
Dim x As Byte
OSCCON = 0x60

OSCTUNE.PLLEN = 1
TRISA.1 = 0
TRISC = 0
ADCON1 = 15
Call SPI_init()
Call LCD_init()

str = "MAXIMUM!"
Main:

    x = 1
    While x = 1
    WaitMs 300
    LATA.1 = 1
    Call fillScreen(LCD_RED)

    WaitMs 300
    LATA.1 = 0
    Call fillwindow(10,10,310,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,310,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,310,230,LCD_BLACK)
    Call LCD_DrawLine(310,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,310,120,LCD_BLACK)
    Call LCD_DrawLine(160,10,160,230,LCD_BLACK)

    Call LCD_Circle(160,120,100,LCD_BLUE)
    Call fillwindow(100,50,220,190, LCD_WHITE)
    Call LCD_DrawRectangle(100,50,220,190,LCD_BLUE)
    Call LCD_String( str,90,110, LCD_BLACK, LCD_WHITE)

    WaitMs 2000

Wend
End

Proc SPI_init()

SSPSTAT = 0x40
SSPCON1 = 0x30


End Proc

Proc LCD_WRITE_COM(dat As Byte)
    TFT_CS = 0
    TFT_DC = 0
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_WRITE_DATA(dat As Byte)
    TFT_CS = 0
    TFT_DC = 1
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_init()

Dim idx As Byte
Dim cmd As Byte
    High TFT_RST
    'ConfigPin TFT_RST = Output
    WaitMs 100
    Low TFT_RST
    WaitMs 100
    High TFT_RST
    WaitMs 200

    Call LCD_WRITE_COM(ST7789_SWRESET)
    WaitMs 150
    Call LCD_WRITE_COM(ST7789_DISPOFF)
    Call LCD_WRITE_COM(0xCB)     //Power control a
    Call LCD_WRITE_DATA(0x39)
    Call LCD_WRITE_DATA(0x2C)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x34)
    Call LCD_WRITE_DATA(0x02)
    WaitMs 1
    Call LCD_WRITE_COM(0xCF)    //Power control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0XC1)
    Call LCD_WRITE_DATA(0X30)
    WaitMs 1
    Call LCD_WRITE_COM(0xE8)    //Timing control a
    Call LCD_WRITE_DATA(0x85)
    Call LCD_WRITE_DATA(0x10)
    Call LCD_WRITE_DATA(0x78)
    WaitMs 1
    Call LCD_WRITE_COM(0xEA)    //Timing control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x00)
    WaitMs 1
    Call LCD_WRITE_COM(0xED)    //Power on seq control
    Call LCD_WRITE_DATA(0x64)
    Call LCD_WRITE_DATA(0x03)
    Call LCD_WRITE_DATA(0X12)
    Call LCD_WRITE_DATA(0X81)

    //WaitMs 1
    Call LCD_WRITE_COM(0xC0)    //Power control 1
    Call LCD_WRITE_DATA(0x26)  //VRH[5:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC1)    //Power control 2
    Call LCD_WRITE_DATA(0x11)   //SAP[2:0];BT[3:0]
    //WaitMs 1
    Call LCD_WRITE_COM(0xC5)    //VCM control
    Call LCD_WRITE_DATA(0x3e)   //Contrast
    Call LCD_WRITE_DATA(0x28)
   // WaitMs 1
    Call LCD_WRITE_COM(0xF7)
    Call LCD_WRITE_DATA(0x20)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_MADCTL)
    Call LCD_WRITE_DATA(0x8)
    Call LCD_WRITE_COM(ST7789_INVOFF)
    //WaitMs 1
    Call LCD_WRITE_COM(ST7789_NORON)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_COLMOD )
    Call LCD_WRITE_DATA(0x55)
    //WaitMs 1
    Call LCD_WRITE_COM(0xB7) //emtry mode
    Call LCD_WRITE_DATA(0x07)
    Call LCD_WRITE_COM(ST7789_DISP_FUNC)    // Display Function Control
    Call LCD_WRITE_DATA(0x08)
    Call LCD_WRITE_DATA(0x82)
    Call LCD_WRITE_DATA(0x27)
    WaitMs 1
    Call LCD_WRITE_COM(ST7789_SLPOUT)
    WaitMs 120
    Call LCD_WRITE_COM(ST7789_DISPON)
    WaitMs 1

    LCD_height = 240
    LCD_width = 320

End Proc

'/**************************************************************************/
'@brief  SPI displays set an address window rectangle For blitting pixels
'@param  x  Top left corner x coordinate
'@param  y  Top left corner x coordinate
'@param  W  Width of window
'@param  h  Height of window
'/**************************************************************************/
Proc setAddrWindow(x1 As Word, y1 As Word, x2 As Word, y2 As Word)

Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
Call LCD_WRITE_DATA(x1.HB)
Call LCD_WRITE_DATA(x1.LB)
Call LCD_WRITE_DATA(x2.HB)
Call LCD_WRITE_DATA(x2.LB)
Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
Call LCD_WRITE_DATA(y1.HB)
Call LCD_WRITE_DATA(y1.LB)
Call LCD_WRITE_DATA(y2.HB)
Call LCD_WRITE_DATA(y2.LB)

Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM
End Proc
Proc LCD_DrawLine(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim t As Word
    Dim xerr, yerr, delta_x, delta_y, distance As Integer
    Dim incx, incy, xPix, yPix As Integer
    xerr = 0
    yerr = 0

    delta_x = x2 - x1
    delta_y = y2 - y1
    xPix = x1
    yPix = y1

    If delta_x > 0 Then    incx = 1
    If delta_x = 0 Then incx = 0
    If delta_x < 0 Then
        incx = -1
        delta_x = -delta_x
    Endif

    If delta_y > 0 Then    incy = 1
    If delta_y = 0 Then incy = 0
    If delta_y < 0 Then
        incy = -1
        delta_y = -delta_y
    Endif


    If delta_x > delta_y Then
        distance = delta_x
    Else
        distance = delta_y
    Endif

    For t = 0 To distance + 1 Step 1
         Call LCD_DrawPoint(xPix, yPix, color)
        xerr = xerr + delta_x
        yerr = yerr + delta_y
        If xerr > distance Then
            xerr = xerr - distance
            xPix = xPix + incx
        Endif
        If  yerr > distance Then
            yerr = yerr - distance
            yPix = yPix + incy
        Endif
    Next t
End Proc
Proc LCD_Char( char As Byte, x As Word, y As Word, fcol As Word , bcol As Word)

    Dim  x0 As Integer
    Dim idx, idx2 As Byte
    Dim mask As Byte

    For idx = 0 To 9 Step 1
        mask = _LCDFnt(char, idx)
        For idx2 = 0 To 13 Step 2
            If mask And 0x80 Then
                Call LCD_DrawPoint(x+idx2, y, fcol)
                Call LCD_DrawPoint(x+idx2+1, y, fcol)
                Call LCD_DrawPoint(x+idx2, y+1, fcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, fcol)
            Else
                Call LCD_DrawPoint(x+idx2, y, bcol)
                Call LCD_DrawPoint(x+idx2+1, y, bcol)
                Call LCD_DrawPoint(x+idx2, y+1, bcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, bcol)
            Endif
            mask = ShiftLeft(mask,1)
        Next idx2
        y = y + 2
    Next idx

End Proc
Proc LCD_String( str As String, x As Word, y As Word, fcol As Word , bcol As Word)

Dim idx As Byte
Dim x0 As Word
idx = 0

    While str(idx) <> 0
        Call LCD_Char(str(idx), x, y,fcol,bcol)
        x = x+18
        idx = idx + 1
    Wend

End Proc
// Rectangle

Proc LCD_DrawRectangle( x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Word)

    Call LCD_DrawLine(x1, y1, x2, y1, color)
    Call LCD_DrawLine(x1, y1, x1, y2, color)
    Call LCD_DrawLine(x1, y2, x2, y2, color)
    Call LCD_DrawLine(x2, y1, x2, y2, color)

End Proc
//   Circle routine

Proc LCD_Circle(x1 As Word, y1 As Word, rad As Word, color As Word)
Dim xPix, yPix, di As Integer
xPix = 0
yPix = rad
di = 3 - ShiftLeft(rad,1)
    While xPix <= yPix

    Call LCD_DrawPoint(x1+xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1+yPix, y1-xPix, color)
    Call LCD_DrawPoint(x1+yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1+xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1-xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1-xPix, color)
    xPix = xPix + 1

    If di < 0 Then
        di= (4 * xPix + 6) + di
    Else
        di= (10 + 4 * (xPix-yPix)) + di
        yPix = yPix - 1
    Endif
    Wend

End Proc
// line drawing

Proc LCD_DrawPoint(x1 As Word, y1 As Word ,color As Word)

    Call LCD_WRITE_COM(ST7789_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x1.HB)
    Call LCD_WRITE_DATA(x1.LB)
    Call LCD_WRITE_COM(ST7789_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y1.HB)
    Call LCD_WRITE_DATA(y1.LB)
    Call LCD_WRITE_COM(ST7789_RAMWR)  //write to RAM

    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc

'/**************************************************************************/
Proc fillRect(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)
Dim px As Long
Dim tmp As Word
If x2 > 0 And y2 > 0 Then      //Nonzero width and height?

    Call setAddrWindow(x1, y1, x2, y2)

    px = x2
    px = px * y2
    TFT_CS = 0
    TFT_DC = 1
    While px > 1
        SSPBUF = color.HB
        While SSPSTAT.BF = 0
        Wend
        SSPBUF = color.LB
        While SSPSTAT.BF = 0
        Wend
        px = px - 1
    Wend
    TFT_DC = 1
    TFT_CS = 1
    Endif
End Proc

'/**************************************************************************/
'@brief    Fill the screen completely with one color. Update in subclasses If desired!
'@param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillScreen(color As Word)
Call fillRect(0, 0, LCD_width, LCD_height, color)
End Proc
Proc fillwindow(x1 As Word,y1 As Word,x2 As Word,y2 As Word,color As Word)
Call fillRect(x1, y1, x2, y2, color)
End Proc
Function _LCDFnt(ch As Byte, idx As Byte) As Byte
    Symbol Retval = _LCDFnt

            Select Case ch
                Case " "
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //SPACE
                Case "!"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //!
                Case 34
                    Retval = LookUp(0x00, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  // "
                Case "#"
                    Retval = LookUp(0x00, 0x12, 0x12, 0x7f, 0x24, 0x24, 0xfe, 0x48, 0x48, 0x00), idx  //#
                Case "$"
                    Retval = LookUp(0x00, 0x10, 0x7c, 0x92, 0x70, 0x1c, 0x92, 0x7c, 0x10, 0x00), idx  //$
                Case "%"
                    Retval = LookUp(0x00, 0x41, 0xa2, 0x44, 0x08, 0x10, 0x22, 0x45, 0x82, 0x00), idx  //%
                Case "&"
                    Retval = LookUp(0x00, 0x10, 0x28, 0x10, 0x28, 0x44, 0x43, 0x42, 0x39, 0x00), idx  //&
                Case "'"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //'
                Case "("
                    Retval = LookUp(0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00), idx  //(
                Case ")"
                    Retval = LookUp(0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x20, 0x04, 0x08, 0x00), idx  //)
                Case "*"
                    Retval = LookUp(0x00, 0x08, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x08, 0x00, 0x00), idx  //*
                Case "+"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x00, 0x00), idx  //+
                Case ","
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //,
                Case "-"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00), idx  //-
                Case "."
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00), idx  //.
                Case "/"
                    Retval = LookUp(0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00), idx  ///
                Case "0"
                    Retval = LookUp(0x00, 0x3c, 0x46, 0x4a, 0x4a, 0x52, 0x52, 0x62, 0x3c, 0x00), idx  //0
                Case "1"
                    Retval = LookUp(0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00), idx  //1
                Case "2"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x30, 0x40, 0x40, 0x7e, 0x00), idx  //2
                Case "3"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //3
                Case "4"
                    Retval = LookUp(0x00, 0x09, 0x18, 0x28, 0x48, 0x48, 0x7e, 0x08, 0x08, 0x00), idx  //4
                Case "5"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x7c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //5
                Case "6"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //6
                Case "7"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00), idx  //7
                Case "8"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //8
                Case "9"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //9
                Case ":"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00), idx  //:
                Case ";"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //;
                Case "<"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x10, 0x20, 0x20, 0x10, 0x08, 0x04, 0x00), idx  //<
                Case "="
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00), idx  //=
                Case ">"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x00), idx  //>
                Case "?"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //?
                Case "@"
                    Retval = LookUp(0x00, 0x7e, 0x81, 0x9b, 0xa5, 0xa6, 0x9c, 0x81, 0x7e, 0x00), idx  //@
                Case "A"
                    Retval = LookUp(0x00, 0x18, 0x24, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00), idx  //A
                Case "B"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //B
                Case "C"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00), idx  //C
                Case "D"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //D
                Case "E"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //E
                Case "F"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //F
                Case "G"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x46, 0x42, 0x42, 0x3c, 0x00), idx  //G
                Case "H"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //H
                Case "I"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7e, 0x00), idx  //I
                Case "J"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x30, 0x00), idx  //J
                Case "K"
                    Retval = LookUp(0x00, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //K
                Case "L"
                    Retval = LookUp(0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //L
                Case "M"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //M
                Case "N"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0x42, 0x00), idx  //N
                Case "O"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //O
                Case "P"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //P
                Case "Q"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x46, 0x3e, 0x00), idx  //Q
                Case "R"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //R
                Case "S"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x3c, 0x00), idx  //S
                Case "T"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //T
                Case "U"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //U
                Case "V"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00), idx  //V
                Case "W"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0x00), idx  //W
                Case "X"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00), idx  //X
                Case "Y"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x05, 0x08, 0x08, 0x08, 0x00), idx  //Y
                Case "Z"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7e, 0x00), idx  //Z
                Case "["
                    Retval = LookUp(0x00, 0x3c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x00), idx  //[
                Case "\"
                    Retval = LookUp(0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00), idx  //\
                Case "]"
                    Retval = LookUp(0x00, 0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, 0x00), idx  //]
                Case "^"
                    Retval = LookUp(0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //^
                Case "_"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00), idx  //_
                Case "`"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //`
                Case "a"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x02, 0x1e, 0x22, 0x22, 0x1e, 0x00), idx  //a
                Case "b"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x00), idx  //b
                Case "c"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x20, 0x20, 0x22, 0x1c, 0x00), idx  //c
                Case "d"
                    Retval = LookUp(0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x00), idx  //d
                Case "e"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x20, 0x22, 0x1c, 0x00), idx  //e
                Case "f"
                    Retval = LookUp(0x00, 0x0c, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x10, 0x10, 0x00), idx  //f
                Case "g"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //g
                Case "h"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //h
                Case "i"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //i
                Case "j"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30), idx  //j
                Case "k"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x22, 0x24, 0x38, 0x24, 0x22, 0x22, 0x00), idx  //k
                Case "l"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x00), idx  //l
                Case "m"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x36, 0x2a, 0x22, 0x22, 0x22, 0x00), idx  //m
                Case "n"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //n
                Case "o"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //o
                Case "p"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00), idx  //p
                Case "q"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20), idx  //q
                Case "r"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x2e, 0x30, 0x20, 0x20, 0x20, 0x20, 0x00), idx  //r
                Case "s"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x10, 0x0c, 0x22, 0x1c, 0x00), idx  //s
                Case "t"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x38, 0x10, 0x10, 0x10, 0x12, 0x0c, 0x00), idx  //t
                Case "u"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //u
                Case "v"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x14, 0x08, 0x00), idx  //v
                Case "w"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x36, 0x22, 0x00), idx  //w
                Case "x"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00), idx  //x
                Case "y"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //y
                Case "z"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3e, 0x02, 0x04, 0x08, 0x10, 0x3e, 0x00), idx  //z
                Case "{"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x08, 0x08, 0x10, 0x08, 0x08, 0x08, 0x04), idx  //{
                Case "|"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //|
                Case "}"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x08, 0x08, 0x04, 0x08, 0x08, 0x08, 0x10), idx  //}
                Case "~"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0xcc, 0x33, 0x00, 0x00, 0x00, 0x00), idx  //~
                Case 165 '"Ñ" + chr(165) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7e, 0x05, 0x09, 0x11, 0x7e), idx  //Ñ
                Case 164'"ñ" + chr(164) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x78, 0x12, 0x0a, 0x0a, 0x70), idx  //ñ
            EndSelect

End Function
Hi I,
I've just noticed, that this is for ST7789, no wonder I can't get it to work :)

Can you post our ILI9341 CODE once you have it working ok, please?
C
 
TFT GMT020-02 (ST7789):

To operate the SPI at 16 MHz SCL, I need to set it to Mode 2.
_SPI1_Init(_SPI_MODE2, _SPI_MASTER_SPEED0 | _SPI_ENABLE) 'SCL 16Mhz (64Mhz).

On my LCD, I must keep the command LCD_WRITE_COM(ST7789_INVON) active to ensure the colors display correctly.

However on the GMT320 (ST7789) it has to be: LCD_WRITE_COM(ST7789_INVOFF).

Everything seems to work fine in full screen. :)
For the current color table the configuration is as follows:

TFT GMT020-02 (ST7789):
Call LCD_WRITE_COM(ST7789_MADCTL)
Call LCD_WRITE_DATA(0x08)
Call LCD_WRITE_COM(ST7789_INVON)
TFT GMT320 (ST7789):
Call LCD_WRITE_COM(ST7789_MADCTL)
Call LCD_WRITE_DATA(0x08)
Call LCD_WRITE_COM(ST7789_INVOFF)
 
Hi C... The only difference between the two IS the MADCTRL..

The code I have pasteted before was for the ILI9341.

MADCTRL is 0x28.. Bit 6 MV swaps horiz / vertical BUT.. If your screen is partial we need to look at the direction as well.

On line I found code from RinkyDink and his MADCTRL is 0x48 and rotated 180, was 0x88

Remember! you changed the colour to suit
 
Here is my current code.

I have changed the font to a larger one but it is only size one.

BE CAREFUL.. The font data is on two lines so it needs to be one in the IDE, but Vlad uses a separator
You'll see...


Code:
'Fuses definition.

#define CONFIG1L = 0x00
#define CONFIG1H = 0x38
#define CONFIG2L = 0x1E
#define CONFIG2H = 0x3C
#define CONFIG3L = 0x00
#define CONFIG3H = 0x3D
#define CONFIG4L = 0x80
#define CONFIG4H = 0x00
#define CONFIG5L = 0x0F
#define CONFIG5H = 0xC0
#define CONFIG6L = 0x0F
#define CONFIG6H = 0xE0
#define CONFIG7L = 0x0F
#define CONFIG7H = 0x40

#define CLOCK_FREQUENCY = 32 'Clock 64Mhz
#define STRING_MAX_LENGTH = 60

'#define SIMULATION_WAITMS_VALUE = 1
'************************************************


'*****************************************************
'lcd driver

Const ILI9341_NOP = 0x00
Const ILI9341_SWRESET = 0x01
Const ILI9341_RDDID = 0x04
Const ILI9341_RDDST = 0x09

Const ILI9341_SLPIN = 0x10
Const ILI9341_SLPOUT = 0x11
Const ILI9341_PTLON = 0x12
Const ILI9341_NORON = 0x13

Const ILI9341_INVOFF = 0x20
Const ILI9341_INVON = 0x21
Const ILI9341_DISPOFF = 0x28
Const ILI9341_DISPON = 0x29
Const ILI9341_CASET = 0x2a
Const ILI9341_RASET = 0x2b
Const ILI9341_RAMWR = 0x2c
Const ILI9341_RAMRD = 0x2e

Const ILI9341_PTLAR = 0x30
Const ILI9341_COLMOD = 0x3a
Const ILI9341_MADCTL = 0x36
Const ILI9341_DISP_FUNC = 0xB6


Const ILI9341_MADCTL_MY = 0x80
Const ILI9341_MADCTL_MX = 0x40
Const ILI9341_MADCTL_MV = 0x20
Const ILI9341_MADCTL_ML = 0x10
Const ILI9341_MADCTL_RGB = 0x08
Const ILI9341_MADCTL_MH = 0x04

Const ILI9341_POWER_CTLRA = 0xCB
Const ILI9341_POWER_CTLRB = 0xCF
Const ILI9341_POWER_CTLR1 = 0xC0
Const ILI9341_POWER_CTLR2 = 0xC1
Const ILI9341_VCM_CTRL = 0xC5
Const ILI9341_TIMING_CTLRA = 0xE8
Const ILI9341_TIMING_CTLRB = 0xEA


Const ILI9341_RDID1 = 0xda
Const ILI9341_RDID2 = 0xdb
Const ILI9341_RDID3 = 0xdc
Const ILI9341_RDID4 = 0xdd


Const LCD_BLACK = 0x0000
Const LCD_RED = 0x001f
Const LCD_BLUE = 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0xffe0
Const LCD_WHITE = 0xffff

Dim LCD_width As Word  ///< Display width as modified by current rotation
Dim LCD_height As Word  ///< Display height as modified by current rotation

Dim LCD_rotation As Byte  ///< Display rotation (0 thru 3)

Symbol TFT_RST = LATC.0  'RST RESET pin
Symbol TFT_DC = LATC.1  'DC (SS) Data/Command pin
Symbol TFT_CS = LATC.2  'CS Chip Select pin
Symbol TFT_SCK = LATC.3  'SCK as output
Symbol TFT_SDI = LATC.4  'SDI as input -> SDO
Symbol TFT_SDO = LATC.5  'SDO as output -> SDI
'*************************************************
Dim str As String
Dim x As Byte
OSCCON = 0x60

OSCTUNE.PLLEN = 1
TRISA.1 = 0
TRISC = 0
ADCON1 = 15
Call SPI_init()
Call LCD_init()

str = "MAXIMUM! "
Main:

    x = 1
    While x = 1
    WaitMs 300
    LATA.1 = 1
    Call fillScreen(LCD_RED)

    WaitMs 300
    LATA.1 = 0
    Call fillwindow(10,10,310,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,310,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,310,230,LCD_BLACK)
    Call LCD_DrawLine(310,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,310,120,LCD_BLACK)
    Call LCD_DrawLine(160,10,160,230,LCD_BLACK)

    Call LCD_Circle(160,120,100,LCD_BLUE)
    Call fillwindow(100,50,220,190, LCD_WHITE)
    Call LCD_DrawRectangle(100,50,220,190,LCD_BLUE)
    Call LCD_String( str,90,110, LCD_BLACK, LCD_WHITE)

    WaitMs 2000

Wend
End

Proc SPI_init()

SSPSTAT = 0x40
SSPCON1 = 0x30


End Proc

Proc LCD_WRITE_COM(dat As Byte)
    TFT_CS = 0
    TFT_DC = 0
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_WRITE_DATA(dat As Byte)
    TFT_CS = 0
    TFT_DC = 1
    SSPBUF = dat
    While SSPSTAT.BF = 0
    Wend
    TFT_DC = 1
    TFT_CS = 1

End Proc

Proc LCD_init()

Dim idx As Byte
Dim cmd As Byte
    High TFT_RST
    'ConfigPin TFT_RST = Output
    WaitMs 100
    Low TFT_RST
    WaitMs 100
    High TFT_RST
    WaitMs 200

    Call LCD_WRITE_COM(ILI9341_SWRESET)
    WaitMs 150
    Call LCD_WRITE_COM(ILI9341_DISPOFF)
    Call LCD_WRITE_COM(ILI9341_POWER_CTLRA)     //Power control a
    Call LCD_WRITE_DATA(0x39)
    Call LCD_WRITE_DATA(0x2C)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x34)
    Call LCD_WRITE_DATA(0x02)
    WaitMs 1
    Call LCD_WRITE_COM(ILI9341_POWER_CTLRB)    //Power control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0XC1)
    Call LCD_WRITE_DATA(0X30)
    WaitMs 1
    Call LCD_WRITE_COM(ILI9341_TIMING_CTLRA)    //Timing control a
    Call LCD_WRITE_DATA(0x85)
    Call LCD_WRITE_DATA(0x10)
    Call LCD_WRITE_DATA(0x78)
    WaitMs 1
    Call LCD_WRITE_COM(ILI9341_TIMING_CTLRB)    //Timing control b
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x00)
    WaitMs 1
    Call LCD_WRITE_COM(0xED)    //Power on seq control
    Call LCD_WRITE_DATA(0x64)
    Call LCD_WRITE_DATA(0x03)
    Call LCD_WRITE_DATA(0X12)
    Call LCD_WRITE_DATA(0X81)

    //WaitMs 1
    Call LCD_WRITE_COM(ILI9341_POWER_CTLR1)  //Power control 1
    Call LCD_WRITE_DATA(0x26)                  //VRH[5:0]
    //WaitMs 1
    Call LCD_WRITE_COM(ILI9341_POWER_CTLR2)    //Power control 2
    Call LCD_WRITE_DATA(0x11)               //SAP[2:0];BT[3:0]
    //WaitMs 1
    Call LCD_WRITE_COM(ILI9341_VCM_CTRL)    //VCM control
    Call LCD_WRITE_DATA(0x3e)               //Contrast
    Call LCD_WRITE_DATA(0x28)
   // WaitMs 1
    Call LCD_WRITE_COM(0xF7)
    Call LCD_WRITE_DATA(0x20)
    //WaitMs 1
    Call LCD_WRITE_COM(ILI9341_MADCTL)
    Call LCD_WRITE_DATA(0x28)

    Call LCD_WRITE_COM(ILI9341_INVOFF)
    //WaitMs 1
    Call LCD_WRITE_COM(ILI9341_NORON)
    WaitMs 1
    Call LCD_WRITE_COM(ILI9341_COLMOD )
    Call LCD_WRITE_DATA(0x55)
    //WaitMs 1
    Call LCD_WRITE_COM(0xB7) //emtry mode
    Call LCD_WRITE_DATA(0x07)
    Call LCD_WRITE_COM(ILI9341_DISP_FUNC)    // Display Function Control
    Call LCD_WRITE_DATA(0x08)
    Call LCD_WRITE_DATA(0x82)
    Call LCD_WRITE_DATA(0x27)
    WaitMs 1
    Call LCD_WRITE_COM(ILI9341_SLPOUT)
    WaitMs 120
    Call LCD_WRITE_COM(ILI9341_DISPON)
    WaitMs 1

    LCD_height = 240
    LCD_width = 320

End Proc

'/**************************************************************************/
'@brief  SPI displays set an address window rectangle For blitting pixels
'@param  x  Top left corner x coordinate
'@param  y  Top left corner x coordinate
'@param  W  Width of window
'@param  h  Height of window
'/**************************************************************************/
Proc setAddrWindow(x1 As Word, y1 As Word, x2 As Word, y2 As Word)

Call LCD_WRITE_COM(ILI9341_CASET)  //Column addr set
Call LCD_WRITE_DATA(x1.HB)
Call LCD_WRITE_DATA(x1.LB)
Call LCD_WRITE_DATA(x2.HB)
Call LCD_WRITE_DATA(x2.LB)
Call LCD_WRITE_COM(ILI9341_RASET)  //Row addr set
Call LCD_WRITE_DATA(y1.HB)
Call LCD_WRITE_DATA(y1.LB)
Call LCD_WRITE_DATA(y2.HB)
Call LCD_WRITE_DATA(y2.LB)

Call LCD_WRITE_COM(ILI9341_RAMWR)  //write to RAM
End Proc
Proc LCD_DrawLine(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim t As Word
    Dim xerr, yerr, delta_x, delta_y, distance As Integer
    Dim incx, incy, xPix, yPix As Integer
    xerr = 0
    yerr = 0

    delta_x = x2 - x1
    delta_y = y2 - y1
    xPix = x1
    yPix = y1

    If delta_x > 0 Then    incx = 1
    If delta_x = 0 Then incx = 0
    If delta_x < 0 Then
        incx = -1
        delta_x = -delta_x
    Endif

    If delta_y > 0 Then    incy = 1
    If delta_y = 0 Then incy = 0
    If delta_y < 0 Then
        incy = -1
        delta_y = -delta_y
    Endif


    If delta_x > delta_y Then
        distance = delta_x
    Else
        distance = delta_y
    Endif

    For t = 0 To distance + 1 Step 1
         Call LCD_DrawPoint(xPix, yPix, color)
        xerr = xerr + delta_x
        yerr = yerr + delta_y
        If xerr > distance Then
            xerr = xerr - distance
            xPix = xPix + incx
        Endif
        If  yerr > distance Then
            yerr = yerr - distance
            yPix = yPix + incy
        Endif
    Next t
End Proc
Proc LCD_Char( char As Byte, x As Word, y As Word, fcol As Word , bcol As Word)

    Dim  x0 As Integer
    Dim idx, idx2 As Byte
    Dim mask As Integer

    For idx = 0 To 31 Step 2
        mask.HB = _LCDFnt(char, idx)
        mask.LB = _LCDFnt(char, idx +1)
        For idx2 = 0 To 15 Step 1
            If mask And 0x8000 Then
                Call LCD_DrawPoint(x+idx2, y, fcol)
            Else
                Call LCD_DrawPoint(x+idx2, y, bcol)
            Endif
            mask = ShiftLeft(mask,1)
        Next idx2
        y = y + 1
    Next idx

End Proc
Proc LCD_String( str As String, x As Word, y As Word, fcol As Word , bcol As Word)

Dim idx As Byte
Dim x0 As Word
idx = 0

    While str(idx) <> 0
        Call LCD_Char(str(idx), x, y,fcol,bcol)
        x = x+16
        idx = idx + 1
    Wend

End Proc
// Rectangle

Proc LCD_DrawRectangle( x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Word)

    Call LCD_DrawLine(x1, y1, x2, y1, color)
    Call LCD_DrawLine(x1, y1, x1, y2, color)
    Call LCD_DrawLine(x1, y2, x2, y2, color)
    Call LCD_DrawLine(x2, y1, x2, y2, color)

End Proc
//   Circle routine

Proc LCD_Circle(x1 As Word, y1 As Word, rad As Word, color As Word)
Dim xPix, yPix, di As Integer
xPix = 0
yPix = rad
di = 3 - ShiftLeft(rad,1)
    While xPix <= yPix

    Call LCD_DrawPoint(x1+xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1+yPix, y1-xPix, color)
    Call LCD_DrawPoint(x1+yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1+xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-xPix, y1+yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1+xPix, color)
    Call LCD_DrawPoint(x1-xPix, y1-yPix, color)
    Call LCD_DrawPoint(x1-yPix, y1-xPix, color)
    xPix = xPix + 1

    If di < 0 Then
        di= (4 * xPix + 6) + di
    Else
        di= (10 + 4 * (xPix-yPix)) + di
        yPix = yPix - 1
    Endif
    Wend

End Proc
// line drawing

Proc LCD_DrawPoint(x1 As Word, y1 As Word ,color As Word)

    Call LCD_WRITE_COM(ILI9341_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x1.HB)
    Call LCD_WRITE_DATA(x1.LB)
    Call LCD_WRITE_COM(ILI9341_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y1.HB)
    Call LCD_WRITE_DATA(y1.LB)
    Call LCD_WRITE_COM(ILI9341_RAMWR)  //write to RAM

    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc

'/**************************************************************************/
Proc fillRect(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)
Dim px As Long
Dim tmp As Word
If x2 > 0 And y2 > 0 Then      //Nonzero width and height?

    Call setAddrWindow(x1, y1, x2, y2)

    px = x2
    px = px * y2
    TFT_CS = 0
    TFT_DC = 1
    While px > 1
        SSPBUF = color.HB
        While SSPSTAT.BF = 0
        Wend
        SSPBUF = color.LB
        While SSPSTAT.BF = 0
        Wend
        px = px - 1
    Wend
    TFT_DC = 1
    TFT_CS = 1
    Endif
End Proc

'/**************************************************************************/
'@brief    Fill the screen completely with one color. Update in subclasses If desired!
'@param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillScreen(color As Word)
Call fillRect(0, 0, LCD_width, LCD_height, color)
End Proc
Proc fillwindow(x1 As Word,y1 As Word,x2 As Word,y2 As Word,color As Word)
Call fillRect(x1, y1, x2, y2, color)
End Proc
Function _LCDFnt(ch As Byte, idx As Byte) As Byte
    Symbol Retval = _LCDFnt
    Select Case ch
    Case 32
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx '//
    Case 33
    Retval = LookUp(0x00,0x00,0x00,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx'// !
    Case 34
    Retval = LookUp(0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x18,0x60,0x10,0x40,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx '// "
    Case 35
    Retval = LookUp(0x00,0x00,0x00,0x00,0x06,0x30,0x06,0x30,0x06,0x30,0x1F,0xF8,0x1F,0xF8,0x0C,0x60,            0x0C,0x60,0x0C,0x60,0x3F,0xF0,0x3F,0xF0,0x18,0xC0,0x18,0xC0,0x00,0x00,0x00,0x00),idx '// #
    Case 36
    Retval = LookUp(0x00,0x00,0x01,0x00,0x07,0xC0,0x0F,0xE0,0x0D,0x20,0x0D,0x00,0x0D,0x00,0x0F,0xC0,            0x07,0xE0,0x01,0x60,0x01,0x60,0x09,0x60,0x0F,0xE0,0x07,0xC0,0x01,0x00,0x00,0x00),idx' // $
    Case 37
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x18,0x0A,0x30,0x0E,0x60,0x00,0xC0,0x00,0x80,            0x01,0x80,0x03,0x00,0x06,0x00,0x04,0x70,0x0C,0x50,0x18,0x70,0x00,0x00,0x00,0x00),idx '// %
    Case 38
    Retval = LookUp(0x00,0x00,0x00,0x00,0x03,0xC0,0x07,0xE0,0x06,0x60,0x06,0x60,0x06,0x60,0x0F,0xE0,            0x0F,0xC0,0x1D,0xC0,0x18,0xE0,0x18,0xE0,0x1F,0xF0,0x0F,0xD8,0x00,0x00,0x00,0x00),idx // &
    Case 39
    Retval = LookUp(0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // '
    Case 40
    Retval = LookUp(0x00,0x00,0x00,0x60,0x00,0xE0,0x01,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0xC0,0x00,0xE0,0x00,0x60,0x00,0x00),idx // (
    Case 41
    Retval = LookUp(0x00,0x00,0x06,0x00,0x07,0x00,0x03,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x03,0x80,0x07,0x00,0x06,0x00,0x00,0x00),idx // )
    Case 42
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x1F,0xF8,            0x1F,0xF8,0x03,0xC0,0x06,0x60,0x06,0x60,0x0C,0x30,0x0C,0x30,0x00,0x00,0x00,0x00),idx // *
    Case 43
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xF0,            0x0F,0xF0,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // +
    Case 44
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x03,0x00),idx // ,
    Case 45
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,            0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // -
    Case 46
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,0x00,0x00),idx // .
    Case 47
    Retval = LookUp(0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x60,0x00,0x60,0x00,0xC0,0x00,0xC0,0x01,0x80,            0x01,0x80,0x03,0x00,0x03,0x00,0x06,0x00,0x06,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00),idx // /
    Case 48
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x1F,0xF0,0x18,0x30,0x18,0x70,0x18,0xB0,0x18,0xB0,            0x19,0x30,0x1A,0x30,0x1A,0x30,0x1C,0x30,0x1F,0xF0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // 0
    Case 49
    Retval = LookUp(0x00,0x00,0x00,0x00,0x03,0x80,0x07,0x80,0x05,0x80,0x01,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00),idx // 1
    Case 50
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x08,0x60,0x00,0x60,0x00,0x60,0x00,0xE0,            0x03,0xC0,0x07,0x80,0x0E,0x00,0x0C,0x00,0x0F,0xE0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // 2
    Case 51
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x60,0x08,0x60,0x00,0x60,0x01,0xC0,            0x01,0xC0,0x00,0x60,0x00,0x60,0x08,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // 3
    Case 52
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,            0x0D,0x80,0x0D,0x80,0x0F,0xE0,0x0F,0xE0,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx // 4
    Case 53
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x0C,0x00,0x0C,0x00,0x0F,0xC0,0x0F,0xE0,            0x08,0x60,0x00,0x60,0x00,0x60,0x08,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // 5
    Case 54
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0F,0xC0,            0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // 6
    Case 55
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x08,0x60,0x00,0x60,0x00,0x60,0x00,0x60,            0x00,0xE0,0x00,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx // 7
    Case 56
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x07,0xC0,            0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // 8
    Case 57
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,            0x07,0xE0,0x00,0x60,0x00,0x60,0x08,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // 9
    Case 58
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,            0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx // :
    Case 59
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,            0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x00,0x00,0x00),idx // ;
    Case 60
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x80,0x03,0x00,0x06,0x00,0x0C,0x00,            0x0C,0x00,0x06,0x00,0x03,0x00,0x01,0x80,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00),idx // <
    Case 61
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,0x00,0x00,            0x00,0x00,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // =
    Case 62
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x01,0x80,0x00,0xC0,0x00,0x60,0x00,0x30,            0x00,0x30,0x00,0x60,0x00,0xC0,0x01,0x80,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // >
    Case 63
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x08,0x60,0x00,0x60,0x00,0x60,0x01,0xE0,            0x03,0xC0,0x03,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00),idx // ?
    Case 64
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xE0,0x0F,0xF0,0x1C,0x30,0x19,0xF0,0x1B,0xF0,0x1B,0x30,            0x1B,0x30,0x1B,0xF0,0x19,0xD0,0x1C,0x38,0x0F,0xF0,0x07,0xE0,0x00,0x00,0x00,0x00),idx // @
    Case 65
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0F,0xE0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x00,0x00,0x00,0x00),idx // A
    Case 66
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0F,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x0F,0xC0,0x00,0x00,0x00,0x00),idx // B
    Case 67
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0C,0x00,            0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x20,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // C
    Case 68
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x0F,0xC0,0x00,0x00,0x00,0x00),idx // D
    Case 69
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0F,0x80,            0x0F,0x80,0x0C,0x00,0x0C,0x00,0x0C,0x20,0x0F,0xE0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // E
    Case 70
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0F,0x00,            0x0F,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00),idx // F
    Case 71
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0C,0x00,            0x0C,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // G
    Case 72
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,            0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x00,0x00,0x00,0x00),idx // H
    Case 73
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xE0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // I
    Case 74
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,            0x01,0x80,0x01,0x80,0x01,0x80,0x09,0x80,0x0F,0x80,0x07,0x00,0x00,0x00,0x00,0x00),idx // J
    Case 75
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x60,0x0C,0x60,0x0C,0xC0,0x0D,0x80,0x0D,0x80,0x0F,0x00,            0x0F,0x00,0x0D,0x80,0x0D,0xC0,0x0C,0xC0,0x0C,0x60,0x0C,0x60,0x00,0x00,0x00,0x00),idx // K
    Case 76
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,            0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0F,0xE0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // L
    Case 77
    Retval = LookUp(0x00,0x00,0x00,0x00,0x18,0x30,0x1C,0x70,0x1F,0xF0,0x1F,0xF0,0x1B,0xB0,0x18,0x30,            0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,0x00,0x00,0x00,0x00),idx // M
    Case 78
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x30,0x0E,0x30,0x0E,0x30,0x0F,0x30,0x0F,0x30,0x0D,0xB0,            0x0D,0xF0,0x0C,0xF0,0x0C,0xF0,0x0C,0x70,0x0C,0x70,0x0C,0x30,0x00,0x00,0x00,0x00),idx // N
    Case 79
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xE0,0x0F,0xF0,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,            0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0F,0xF0,0x07,0xE0,0x00,0x00,0x00,0x00),idx // O
    Case 80
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0F,0xE0,0x0F,0xC0,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00),idx // P
    Case 81
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0C,0x60,0x0C,0x60,0x0D,0xE0,0x0D,0xE0,0x0F,0xE0,0x07,0xF0,0x00,0x00,0x00,0x00),idx // Q
    Case 82
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xC0,0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0F,0xE0,0x0F,0xC0,0x0C,0xC0,0x0C,0xC0,0x0C,0x60,0x0C,0x60,0x00,0x00,0x00,0x00),idx // R
    Case 83
    Retval = LookUp(0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,0x0C,0x20,0x0C,0x00,0x0C,0x00,0x0F,0xC0,            0x07,0xE0,0x00,0x60,0x00,0x60,0x08,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // S
    Case 84
    Retval = LookUp(0x00,0x00,0x00,0x00,0x1F,0xE0,0x1F,0xE0,0x13,0x20,0x03,0x00,0x03,0x00,0x03,0x00,            0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00),idx // T
    Case 85
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // U
    Case 86
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,            0x0C,0x60,0x0E,0xE0,0x06,0xC0,0x07,0xC0,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00),idx // V
    Case 87
    Retval = LookUp(0x00,0x00,0x00,0x00,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x30,            0x18,0x30,0x1B,0xB0,0x1F,0xF0,0x1F,0xF0,0x1C,0x70,0x18,0x30,0x00,0x00,0x00,0x00),idx // W
    Case 88
    Retval = LookUp(0x00,0x00,0x00,0x00,0x18,0x60,0x18,0x60,0x18,0x60,0x0C,0xC0,0x07,0x80,0x03,0x00,            0x03,0x00,0x07,0x80,0x07,0x80,0x0C,0xC0,0x18,0x60,0x18,0x60,0x00,0x00,0x00,0x00),idx // X
    Case 89
    Retval = LookUp(0x00,0x00,0x00,0x00,0x18,0x60,0x18,0x60,0x18,0x60,0x18,0x60,0x1C,0xE0,0x0F,0xC0,            0x07,0x80,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00),idx // Y
    Case 90
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0F,0xE0,0x0F,0xE0,0x08,0x60,0x00,0x60,0x00,0xC0,0x01,0x80,            0x03,0x00,0x06,0x00,0x0C,0x00,0x0C,0x20,0x0F,0xE0,0x0F,0xE0,0x00,0x00,0x00,0x00),idx // Z
    Case 91
    Retval = LookUp(0x00,0x00,0x0F,0xC0,0x0F,0xC0,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,            0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0F,0xC0,0x0F,0xC0,0x00,0x00),idx // [
    Case 92
    Retval = LookUp(0x00,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x06,0x00,0x06,0x00,0x03,0x00,0x03,0x80,            0x01,0x80,0x00,0xC0,0x00,0x60,0x00,0x60,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x00),idx // \
    Case 93
    Retval = LookUp(0x00,0x00,0x03,0xF0,0x03,0xF0,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,            0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x03,0xF0,0x03,0xF0,0x00,0x00),idx // ]
    Case 94
    Retval = LookUp(0x00,0x00,0x00,0x00,0x01,0x80,0x03,0xC0,0x06,0x60,0x0C,0x30,0x18,0x18,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // ^
    Case 95
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x7F,0xFE),idx // _
    Case 96
    Retval = LookUp(0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),idx // '
    Case 97
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x0F,0xC0,0x00,0xC0,            0x07,0xC0,0x0F,0xC0,0x0C,0xC0,0x0C,0xC0,0x0F,0xC0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // a
    Case 98
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0D,0xC0,            0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x0D,0xC0,0x00,0x00,0x00,0x00),idx // b
    Case 99
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,            0x0F,0xC0,0x0C,0x00,0x0C,0x00,0x0C,0x40,0x0F,0xC0,0x07,0x80,0x00,0x00,0x00,0x00),idx // c
    Case 100
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x60,0x00,0x60,0x07,0x60,            0x0F,0xE0,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x0F,0xE0,0x07,0x60,0x00,0x00,0x00,0x00),idx // d
    Case 101
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x0F,0xE0,            0x0C,0x60,0x0F,0xE0,0x0F,0xE0,0x0C,0x00,0x0F,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00),idx // e
    Case 102
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0xE0,0x01,0x80,0x01,0x80,            0x07,0xE0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx // f
    Case 103
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,            0x0F,0xE0,0x0C,0x60,0x0F,0xE0,0x07,0xE0,0x00,0x60,0x0F,0xE0,0x07,0xC0,0x00,0x00),idx // g
    Case 104
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0D,0x80,            0x0F,0xC0,0x0C,0xC0,0x0C,0xC0,0x0C,0xC0,0x0C,0xC0,0x0C,0xC0,0x00,0x00,0x00,0x00),idx // h
    Case 105
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x00,0x00,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00),idx // i
    Case 106
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,            0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x09,0x80,0x0F,0x80,0x07,0x00,0x00,0x00),idx // j
    Case 107
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x60,            0x06,0x60,0x06,0xC0,0x07,0x80,0x07,0x80,0x06,0xC0,0x06,0x60,0x06,0x60,0x00,0x00),idx // k
    Case 108
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,            0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00),idx // l
    Case 109
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x60,            0x0F,0xE0,0x0F,0xE0,0x0D,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x60,0x00,0x00,0x00,0x00),idx // m
    Case 110
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,            0x06,0xE0,0x07,0xE0,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x00,0x00,0x00,0x00),idx // n
    Case 111
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,            0x07,0xE0,0x06,0x60,0x06,0x60,0x06,0x60,0x07,0xE0,0x03,0xC0,0x00,0x00,0x00,0x00),idx // o
    Case 112
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,            0x07,0xE0,0x06,0x60,0x06,0x60,0x07,0xE0,0x07,0xC0,0x06,0x00,0x06,0x00,0x00,0x00),idx // p
    Case 113
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,            0x0F,0xC0,0x0C,0xC0,0x0C,0xC0,0x0F,0xC0,0x07,0xC0,0x00,0xC0,0x00,0xC0,0x00,0x00),idx // q
    Case 114
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0xC0,            0x07,0xC0,0x06,0x40,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00),idx // r
    Case 115
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x0F,0xC0,            0x0C,0x40,0x0F,0x00,0x03,0x80,0x08,0xC0,0x0F,0xC0,0x07,0x80,0x00,0x00,0x00,0x00),idx // s
    Case 116
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x0F,0xC0,            0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0xE0,0x01,0xC0,0x00,0x00,0x00,0x00),idx // t
    Case 117
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,            0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x07,0xE0,0x03,0xE0,0x00,0x00,0x00,0x00),idx // u
    Case 118
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,            0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x07,0xE0,0x03,0xC0,0x01,0x80,0x00,0x00),idx // v
    Case 119
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0xC0,0x06,0xC0,            0x06,0xC0,0x03,0x80,0x03,0x80,0x06,0xC0,0x06,0xC0,0x06,0xC0,0x00,0x00,0x00,0x00),idx // w
    Case 120
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,0x06,0x60,            0x06,0x60,0x07,0xE0,0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x07,0x00,0x00,0x00),idx // x
    Case 121
    Retval = LookUp(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x0F,0xC0,            0x01,0x80,0x03,0x00,0x06,0x00,0x0C,0x00,0x0F,0xC0,0x0F,0xC0,0x00,0x00,0x00,0x00),idx // y
    Case 122
    Retval = LookUp(0x00,0x00,0x01,0x80,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x06,0x00,            0x06,0x00,0x06,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x01,0x80,0x00,0x00),idx // z

    EndSelect

End Function
 
All ok.

TFT 3.2V MSP3218 (ILI9341):
Call LCD_WRITE_COM(ILI9341_MADCTL)
Call LCD_WRITE_DATA(0x20)
Llamar a LCD_WRITE_COM(ILI9341_INVOFF)

This TFT is more affected by parasitic capacitances and I cannot get it to work at 16Mhz.
 
Last edited:
I have merged it with the initial libraries and it has become as follows:

Code:
'*************************************************************************
' Special Command Signifiers
'*************************************************************************
Const ST_CMD_DELAY    =  0x80    ' Special signifier for command lists
'*************************************************************************
' Basic ST7789 Commands
'*************************************************************************
Const ST77XX_NOP      =  0x00    ' No operation
Const ST77XX_SWRESET  =  0x01    ' Software reset
Const ST77XX_RDDID    =  0x04    ' Read display ID
Const ST77XX_RDDST    =  0x09    ' Read display status

Const ST77XX_SLPIN    =  0x10    ' Enter sleep mode
Const ST77XX_SLPOUT   =  0x11    ' Exit sleep mode
Const ST77XX_PTLON    =  0x12    ' Enable partial mode
Const ST77XX_NORON    =  0x13    ' Exit partial mode (normal display mode)

Const ST77XX_INVOFF   =  0x20    ' Display inversion off
Const ST77XX_INVON    =  0x21    ' Display inversion on
Const ST77XX_DISPOFF  =  0x28    ' Display off
Const ST77XX_DISPON   =  0x29    ' Display on
Const ST77XX_CASET    =  0x2A    ' Column address set
Const ST77XX_RASET    =  0x2B    ' Row address set
Const ST77XX_RAMWR    =  0x2C    ' Memory write
Const ST77XX_RAMRD    =  0x2E    ' Memory read

Const ST77XX_PTLAR    =  0x30    ' Partial area
Const ST77XX_COLMOD   =  0x3A    ' Interface pixel format
Const ST77XX_MADCTL   =  0x36    ' Memory access control
Const ST77xx_DISP_FUNC = 0xB6    ' Display function control

'*************************************************************************
' MADCTL Options (Memory Access Control Register)
'*************************************************************************
Const ST77XX_MADCTL_MY  = 0x80    ' Row address order (top to bottom)
Const ST77XX_MADCTL_MX  = 0x40    ' Column address order (left to right)
Const ST77XX_MADCTL_MV  = 0x20    ' Row/column exchange (rotation)
Const ST77XX_MADCTL_ML  = 0x10    ' Vertical refresh order
Const ST77XX_MADCTL_RGB = 0x08    ' RGB color order (default)

'*************************************************************************
' ID Reading Commands
'*************************************************************************
Const ST77XX_RDID1     = 0xDA    ' Read ID part 1
Const ST77XX_RDID2     = 0xDB    ' Read ID part 2
Const ST77XX_RDID3     = 0xDC    ' Read ID part 3
Const ST77XX_RDID4     = 0xDD    ' Read ID part 4

'*************************************************************************
' Predefined 16-Bit Colors (RGB565 Format)
'*************************************************************************
Const LCD_BLACK   = 0x0000    ' Black color
Const LCD_RED     = 0x001F    ' Red color
Const LCD_BLUE    = 0xF800    ' Blue color
Const LCD_GREEN   = 0x07E0    ' Green color
Const LCD_YELLOW  = 0x07FF    ' Yellow color (Red + Green)
Const LCD_MAGENTA = 0xF81F    ' Magenta color (Red + Blue)
Const LCD_CYAN    = 0xFFE0    ' Cyan color (Green + Blue)
Const LCD_WHITE   = 0xFFFF    ' White color (Red + Green + Blue)
''/**************************************************************************/
''    @brief  Configuration and control of SPI for ST7789 display
''            Includes SPI initialization and command writing procedures.
''**************************************************************************/

'*************************************************************************
' Constants and Pin Definitions
'*************************************************************************

' LCD dimensions (modified by current rotation settings)
Const LCD_width = 320        ' Display width
Const LCD_height = 240       ' Display height

' SPI Pin Definitions
Symbol TFT_RST = LATC.0      ' Reset pin (RST)
Symbol TFT_DC  = LATC.1      ' Data/Command pin (DC/SS)
Symbol TFT_CS  = LATC.2      ' Chip Select pin (CS)
Symbol TFT_SCK = LATC.3      ' Clock pin (SCK)
Symbol TFT_SDI = PORTC.4     ' Serial Data In (SDI, input)
Symbol TFT_SDO = LATC.5      ' Serial Data Out (SDO, output)

' SPI Pin I/O Definitions
Symbol TFT_RST_IO = PORTC.0  ' Reset pin as I/O
Symbol TFT_DC_IO  = PORTC.1  ' Data/Command pin as I/O
Symbol TFT_CS_IO  = PORTC.2  ' Chip Select pin as I/O
Symbol TFT_SCK_IO = PORTC.3  ' Clock pin as I/O
Symbol TFT_SDI_IO = PORTC.4  ' Serial Data In pin as I/O
Symbol TFT_SDO_IO = PORTC.5  ' Serial Data Out pin as I/O

' SPI Operation Modes
Const LCD_SPI_MODE0 = 0         ' Clock low, data sampled on rising edge
Const LCD_SPI_MODE1 = 1         ' Clock low, data sampled on falling edge
Const LCD_SPI_MODE2 = 2         ' Clock high, data sampled on falling edge
Const LCD_SPI_MODE3 = 3         ' Clock high, data sampled on rising edge

' SPI Speeds
Const LCD_SPI_MASTER_SPEED0 = 0 ' Clock Fosc/4
Const LCD_SPI_MASTER_SPEED1 = 1 ' Clock Fosc/16
Const LCD_SPI_MASTER_SPEED2 = 2 ' Clock Fosc/64
Const LCD_SPI_MASTER_SPEED3 = 3 ' Clock TMR2 output/2

' Data Sampling Points
Const LCD_SMP_MIDDLE = %00000000 ' Data sampled in the middle of the output time
Const LCD_SMP_END    = %10000000 ' Data sampled at the end of the output time

' SPI Module Enable/Disable
Const LCD_SPI_ENABLE  = %00100000 ' Enable SSP module
Const LCD_SPI_DISABLE = %00000000 ' Disable SSP module

'*************************************************************************
' SPI Initialization Procedure
'*************************************************************************

'' @brief  Initializes the SPI module (MSSP1) in master mode.
''         Configures SPI mode, speed, and pin directions.
'' @param  mode  SPI operation mode (0 to 3).
'' @param  speed SPI speed setting (bits 3-0 of SSPCON1).
Proc LCD_SPI1_Init(mode As Byte, speed As Byte)
    ' Configure SPI pins
    ConfigPin TFT_RST_IO = Output   ' RESET pin as output
    ConfigPin TFT_DC_IO = Output    ' Data/Command pin as output
    ConfigPin TFT_CS_IO = Output    ' Chip Select pin as output
    ConfigPin TFT_SCK_IO = Output   ' Clock pin as output
    ConfigPin TFT_SDI_IO = Input    ' SDI pin as input
    ConfigPin TFT_SDO_IO = Output   ' SDO pin as output

    ' Configure SPI operation mode
    Select Case mode
        Case 0
            SSP1CON1.4 = 0 ' CKP = 0 (clock idle low)
            SSP1STAT.6 = 1 ' CKE = 1 (data changes on falling edge, sampled on rising edge)
        Case 1
            SSP1CON1.4 = 0 ' CKP = 0 (clock idle low)
            SSP1STAT.6 = 0 ' CKE = 0 (data changes on rising edge, sampled on falling edge)
        Case 2
            SSP1CON1.4 = 1 ' CKP = 1 (clock idle high)
            SSP1STAT.6 = 1 ' CKE = 1 (data changes on rising edge, sampled on falling edge)
        Case 3
            SSP1CON1.4 = 1 ' CKP = 1 (clock idle high)
            SSP1STAT.6 = 0 ' CKE = 0 (data changes on falling edge, sampled on rising edge)
    EndSelect

    ' Configure SPI speed and enable the module
    SSP1CON1 = SSP1CON1 | speed
End Proc

'*************************************************************************
' LCD Command Writing Procedure
'*************************************************************************

'' @brief  Sends a command byte to the LCD.
''         Controls DC and CS pins for proper communication.
'' @param  dat  Command byte to be sent.
Proc LCD_WRITE_COM(dat As Byte)
    TFT_CS = 0            ' Enable the LCD (Chip Select active)
    TFT_DC = 0            ' Set to command mode (DC low)
    SSPBUF = dat          ' Load the command byte into the SPI buffer
    While SSPSTAT.BF = 0  ' Wait for the transmission to complete
    Wend
    TFT_DC = 1            ' Return to data mode (DC high)
    TFT_CS = 1            ' Disable the LCD (Chip Select inactive)
End Proc
'' @brief  Sends a data byte to the LCD over SPI.
''         Controls the Data/Command (DC) and Chip Select (CS) pins to
''         indicate that the transmitted byte is data.
'' @param  dat  The data byte to send to the LCD.
Proc LCD_WRITE_DATA(dat As Byte)
    ' Select the LCD (Chip Select active)
    TFT_CS = 0

    ' Set DC pin high to indicate data mode
    TFT_DC = 1

    ' Send the data byte via SPI
    SSPBUF = dat

    ' Wait for the SPI transmission to complete
    While SSPSTAT.BF = 0
    Wend

    ' Optionally keep DC high, as it is data mode by default
    TFT_DC = 1

    ' Deselect the LCD (Chip Select inactive)
    TFT_CS = 1
End Proc
''/**************************************************************************/
''    @brief  Initialization code for ST7789 display
''            This function initializes the display controller using a
''            predefined sequence of commands and data. It sets up power,
''            timing, and display configuration parameters.
''/**************************************************************************/
Proc LCD_init()

    ' Reset sequence for the display controller
    High TFT_RST                ' Set the reset pin high
    ' ConfigPin TFT_RST = Output ' Ensure the pin is configured as output
    WaitMs 100                  ' Wait 100ms
    Low TFT_RST                 ' Pull the reset pin low
    WaitMs 100                  ' Wait 100ms
    High TFT_RST                ' Set the reset pin high again
    WaitMs 200                  ' Wait 200ms for the reset to complete

    ' Send software reset command
    Call LCD_WRITE_COM(ST77XX_SWRESET)  ' Software reset
    WaitMs 150                          ' Wait for the reset to take effect

    ' Turn off the display (preparation step)
    Call LCD_WRITE_COM(ST77XX_DISPOFF)  ' Display off

    ' Power control A configuration
    Call LCD_WRITE_COM(0xCB)
    Call LCD_WRITE_DATA(0x39)
    Call LCD_WRITE_DATA(0x2C)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x34)
    Call LCD_WRITE_DATA(0x02)
    WaitMs 1

    ' Power control B configuration
    Call LCD_WRITE_COM(0xCF)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0xC1)
    Call LCD_WRITE_DATA(0x30)
    WaitMs 1

    ' Timing control A configuration
    Call LCD_WRITE_COM(0xE8)
    Call LCD_WRITE_DATA(0x85)
    Call LCD_WRITE_DATA(0x10)
    Call LCD_WRITE_DATA(0x78)
    WaitMs 1

    ' Timing control B configuration
    Call LCD_WRITE_COM(0xEA)
    Call LCD_WRITE_DATA(0x00)
    Call LCD_WRITE_DATA(0x00)
    WaitMs 1

    ' Power-on sequence control
    Call LCD_WRITE_COM(0xED)
    Call LCD_WRITE_DATA(0x64)
    Call LCD_WRITE_DATA(0x03)
    Call LCD_WRITE_DATA(0x12)
    Call LCD_WRITE_DATA(0x81)

    ' Power control 1 (VRH)
    Call LCD_WRITE_COM(0xC0)
    Call LCD_WRITE_DATA(0x26)

    ' Power control 2 (SAP and BT settings)
    Call LCD_WRITE_COM(0xC1)
    Call LCD_WRITE_DATA(0x11)

    ' VCM control (Contrast settings)
    Call LCD_WRITE_COM(0xC5)
    Call LCD_WRITE_DATA(0x3E)
    Call LCD_WRITE_DATA(0x28)

    ' Frame rate control (set to default)
    Call LCD_WRITE_COM(0xF7)
    Call LCD_WRITE_DATA(0x20)

    ' Memory access control (MADCTL)
    Call LCD_WRITE_COM(ST77XX_MADCTL)
    Call LCD_WRITE_DATA(0x08)   ' Set orientation and RGB order

    ' Disable display inversion
    Call LCD_WRITE_COM(ST77XX_INVOFF)

    ' Normal display mode
    Call LCD_WRITE_COM(ST77XX_NORON)
    WaitMs 1

    ' Set pixel format to 16 bits per pixel
    Call LCD_WRITE_COM(ST77XX_COLMOD)
    Call LCD_WRITE_DATA(0x55)

    ' Entry mode configuration
    Call LCD_WRITE_COM(0xB7)
    Call LCD_WRITE_DATA(0x07)

    ' Display function control
    Call LCD_WRITE_COM(ST77xx_DISP_FUNC)
    Call LCD_WRITE_DATA(0x08)
    Call LCD_WRITE_DATA(0x82)
    Call LCD_WRITE_DATA(0x27)
    WaitMs 1

    ' Exit sleep mode
    Call LCD_WRITE_COM(ST77XX_SLPOUT)
    WaitMs 120                  ' Wait for the display to wake up

    ' Turn on the display
    Call LCD_WRITE_COM(ST77XX_DISPON)
    WaitMs 1                    ' Wait for the display to turn on

End Proc
'/**************************************************************************/
'  @brief  SPI displays set an address window rectangle For blitting pixels
'  @param  x1  Top left corner x coordinate
'  @param  y1 Top left corner x coordinate
'  @param  x2  Width of window
'  @param  y2  Height of window
'/**************************************************************************/
Proc setAddrWindow(x1 As Word, y1 As Word, x2 As Word, y2 As Word)

    Call LCD_WRITE_COM(ST77XX_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x1.HB)
    Call LCD_WRITE_DATA(x1.LB)
    Call LCD_WRITE_DATA(x2.HB)
    Call LCD_WRITE_DATA(x2.LB)
    Call LCD_WRITE_COM(ST77XX_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y1.HB)
    Call LCD_WRITE_DATA(y1.LB)
    Call LCD_WRITE_DATA(y2.HB)
    Call LCD_WRITE_DATA(y2.LB)

    Call LCD_WRITE_COM(ST77XX_RAMWR)  //write to RAM
End Proc

'/**************************************************************************/
'    @brief  Set origin of (0,0) And orientation of TFT display
'    @param  m  The index For rotation, from 0-3 inclusive
'/**************************************************************************/
Proc SetRotation(m As Word)
  Dim rotation As Byte
  Dim madctl As Byte
  madctl = 0

  If m > 3 Then m = 3
   rotation = m

  Select Case (rotation)
   Case 0
     madctl  = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB
   Case 1
     madctl  = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB
  Case 2
     madctl  = ST77XX_MADCTL_RGB
   Case 3
     madctl  = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB
  EndSelect
   Call LCD_WRITE_COM(ST77XX_MADCTL)
   Call LCD_WRITE_DATA(madctl)
End Proc
'    @brief  Draw a single pixel on the LCD at the specified coordinates.
'            The pixel color is defined in '565' RGB format.
'    @param  x1     X coordinate of the pixel.
'    @param  y1     Y coordinate of the pixel.
'    @param  color  16-bit pixel color in '565' RGB format.
Proc LCD_DrawPoint(x1 As Word, y1 As Word, color As Word)

    ' Set column address (X coordinate)
    Call LCD_WRITE_COM(ST77XX_CASET)  // Column address set
    Call LCD_WRITE_DATA(x1.HB)        // High byte of X coordinate
    Call LCD_WRITE_DATA(x1.LB)        // Low byte of X coordinate

    ' Set row address (Y coordinate)
    Call LCD_WRITE_COM(ST77XX_RASET)  // Row address set
    Call LCD_WRITE_DATA(y1.HB)        // High byte of Y coordinate
    Call LCD_WRITE_DATA(y1.LB)        // Low byte of Y coordinate

    ' Write pixel data to RAM
    Call LCD_WRITE_COM(ST77XX_RAMWR)  // Write to RAM
    Call LCD_WRITE_DATA(color.HB)     // High byte of color
    Call LCD_WRITE_DATA(color.LB)     // Low byte of color

End Proc
Proc DrawPixel(x As Word, y As Word, color As Word)

    Call LCD_WRITE_COM(ST77XX_CASET)  //Column addr set
    Call LCD_WRITE_DATA(x.HB)
    Call LCD_WRITE_DATA(x.LB)
    Call LCD_WRITE_COM(ST77XX_RASET)  //Row addr set
    Call LCD_WRITE_DATA(y.HB)
    Call LCD_WRITE_DATA(y.LB)
    Call LCD_WRITE_COM(ST77XX_RAMWR)  //write to RAM

    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc
'    @brief  Draw a straight line on the LCD using Bresenham's line algorithm.
'            The line is defined by its start and end points and is drawn pixel by pixel.
'    @param  x1     X coordinate of the starting point.
'    @param  y1     Y coordinate of the starting point.
'    @param  x2     X coordinate of the ending point.
'    @param  y2     Y coordinate of the ending point.
'    @param  color  16-bit pixel color in '565' RGB format.
Proc LCD_DrawLine(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim t As Word
    Dim xerr, yerr, delta_x, delta_y, distance As Integer
    Dim incx, incy, xPix, yPix As Integer
    xerr = 0
    yerr = 0

    delta_x = x2 - x1
    delta_y = y2 - y1
    xPix = x1
    yPix = y1

    ' Determine the direction of the line
    If delta_x > 0 Then incx = 1
    If delta_x = 0 Then incx = 0
    If delta_x < 0 Then
        incx = -1
        delta_x = -delta_x
    Endif

    If delta_y > 0 Then incy = 1
    If delta_y = 0 Then incy = 0
    If delta_y < 0 Then
        incy = -1
        delta_y = -delta_y
    Endif

    ' Determine the distance to iterate
    If delta_x > delta_y Then
        distance = delta_x
    Else
        distance = delta_y
    Endif

    ' Draw the line pixel by pixel
    For t = 0 To distance + 1 Step 1
        Call LCD_DrawPoint(xPix, yPix, color) ' Draw current pixel
        xerr = xerr + delta_x
        yerr = yerr + delta_y
        If xerr > distance Then
            xerr = xerr - distance
            xPix = xPix + incx
        Endif
        If yerr > distance Then
            yerr = yerr - distance
            yPix = yPix + incy
        Endif
    Next t

End Proc
'/**************************************************************************/
'   @brief    Draw A perfectly horizontal line (this is often optimized in A subclass!)
'    @param    x   Left-most x coordinate
'    @param    y   Left-most y coordinate
'    @param    W   Width in pixels
'   @param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc drawHLine(x As Byte, y As Byte, _W As Byte, color As Word)

    Call LCD_DrawLine(x, y, _W, 1, color)

End Proc

'/**************************************************************************/
'   @brief    Draw A perfectly vertical line (this is often optimized in A subclass!)
'    @param    x   Top-most x coordinate
'    @param    y   Top-most y coordinate
'    @param    h   Height in pixels
'   @param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc drawVLine(x As Word, y As Word, h As Word, color As Word)

    Call LCD_DrawLine(x, y, 1, h, color)

End Proc
'    @brief  Draw a rectangle on the LCD by connecting four lines.
'            The rectangle is defined by its top-left and bottom-right corners.
'    @param  x1     X coordinate of the top-left corner.
'    @param  y1     Y coordinate of the top-left corner.
'    @param  x2     X coordinate of the bottom-right corner.
'    @param  y2     Y coordinate of the bottom-right corner.
'    @param  color  16-bit pixel color in '565' RGB format.
Proc LCD_DrawRectangle(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Word)

    ' Draw the top edge of the rectangle
    Call LCD_DrawLine(x1, y1, x2, y1, color)

    ' Draw the left edge of the rectangle
    Call LCD_DrawLine(x1, y1, x1, y2, color)

    ' Draw the bottom edge of the rectangle
    Call LCD_DrawLine(x1, y2, x2, y2, color)

    ' Draw the right edge of the rectangle
    Call LCD_DrawLine(x2, y1, x2, y2, color)

End Proc
'/**************************************************************************/
'   @brief    Fill A rectangle completely with one color. Update in subclasses If desired!
'    @param    x   Top left corner x coordinate
'    @param    y   Top left corner y coordinate
'    @param    W   Width in pixels
'    @param    h   Height in pixels
'   @param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillRect(x1 As Word, y1 As Word, x2 As Word, y2 As Word, color As Word)

    Dim px As Long
    If x2 > 0 And y2 > 0 Then      //Nonzero width and height?
        Call setAddrWindow(x1, y1, x2, y2)
        px = x2
        px = px * y2
        TFT_CS = 0
        TFT_DC = 1
        While px > 1
            SSP1BUF = color.HB
            While SSP1STAT.BF = 0
            Wend
            SSP1BUF = color.LB
            While SSP1STAT.BF = 0
            Wend
            --px
        Wend
        TFT_DC = 1
        TFT_CS = 1
    Endif

End Proc
'    @brief  Draw a circle on the LCD using the midpoint circle algorithm.
'            The circle is defined by its center coordinates, radius, and color.
'    @param  x1     Horizontal position of the circle's center (X coordinate).
'    @param  y1     Vertical position of the circle's center (Y coordinate).
'    @param  rad    Radius of the circle in pixels.
'    @param  color  16-bit pixel color in '565' RGB format.
Proc LCD_Circle(x1 As Word, y1 As Word, rad As Word, color As Word)

    Dim xPix, yPix, di As Integer
    xPix = 0
    yPix = rad
    di = 3 - rad << 1 'ShiftLeft(rad, 1)

    While xPix <= yPix

        ' Draw symmetric points for the circle
        Call LCD_DrawPoint(x1+xPix, y1-yPix, color)
        Call LCD_DrawPoint(x1+yPix, y1-xPix, color)
        Call LCD_DrawPoint(x1+yPix, y1+xPix, color)
        Call LCD_DrawPoint(x1+xPix, y1+yPix, color)
        Call LCD_DrawPoint(x1-xPix, y1+yPix, color)
        Call LCD_DrawPoint(x1-yPix, y1+xPix, color)
        Call LCD_DrawPoint(x1-xPix, y1-yPix, color)
        Call LCD_DrawPoint(x1-yPix, y1-xPix, color)

        xPix = xPix + 1

        ' Update decision parameter and adjust yPix if necessary
        If di < 0 Then
            di = di + (4 * xPix + 6)
        Else
            di = di + (10 + 4 * (xPix - yPix))
            yPix = yPix - 1
        Endif
    Wend

End Proc
'/**************************************************************************/
'   @brief    Fill the screen completely with one color. Update in subclasses If desired!
'    @param    color 16-Bit 5-6-5 Color To fill with
'/**************************************************************************/
Proc fillScreen(color As Word)
    Call fillRect(0, 0, LCD_width, LCD_height, color)
End Proc
Proc fillwindow(x1 As Word,y1 As Word,x2 As Word,y2 As Word,color As Word)
Call fillRect(x1, y1, x2, y2, color)
End Proc
'/**************************************************************************/
'    @brief  Invert the colors of the display (If supported by hardware).
'            Self-contained, no transaction setup required.
'    @param  i  True = inverted display, False = normal display.
'/**************************************************************************/
Proc invertDisplay(i As Bit)
    If i Then
        Call LCD_WRITE_COM(ST77XX_INVON)
    Else
        Call LCD_WRITE_COM(ST77XX_INVOFF)
    Endif
End Proc
'    @brief  Push a 16-bit color to the LCD RAM with a command transaction.
'            Deprecated function, preserved for backward compatibility.
'    @param  color  16-bit pixel color in '565' RGB format.
Proc pushColor(color As Word)

    Call LCD_WRITE_COM(ST77XX_RAMWR)  //write to RAM
    Call LCD_WRITE_DATA(color.HB)
    Call LCD_WRITE_DATA(color.LB)

End Proc

'    @brief  Draw a character at a specified position on the LCD.
'            Characters are rendered with foreground and background colors.
'    @param  char   ASCII character to display.
'    @param  x      Horizontal position (starting X coordinate).
'    @param  y      Vertical position (starting Y coordinate).
'    @param  fcol   Foreground color in '565' RGB format.
'    @param  bcol   Background color in '565' RGB format.
Proc LCD_Char(char As Byte, x As Word, y As Word, fcol As Word, bcol As Word)

    Dim  x0 As Integer
    Dim idx, idx2 As Byte
    Dim mask As Byte

    For idx = 0 To 9 Step 1
        mask = _LCDFnt(char, idx)
        For idx2 = 0 To 13 Step 2
            If mask And 0x80 Then
                Call LCD_DrawPoint(x+idx2, y, fcol)
                Call LCD_DrawPoint(x+idx2+1, y, fcol)
                Call LCD_DrawPoint(x+idx2, y+1, fcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, fcol)
            Else
                Call LCD_DrawPoint(x+idx2, y, bcol)
                Call LCD_DrawPoint(x+idx2+1, y, bcol)
                Call LCD_DrawPoint(x+idx2, y+1, bcol)
                Call LCD_DrawPoint(x+idx2+1, y+1, bcol)
            Endif
            mask = ShiftLeft(mask,1)
        Next idx2
        y = y + 2
    Next idx

End Proc

'    @brief  Display a string of characters on the LCD at a given position.
'            Each character is rendered with specified foreground and background colors.
'    @param  str    String to display.
'    @param  x      Horizontal position (starting X coordinate).
'    @param  y      Vertical position (starting Y coordinate).
'    @param  fcol   Foreground color in '565' RGB format.
'    @param  bcol   Background color in '565' RGB format.
Proc LCD_String(str As String, x As Word, y As Word, fcol As Word, bcol As Word)

    Dim idx As Byte
    Dim x0 As Word
    idx = 0

    While str(idx) <> 0
        Call LCD_Char(str(idx), x, y, fcol, bcol)
        x = x + 18
        idx = idx + 1
    Wend

End Proc

Function _LCDFnt(ch As Byte, idx As Byte) As Byte
    Symbol Retval = _LCDFnt

            Select Case ch
                Case " "
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //SPACE
                Case "!"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //!
                Case 34
                    Retval = LookUp(0x00, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  // "
                Case "#"
                    Retval = LookUp(0x00, 0x12, 0x12, 0x7f, 0x24, 0x24, 0xfe, 0x48, 0x48, 0x00), idx  //#
                Case "$"
                    Retval = LookUp(0x00, 0x10, 0x7c, 0x92, 0x70, 0x1c, 0x92, 0x7c, 0x10, 0x00), idx  //$
                Case "%"
                    Retval = LookUp(0x00, 0x41, 0xa2, 0x44, 0x08, 0x10, 0x22, 0x45, 0x82, 0x00), idx  //%
                Case "&"
                    Retval = LookUp(0x00, 0x10, 0x28, 0x10, 0x28, 0x44, 0x43, 0x42, 0x39, 0x00), idx  //&
                Case "'"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //'
                Case "("
                    Retval = LookUp(0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00), idx  //(
                Case ")"
                    Retval = LookUp(0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x20, 0x04, 0x08, 0x00), idx  //)
                Case "*"
                    Retval = LookUp(0x00, 0x08, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x08, 0x00, 0x00), idx  //*
                Case "+"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x00, 0x00), idx  //+
                Case ","
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //,
                Case "-"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00), idx  //-
                Case "."
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00), idx  //.
                Case "/"
                    Retval = LookUp(0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00), idx  ///
                Case "0"
                    Retval = LookUp(0x00, 0x3c, 0x46, 0x4a, 0x4a, 0x52, 0x52, 0x62, 0x3c, 0x00), idx  //0
                Case "1"
                    Retval = LookUp(0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00), idx  //1
                Case "2"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x30, 0x40, 0x40, 0x7e, 0x00), idx  //2
                Case "3"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x0c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //3
                Case "4"
                    Retval = LookUp(0x00, 0x09, 0x18, 0x28, 0x48, 0x48, 0x7e, 0x08, 0x08, 0x00), idx  //4
                Case "5"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x7c, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //5
                Case "6"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //6
                Case "7"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00), idx  //7
                Case "8"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //8
                Case "9"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x42, 0x3c, 0x00), idx  //9
                Case ":"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00), idx  //:
                Case ";"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x08, 0x08, 0x10, 0x00), idx  //;
                Case "<"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x10, 0x20, 0x20, 0x10, 0x08, 0x04, 0x00), idx  //<
                Case "="
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00), idx  //=
                Case ">"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x00), idx  //>
                Case "?"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00), idx  //?
                Case "@"
                    Retval = LookUp(0x00, 0x7e, 0x81, 0x9b, 0xa5, 0xa6, 0x9c, 0x81, 0x7e, 0x00), idx  //@
                Case "A"
                    Retval = LookUp(0x00, 0x18, 0x24, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00), idx  //A
                Case "B"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //B
                Case "C"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00), idx  //C
                Case "D"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00), idx  //D
                Case "E"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //E
                Case "F"
                    Retval = LookUp(0x00, 0x7e, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //F
                Case "G"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x40, 0x46, 0x42, 0x42, 0x3c, 0x00), idx  //G
                Case "H"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //H
                Case "I"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7e, 0x00), idx  //I
                Case "J"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x30, 0x00), idx  //J
                Case "K"
                    Retval = LookUp(0x00, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //K
                Case "L"
                    Retval = LookUp(0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00), idx  //L
                Case "M"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x42, 0x00), idx  //M
                Case "N"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0x42, 0x00), idx  //N
                Case "O"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //O
                Case "P"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x00), idx  //P
                Case "Q"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x46, 0x3e, 0x00), idx  //Q
                Case "R"
                    Retval = LookUp(0x00, 0x7c, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42, 0x42, 0x00), idx  //R
                Case "S"
                    Retval = LookUp(0x00, 0x3c, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x3c, 0x00), idx  //S
                Case "T"
                    Retval = LookUp(0x00, 0x7e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //T
                Case "U"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00), idx  //U
                Case "V"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00), idx  //V
                Case "W"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0x00), idx  //W
                Case "X"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00), idx  //X
                Case "Y"
                    Retval = LookUp(0x00, 0x42, 0x42, 0x24, 0x18, 0x05, 0x08, 0x08, 0x08, 0x00), idx  //Y
                Case "Z"
                    Retval = LookUp(0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7e, 0x00), idx  //Z
                Case "["
                    Retval = LookUp(0x00, 0x3c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x00), idx  //[
                Case "\"
                    Retval = LookUp(0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00), idx  //\
                Case "]"
                    Retval = LookUp(0x00, 0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, 0x00), idx  //]
                Case "^"
                    Retval = LookUp(0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //^
                Case "_"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00), idx  //_
                Case "`"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), idx  //`
                Case "a"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x02, 0x1e, 0x22, 0x22, 0x1e, 0x00), idx  //a
                Case "b"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x00), idx  //b
                Case "c"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x20, 0x20, 0x22, 0x1c, 0x00), idx  //c
                Case "d"
                    Retval = LookUp(0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x00), idx  //d
                Case "e"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x20, 0x22, 0x1c, 0x00), idx  //e
                Case "f"
                    Retval = LookUp(0x00, 0x0c, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x10, 0x10, 0x00), idx  //f
                Case "g"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //g
                Case "h"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //h
                Case "i"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //i
                Case "j"
                    Retval = LookUp(0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30), idx  //j
                Case "k"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x22, 0x24, 0x38, 0x24, 0x22, 0x22, 0x00), idx  //k
                Case "l"
                    Retval = LookUp(0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x00), idx  //l
                Case "m"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x36, 0x2a, 0x22, 0x22, 0x22, 0x00), idx  //m
                Case "n"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00), idx  //n
                Case "o"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //o
                Case "p"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00), idx  //p
                Case "q"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20), idx  //q
                Case "r"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x2e, 0x30, 0x20, 0x20, 0x20, 0x20, 0x00), idx  //r
                Case "s"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x1c, 0x22, 0x10, 0x0c, 0x22, 0x1c, 0x00), idx  //s
                Case "t"
                    Retval = LookUp(0x00, 0x10, 0x10, 0x38, 0x10, 0x10, 0x10, 0x12, 0x0c, 0x00), idx  //t
                Case "u"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00), idx  //u
                Case "v"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x14, 0x08, 0x00), idx  //v
                Case "w"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x36, 0x22, 0x00), idx  //w
                Case "x"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00), idx  //x
                Case "y"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x3c), idx  //y
                Case "z"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x3e, 0x02, 0x04, 0x08, 0x10, 0x3e, 0x00), idx  //z
                Case "{"
                    Retval = LookUp(0x00, 0x04, 0x08, 0x08, 0x08, 0x10, 0x08, 0x08, 0x08, 0x04), idx  //{
                Case "|"
                    Retval = LookUp(0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00), idx  //|
                Case "}"
                    Retval = LookUp(0x00, 0x10, 0x08, 0x08, 0x08, 0x04, 0x08, 0x08, 0x08, 0x10), idx  //}
                Case "~"
                    Retval = LookUp(0x00, 0x00, 0x00, 0x00, 0xcc, 0x33, 0x00, 0x00, 0x00, 0x00), idx  //~
                Case 165 '"Ñ" + chr(165) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x7e, 0x05, 0x09, 0x11, 0x7e), idx  //Ñ
                Case 164'"ñ" + chr(164) +
                    Retval = LookUp(0x00, 0x00, 0x00, 0x78, 0x12, 0x0a, 0x0a, 0x70), idx  //ñ
            EndSelect

End Function
 
Last edited:

Latest threads

New Articles From Microcontroller Tips

Back
Top