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: 168
  • ST7789_240X240.bas
    15 KB · Views: 152
  • _SPI_Library.bas
    6 KB · Views: 161
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 149
  • _SetUpAmicus18.bas
    2.9 KB · Views: 140
Now this is weird.

I just plugged the LCD st7789 240 x 240 back in "as is" using the init I already created for the ILI9341.

It worked straight off the bat..

All I have done now is shorten the graphical writes to fit ( I also had to turn inversion on)

Go figure the drivers are the same..
 
Last edited:
I'll put it on tonight .. Still cant get 16Mhz... must be the breadboard.
The colours aren't as vibrant maybe that's what all the power controls are for.

BUT! Its the exact same code I used on the ILI screen it just worked.. all I did was alter the graphical out put to 240 x 240 and set the height and width to 240.. I'm sure if you have a 320 x 240 it just works.

The INV has to be on as its colours were backwards... The MADCTL BGR may need to be RGB which is bit 4
 
As requested.


I haven't changed the symbols at all.. I'm running 32Mhz on a pic18f46k22 SPI at 8Mhz
SPI in MODE 3

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 = 0x00

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,230,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,230,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,230,230,LCD_BLACK)
    Call LCD_DrawLine(230,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,230,120,LCD_BLACK)
    Call LCD_DrawLine(120,10,120,230,LCD_BLACK)

    Call LCD_Circle(120,120,100,LCD_BLUE)
    Call fillwindow(60,50,180,190, LCD_WHITE)
    Call LCD_DrawRectangle(60,50,180,190,LCD_BLUE)
    Call LCD_String( str,50,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(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(ILI9341_MADCTL)
    Call LCD_WRITE_DATA(0x8)
    Call LCD_WRITE_COM(ILI9341_INVON)
    //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(0x3A) //pixel format
    Call LCD_WRITE_DATA(0x55) //16bit
    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 = 240

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 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(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 " "
                    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
 
As requested.


I haven't changed the symbols at all.. I'm running 32Mhz on a pic18f46k22 SPI at 8Mhz
SPI in MODE 3

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 = 0x00

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,230,230, LCD_BLUE)
    WaitMs 300
    LATA.1 = 1
    Call fillwindow(10,10,230,230, LCD_GREEN)
    WaitMs 300
    LATA.1 = 0
    Call fillScreen(LCD_WHITE)
    Call LCD_DrawLine(10,10,230,230,LCD_BLACK)
    Call LCD_DrawLine(230,10,10,230,LCD_BLACK)
    Call LCD_DrawLine(10,120,230,120,LCD_BLACK)
    Call LCD_DrawLine(120,10,120,230,LCD_BLACK)

    Call LCD_Circle(120,120,100,LCD_BLUE)
    Call fillwindow(60,50,180,190, LCD_WHITE)
    Call LCD_DrawRectangle(60,50,180,190,LCD_BLUE)
    Call LCD_String( str,50,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(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(ILI9341_MADCTL)
    Call LCD_WRITE_DATA(0x8)
    Call LCD_WRITE_COM(ILI9341_INVON)
    //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(0x3A) //pixel format
    Call LCD_WRITE_DATA(0x55) //16bit
    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 = 240

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 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(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 " "
                    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,
#164
We have colours circles and squares :)
Well done.
C.
 
Last edited:
Hi,
Yesterday Ian's CODE worked ok, the [ SYMBOL RLED = LATE.2 ] didn't work, so I tried [ PORTE.2 ] and this works. I switched it a number of times, same result.

I tried to copy this working program and correct a few things that were probably my set up interfering with original settings. The original settings didn't work.

Anyway, the CODE sometimes works and sometimes not. I can WRITE working CODE to the PIC, and it doesn't work, then re WRITE it and now it does work.

I switched everything off and on again, I updated the OSH version.
Nothing worked consistently.
So that's been my morning.
C.
 
I have written to BOTH units more than 10 times each.. I have never had a bad write.

BTW, What programmer do you use? I have pickit3 and IPE v5.10
Hi I,
It's a mystery!
I use Pickit 3 and today I updated to V5.7

I use a USB extension, and just ried directly to USB3 socket, which had better results. So it could be something as simple as new cables and shorter Pickit 3 leads?

What voltage is shown on your Pickit ? I have to turn mine up to 3.6V, which I think improved things?
C
 
Hi I,
It's a mystery!
I use Pickit 3 and today I updated to V5.7

I use a USB extension, and just ried directly to USB3 socket, which had better results. So it could be something as simple as new cables and shorter Pickit 3 leads?

What voltage is shown on your Pickit ? I have to turn mine up to 3.6V, which I think improved things?
C
Bear in mind, a PK3 can only supply VERY limited power, a good reason to upgrade to the much more powerful PK4.
 
Bear in mind, a PK3 can only supply VERY limited power, a good reason to upgrade to the much more powerful PK4.
Hi N,
I have a PK4, but seem to remember, that it needs a complicated set up, where PK3 is simple, and not bloated.
Also Ian doesn't have trouble, like me usually and many others.

From what you say PK3 doesn't deliver enough power, do you have any suggestions of a solution?
C.
 
Hi N,
I have a PK4, but seem to remember, that it needs a complicated set up, where PK3 is simple, and not bloated.
Also Ian doesn't have trouble, like me usually and many others.

What 'setup' are you talking about?, you just plug it in - end of story.

From what you say PK3 doesn't deliver enough power, do you have any suggestions of a solution?
C.

Yes, use a PK4 :D

If you've got a TFT on board, then a PK3 will certainly struggle providing enough power for it.
 
Mine is at 3.3v BUT my pic is on a breadboard powered by a switched mode PSU all comes from the same laptop..

I hardly EVER supply a circuit with pickit3 power as the LCD alone will be too much.

If you have the pic in a "programming socket" fine, but its not good to use the pickit 3 to power... The old pickit 2 was better..

I have two USB leads to my laptop.. One to run the circuit and one to the pickit3.

The switched PSU is one of those drop in 7803 replacement devices... Tons more efficient
 
Also... One thing to remember!!! If your pickit3 is plugged in all the time " as mine normally is" and you are on an external MCLRE, the pic never resets right... Either put a manual reset button or use the internal MCLRE.. I had this once on a pic26k80 with this same screen. I put a button on and resolved the reboot
 
What 'setup' are you talking about?, you just plug it in - end of story.
Hi N,
Are you saying that the PK4 simply plugs into the PK3 program?
When I looked at it, it seemed to use MPLAB software, which is a big program and does more than i need, as I use OSH/PK3 for programming.
Yes, use a PK4 :D

If you've got a TFT on board, then a PK3 will certainly struggle providing enough power for it.
I'm a bit confused about how the MCLR works, the PIC is powered, through the board, and it looks like PK3 doesn't need to supply much power. I think PK3 may need to be set a little more than the PCB voltage, but not sure.

I'm checking the PCB to make sure it's clean and all of the connections are ok.
C
 
Hi N,
Are you saying that the PK4 simply plugs into the PK3 program?
When I looked at it, it seemed to use MPLAB software, which is a big program and does more than i need, as I use OSH/PK3 for programming.

The PK4 (and the PK3) are designed to work with MPLABX, if you don't use it you could use the MPLABX IPE to use it as just a programmer.

If you're powering your project separately, then the power problem doesn't apply anyway, and you should have the PK3 power switched OFF.
 
Hi C

Have you ever used the IPE from Microchip? I use it when I program pics.. You just plug it in the same as pickit 3 it is supported by the IPE

The IPE is a stand alone program you do not need to open the MPLAB IDE
 

Latest threads

New Articles From Microcontroller Tips

Back
Top