• 3.5" Color LCD code example

    I recently bought a 3.5" color lcd from China from
    http://cgi.ebay.com/3-5-262k-TFT-240...item1c153a8de4
    for $35.00 including shipping. It also has a touch screen and controller , eeprom, and sd socket.





    Below is the test code. This should get you started if you want to play with this color display.

    I am using 8 bit control for the LCD and hardware SPI for the touch screen controller.

    Here are the spec's

    3.5" QVGA 262k TFT-LCD module
    240*RGB*320 pixels
    LCD driver is SSD2119
    2.7-3.3V operating voltage
    RS1843 touch panel controller onboard directly compatible with ADS7843
    Standard 2.54mm PCB headers for prototyping
    Support a SD card interface(SPI mode)
    Support a ATMEL DataFlash AT45DBxxx series device
    Optional 8-bit or 16-bit parallel bus interface and
    Optional 3 wire SPI or 4 wire SPI interface with PS3、PS2、PS1、PS1 jump select
    4-wire Touch Panel support

    I have to give credit to Darrel Taylor, mister_e, skimask and anyone else I may have used their code over the years.
    Code:
    ' **************************************************  **********
    ' * Auto generated EasyHID file. PBP 2.60 and above          *
    ' **************************************************  **********
    
    ' include the HID descriptor
    include    "DESC_TFT.bas"
    
    DEFINE OSC 48
    DEFINE LOADER_USED 1
    
    ADCON1 = $F       'port A digital
    CMCON = 7         'PortA Digital
    INTCON2.7 = 0     'weak pullups portB
    'INTCON2.4 = 0     'INT2 falling edge
    USBBufferSizeMax   con 64  ' maximum buffer size
    USBBufferSizeTX    con 64  ' input
    USBBufferSizeRX    con 64  ' output
    
    ' the USB buffer...
    USBBuffer        Var Byte[USBBufferSizeMax] 
    USBBufferCount   Var Byte 
    
    
    SPI_Buf_out   var        byte[8]      'spi output buffer
    SPI_Buf_in   var        byte[8]       'spi input buffer
    spi_cnt      var        byte          ' Transmit counter
    ts_y      var        word
    ts_x      var        word
    ts_cs     var        PORTB.5
    number    var        word
    len       var        byte
    high      ts_cs
    ' LCD VARS______________________________________________  ____________
    
    LCD_Dat         var    PORTD
    LCD_CS          var    PORTE.2
    LCD_RS          var    PORTB.3
    LCD_RD          var    PORTE.0
    LCD_WR          var    PORTE.1
    LCD_RST         var    PORTC.6
    CMD             var    word
    DAT             var    word
    Color           var    word
    fColor           var    word
    bColor           var    word
    ' Color
    RED        con  $f800
    GREEN    con  $07e0
    BLUE    con  $001f
    YELLOW    con  $ffe0
    CYAN    con  $07ff
    MAGENTA    con  $f81f
    BLACK    con  $0000
    WHITE    con  $ffff
    rlb   var    byte
    rhb   var    word
    i     var    long
    j     var    long
    k     var    long
    m     var    byte
    n     var    byte
    
    '** Graphic vars **************************************************  ***********
    cx          var     long
    cy          var     long
    sx          var     long
    ex          var     long
    sy          var     long
    ey          var     long
    x           var     word
    y           var     word
    ypos        var     long
    rad         var     long
    rad2         var    long
    color_buf   var     word
    sx_buff      var     word
    ex_buff      var     word
    'Circle constants and variables
    gl_pi            con    2    'PI as an integer
    glc_x            var     BYTE    'Calculation var
    glc_y            var     BYTE    'Calculation var
    glc_s            var     WORD    'Slope
    glc_cx            var     BYTE    'Center x
    glc_cy          var     BYTE    'Center y
    glc_r            var     BYTE    'Radius
    gl_x1            var     word
    gl_x2           var     word
    gl_y1           var     BYTE
    gl_y2           var     BYTE
    b_inp1             var     BYTE
    b_inp2             var     BYTE
    b_inp3             var     BYTE
    gl_i        var    word
    gl_j        var BYTE
    gl_k        var    BYTE
    gl_l        var BYTE
    gl_m        var BYTE
    gl_x        var    WORD
    gl_y        var    WORD
    '=================================================  ==============================
    Invert          var bit
    charsel          var byte[8]
    char_row         var byte
    lu1              var byte
    charpos          var byte
    addr             var word
    addrb            var byte
    addrb = 0
    addr1            var word
    char             var chardata[0]
    chardata         var byte[8]
    temp             var byte
    temp1            var byte
    temp5            var byte
    Im1              var word
    temp2            var byte
    a               var byte
    LCDx    var byte    '  Col position
    LCDy    var byte    '  Row position
    big     var byte
    big = 0
    Row var byte
    col var byte
    
    picdat  var byte
    
    lcdcharloop var byte
    lcdchardata var byte[8]
    tp_cs      var PORTB.5
    
    SSPEN VAR SSPCON1.5   ' SSP Enable bit
    CKP   VAR SSPCON1.4   ' Clock Polarity Select
    SMP   VAR SSPSTAT.7  ' Data input sample phase
    CKE   VAR SSPSTAT.6  ' Clock Edge Select bit
    SSPIF VAR PIR1.3     ' SPI interrupt flag
    WCOL        Var    SSPCON1.7    ' SSP write collision
    BF            Var    SSPSTAT.0    ' SSP buffer full
    SSPCON1 = %00000010    
    Pen_Down  var PORTB.2
    TRISA = %00000000
    TRISB = %00000101
    TRISC = %00000000
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    latD = %11111111
    high lcd_cs
    high lcd_RD
    high lcd_wr
    high lcd_rs
    high lcd_rst
    
        '   Interrupt definition
        '   ====================
            '   USB interrupt used to keep USB connection alive
    INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
    ASM
    INT_LIST  macro    ; IntSource,         Label,  Type, ResetFlag?
            INT_Handler    INT2_INT,  _TS_INT,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE  INT2_INT      ; enable external (INT) interrupt
    
    ASM    ;printstr2 to color LCD macro,    '@ printstr2 x,y, "string2 to lcd at x,y"
    printstr2    macro x2, y2, str2
            local thestring2, overstr2
        
            bra overstr2
    thestring2
            data str2,0
    overstr2
            MOVE?CB x2, _LCDx
            MOVE?CB y2, _Row
            MOVE?CW thestring2, _addr
            L?CALL _stringout2
            endm
    ENDASM
    
    
    pause 1000
    'include "USB_ASM_Service.pbp"
    lcd_dat = $FF
    goto programstart
    '*************************************************  *****************************
    LCD_Write_CMD:
    high lcd_RD
    low lcd_rs
    low lcd_cs
    low lcd_wr
    lcd_dat = cmd.highbyte
    high lcd_wr
    low lcd_wr
    LCD_Dat = cmd.lowbyte
    high lcd_wr
    high lcd_rs
    high lcd_cs
    
    Return
    '*************************************************  *****************************
    LCD_Write_Dat:
    high lcd_RD
    high lcd_rs
    low lcd_cs
    low lcd_wr
    lcd_dat = dat.highbyte
    high lcd_wr
    low lcd_wr
    LCD_Dat = dat.lowbyte
    high lcd_wr
    high lcd_cs
    
    return
    '*************************************************  *****************************
    LCD_Read_Dat:           ' only works with 16 bit control
    TRISD = $FF
    color_buf = 0
    low lcd_cs
    high lcd_rs
    high lcd_wr
    
    
    low lcd_rd      'dummy read
    high lcd_rd
    
    low lcd_rd
    color_buf.lowbyte = lcd_dat 
    high lcd_rd
                                                            'lcd_dat
    low lcd_rd
    color_buf.highbyte = lcd_dat 
    high lcd_rd
    
                                                               'lcd_dat
    TRISD = $00
    high lcd_cs
    return
    '*************************************************  *****************************
    
    LCD_RESET:
    low lcd_rst
    pause 500
    high lcd_rst
    pause 1000
    return
    '*************************************************  *****************************
    LCD_Test:
    gosub lcd_home
    for i = 0 to 319
        for j = 0 to 239
            if i > 279 then 
            dat = black
            elseif i > 239 then 
            dat = blue
            elseif i > 199 then 
            dat = green
            elseif i > 159 then 
            dat = cyan
            elseif i > 119 then 
            dat = red
            elseif i > 79 then 
            dat = magenta
            elseif i > 39 then 
            dat = yellow
            else 
            dat = white
            
            endif
            gosub lcd_write_dat
        next j       
    
    
    
    
    next i
    return
    '*************************************************  *****************************
    LCD_INIT:
    gosub lcd_reset
    cmd = $0028 : gosub lcd_write_CMD : dat = $0006 : gosub lcd_write_dat
    
    pause 10
    cmd = $0000 : gosub lcd_write_CMD : dat = $0001 : gosub lcd_write_dat ' Start OSC
    cmd = $0010 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $0001 : gosub lcd_write_CMD : dat = $30EF : gosub lcd_write_dat  ' Driver output  32EF
    cmd = $0002 : gosub lcd_write_CMD : dat = $0600 : gosub lcd_write_dat   
    cmd = $0003 : gosub lcd_write_CMD : dat = $6A64 : gosub lcd_write_dat   
    cmd = $0011 : gosub lcd_write_CMD : dat = $6830 : gosub lcd_write_dat   
    
    cmd = $000F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    
    cmd = $000B : gosub lcd_write_CMD : dat = $5308 : gosub lcd_write_dat
    cmd = $000C : gosub lcd_write_CMD : dat = $0003 : gosub lcd_write_dat
    cmd = $000D : gosub lcd_write_CMD : dat = $000A : gosub lcd_write_dat
    cmd = $000E : gosub lcd_write_CMD : dat = $2E00 : gosub lcd_write_dat
    
    cmd = $001E : gosub lcd_write_CMD : dat = $002B : gosub lcd_write_dat '
    cmd = $0025 : gosub lcd_write_CMD : dat = $8000 : gosub lcd_write_dat
    cmd = $0026 : gosub lcd_write_CMD : dat = $7000 : gosub lcd_write_dat 
    cmd = $004E : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $004F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    
    cmd = $0012 : gosub lcd_write_CMD : dat = $08D9 : gosub lcd_write_dat
     ' Gama Curve
    cmd = $0030 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $0031 : gosub lcd_write_CMD : dat = $0104 : gosub lcd_write_dat
    cmd = $0032 : gosub lcd_write_CMD : dat = $0100 : gosub lcd_write_dat
    cmd = $0033 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
    cmd = $0034 : gosub lcd_write_CMD : dat = $0505 : gosub lcd_write_dat
    cmd = $0035 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
    cmd = $0036 : gosub lcd_write_CMD : dat = $0707 : gosub lcd_write_dat
    cmd = $0037 : gosub lcd_write_CMD : dat = $0300 : gosub lcd_write_dat
    cmd = $003A : gosub lcd_write_CMD : dat = $1200 : gosub lcd_write_dat
    cmd = $003B : gosub lcd_write_CMD : dat = $0800 : gosub lcd_write_dat
    pause 150
    cmd = $0007 : gosub lcd_write_CMD : dat = $0033 : gosub lcd_write_dat
    pause 200
    
    Return
    '*************************************************  *****************************
    LCD_HOME:
    
    cmd = $004E : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  ' RAM Addsress set X
    cmd = $004F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  ' RAM Addsress set Y
    cmd = $0044 : gosub lcd_write_CMD : dat = $EF00 : gosub lcd_write_dat  'Vertical start/end RAM address position
    cmd = $0045 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  'Horizontal start RAM address position 
    cmd = $0046 : gosub lcd_write_CMD : dat = $013F : gosub lcd_write_dat   ' Horizontal end RAM address position
    cmd = $0022 : gosub lcd_write_CMD     'RAM data write/read
    
    return
    '*************************************************  *****************************
    CLR_DISP:
    color = white
    for i = 0 to 319
        for j = 0 to 239
        dat = color
        gosub lcd_write_dat
        next j
    next i
    return
    '*************************************************  *****************************
    '  Need sx (start x), ex (end x) sy (start y), ey (end y) and Color
    '
    '*************************************************  *****************************
    Fill_Rect:
    ypos.highbyte = ey
    ypos.lowbyte = sy
    
    
    cmd = $004E : gosub lcd_write_CMD : dat = sx : gosub lcd_write_dat  ' RAM Addsress set X
    cmd = $004F : gosub lcd_write_CMD : dat = sy : gosub lcd_write_dat  ' RAM Addsress set Y
    cmd = $0044 : gosub lcd_write_CMD : dat = ypos: gosub lcd_write_dat  'Vertical start/end RAM address position
    cmd = $0045 : gosub lcd_write_CMD : dat = sx : gosub lcd_write_dat  'Horizontal start RAM address position 
    cmd = $0046 : gosub lcd_write_CMD : dat = ex : gosub lcd_write_dat   ' Horizontal end RAM address position
    cmd = $0022 : gosub lcd_write_CMD     'RAM data write/read
    x = ex - sx + 1
    y = ey - sy + 1
    dat = color
    for j = 0 to y
        for i = 0 to x
        gosub lcd_write_dat
        next i
    next j
    return
    
    '*************************************************  *****************************
    '  Need cx (center x), cy (center y), rad (radius) and Color
    '
    '*************************************************  *****************************
    
    '*************************************************  *****************************
    '    need  x, y, color
    '
    '*************************************************  *****************************
    Setdot:
    cmd = $004E : gosub lcd_write_CMD : dat = x : gosub lcd_write_dat  ' RAM Addsress counter set X
    cmd = $004F : gosub lcd_write_CMD : dat = y : gosub lcd_write_dat  ' RAM Addsress counter set Y
    cmd = $0022 : gosub lcd_write_CMD 
    dat = color
    gosub lcd_write_dat
    
    return
    
    ' ***** Set x,y Points *****
    set8:
        x = glc_x+glc_cx : y=glc_y+glc_cy            '1
        gosub setdot
        x = glc_cx-glc_x : y=glc_y+glc_cy        '2    
        gosub setdot
        x = glc_cx+glc_x : y=glc_cy-glc_y        '3    
        gosub setdot
        x = glc_cx-glc_x : y=glc_cy-glc_y        '4    
        gosub setdot
        x = glc_y+glc_cx : y=glc_x+glc_cy        '5
        gosub setdot            
        x = glc_cx-glc_y : y=glc_cy+glc_x        '6    
        gosub setdot
        x = glc_cx+glc_y : y=glc_cy-glc_x        '7    
        gosub setdot
        x = glc_cx-glc_y : y=glc_cy-glc_x        '8    
        gosub setdot
    return
    
    '*** gl_circle d = diameter r = radius x,y are point locations ***
    '***** Given Center = glc_cx,glc_cy and Radius = glc_r **********
    gl_circ:
      glc_x = 0
      glc_y = glc_r
      glc_s = gl_pi-2*glc_r
      
    
      while (glc_x <= glc_y) 
     
          gosub set8
    
        if (glc_s.15 =1) then
               glc_s = glc_s + (4*glc_x + 6)
             else
               glc_s = glc_s + (4*(glc_x-glc_y) + 10)
               glc_y = glc_y - 1
        endif
    
        glc_x = glc_x + 1
      wend
    
    return
    'Rectangle subroutine given gl_x1,gl_x2,gl_y1, gl_y2
    gl_rect:
    
            gosub chk_xy         
        for gl_i= gl_x1 to gl_x2 step 1
            x = gl_i
            y = gl_y1
            gosub setdot
                y = gl_y2
            gosub setdot
        next gl_i
    
        for gl_i= gl_y1 to gl_y2 step 1
            y = gl_i
            x = gl_x1
            gosub setdot
            x = gl_x2
            gosub setdot
        next gl_i
    
    return
    
    chk_xy:
        if gl_x1 > gl_x2 then
            swap gl_x1,gl_x2
            endif
        if gl_y1 > gl_y2 then
            swap gl_y1,gl_y2
            endif
    return
    
    
    
    '*************************************************  ******************************
    '           Text
    '*************************************************  ******************************
    stringout2:        
    lcdy = row
    Readcode addr, char : 
    If char = 0 then return 
    
    gosub putclcdtext : 
    addr = addr + 1 : 
    lcdx = lcdx + 1 : 
    
    lcdy = row 
    
    goto stringout2
    
    
    putclcdtext:    
    if char < 20 then return
     if char > $7f then return
     
     for char_row = 0 to 4
         if char < $50 then
            charpos  = (((char & $ff)- $20)*5)
            gosub table1
            
         endif
    
         if char > $4f then
            charpos  = (((char & $ff)- $50)*5)
            gosub table2
          endif 
    
    next char_row
    if big = 0 then      ' Normal 5x7 font
        for j = 0 to 7   ' data bits 0 - 7
                    
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
                       
            for k = 1 to 5
        
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next k
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        
        next j 
        lcdx = lcdx + 6
        
    
    elseif big = 1 then      ' big 10x14 font
        for j = 0 to 7   ' data bits 0 - 7
        for n = 0 to 1
                     
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
        
            for k = 1 to 5
            for m = 0 to 1    
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next m
            next k
            
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        next n
        next j 
        lcdx = lcdx + 10       '20X24
    elseif big = 2   then
        for j = 0 to 7   ' data bits 0 - 7
        for n = 0 to 3
                     
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
        
            for k = 1 to 5
            for m = 0 to 3    
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next m
            next k
            
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        next n
        next j 
        lcdx = lcdx + 24
    
    endif
    return
    
    '=================
    'FONT SAMPLE 5x7
    '=================
    
    Table1:
    lu1 = charpos + char_row
    
    lookup lu1, [0,0,0,0,0,_             'space
                $00,$00,$5f,$00,$00,_    '// 21 !
                $00,$07,$00,$07,$00,_    ' 22 "
                $14,$7f,$14,$7f,$14,_     ' 23 #
                $24,$2a,$7f,$2a,$12,_     ' 24 $
                $23,$13,$08,$64,$62,_    '  25%
                $36,$49,$55,$22,$50,_     ' 26 &
                $00,$05,$03,$00,$00,_     ' 27 '
                $00,$1c,$22,$41,$00,_     ' 28 (
                $00,$41,$22,$1c,$00,_     ' 29 )
                $14,$08,$3e,$08,$14,_     ' 2a *
                $08,$08,$3e,$08,$08,_     ' 2b +
                $00,$50,$30,$00,$00,_     ' 2c ,
                $08,$08,$08,$08,$08,_     ' 2d -
                $00,$60,$60,$00,$00,_     ' 2e .
                $20,$10,$08,$04,$02,_     ' 2f /
                $3e,$51,$49,$45,$3e,_     ' 30 0
                $00,$42,$7f,$40,$00,_     ' 31 1
                $42,$61,$51,$49,$46,_    ' 32 2
                $21,$41,$45,$4b,$31,_    ' 33 3
                $18,$14,$12,$7f,$10,_    ' 34 4
                $27,$45,$45,$45,$39,_    ' 35 5
                $3c,$4a,$49,$49,$30,_    ' 36 6
                $01,$71,$09,$05,$03,_    ' 37 7
                $36,$49,$49,$49,$36,_    ' 38 8
                $06,$49,$49,$29,$1e,_    '// 39 9
                $00,$36,$36,$00,$00,_    '// 3a :
                $00,$56,$36,$00,$00,_    '// 3b ;
                $08,$14,$22,$41,$00,_    '// 3c <
                $14,$14,$14,$14,$14,_    '// 3d =
                $00,$41,$22,$14,$08,_    '// 3e >
                $02,$01,$51,$09,$06,_    '// 3f ?
                $32,$49,$79,$41,$3e,_    '// 40 @
                $7e,$11,$11,$11,$7e,_    '// 41 A
                $7f,$49,$49,$49,$36,_    '// 42 B
                $3e,$41,$41,$41,$22,_    '// 43 C
                $7f,$41,$41,$22,$1c,_    '// 44 D
                $7f,$49,$49,$49,$41,_    '// 45 E
                $7f,$09,$09,$09,$01,_    '// 46 F
                $3e,$41,$49,$49,$7a,_    ''// 47 G
                $7f,$08,$08,$08,$7f,_    '// 48 H
                $00,$41,$7f,$41,$00,_    '// 49 I
                $20,$40,$41,$3f,$01,_    '// 4a J
                $7f,$08,$14,$22,$41,_    '// 4b K
                $7f,$40,$40,$40,$40,_    '// 4c L
                $7f,$02,$0c,$02,$7f,_    '// 4d M
                $7f,$04,$08,$10,$7f,_    '// 4e N
                $3e,$41,$41,$41,$3e],temp    '// 4f O
    chardata[char_row + 1] = temp
    
    
    Return
    
    Table2:
    lu1 = charpos + char_row
    
    lookup lu1, [$7f,$09,$09,$09,$06,_    '// 50 P
                $3e,$41,$51,$21,$5e,_    '// 51 Q
                $7f,$09,$19,$29,$46,_    '// 52 R
                $46,$49,$49,$49,$31,_    '// 53 S
                $01,$01,$7f,$01,$01,_    '// 54 T
                $3f,$40,$40,$40,$3f,_    '// 55 U
                $1f,$20,$40,$20,$1f,_    '// 56 V
                $3f,$40,$38,$40,$3f,_    '// 57 W
                $63,$14,$08,$14,$63,_    '// 58 X
                $07,$08,$70,$08,$07,_    '// 59 Y
                $61,$51,$49,$45,$43,_    '// 5a Z
                $00,$7f,$41,$41,$00,_    '// 5b [
                $02,$04,$08,$10,$20,_    '// 5c
                $00,$41,$41,$7f,$00,_    '// 5d
                $04,$02,$01,$02,$04,_    '// 5e
                $40,$40,$40,$40,$40,_    '// 5f
                $00,$01,$02,$04,$00,_    '// 60
                $20,$54,$54,$54,$78,_    '// 61 a
                $7f,$48,$44,$44,$38,_    '// 62 b
                $38,$44,$44,$44,$20,_    '// 63 c
                $38,$44,$44,$48,$7f,_    '// 64 d
                $38,$54,$54,$54,$18,_    '// 65 e
                $08,$7e,$09,$01,$02,_    '// 66 f
                $0c,$52,$52,$52,$3e,_    '// 67 g
                $7f,$08,$04,$04,$78,_    '// 68 h
                $00,$44,$7d,$40,$00,_    '// 69 i
                $20,$40,$44,$3d,$00,_    '// 6a j 
                $7f,$10,$28,$44,$00,_    '// 6b k
                $00,$41,$7f,$40,$00,_    '// 6c l
                $7c,$04,$18,$04,$78,_    '// 6d m
                $7c,$08,$04,$04,$78,_    '// 6e n
                $38,$44,$44,$44,$38,_    '// 6f o
                $7c,$14,$14,$14,$08,_    '// 70 p
                $08,$14,$14,$18,$7c,_    '// 71 q
                $7c,$08,$04,$04,$08,_    '// 72 r
                $48,$54,$54,$54,$20,_    '// 73 s
                $04,$3f,$44,$40,$20,_    '// 74 t
                $3c,$40,$40,$20,$7c,_    '// 75 u
                $1c,$20,$40,$20,$1c,_    '// 76 v
                $3c,$40,$30,$40,$3c,_    '// 77 w
                $44,$28,$10,$28,$44,_    '// 78 x
                $0c,$50,$50,$50,$3c,_    '// 79 y
                $44,$64,$54,$4c,$44,_    '// 7a z
                $00,$08,$36,$41,$00,_    '// 7b
                $00,$00,$7f,$00,$00,_    '// 7c
                $00,$41,$36,$08,$00,_    '// 7d
                $10,$08,$08,$10,$08,_    '// 7e
                $78,$46,$41,$46,$78], temp '    // 7f
    chardata[char_row + 1] = temp
    
    
    Return  
    '*************************************************  *****************************
    
    
    
    
    
    '*************************************************  *****************************
    
    '*************************************************  *****************************
    
    '''***********************************************  ********************************
    spi_Write:
            
           SPI_Buf_out[0] = $90    'read y   ADS7843
           SPI_Buf_out[1] = 0
           SPI_Buf_out[2] = $D0    'read x   ADS7843                                                  '
           SPI_Buf_out[3] = 0
           SPI_Buf_out[4] = 0 
           low tp_cs               ' enable touch screen
            
            
            SPI_Buf_in = SSPBUF    ' Clear the buffer.
            SSPIF = 0        ' Clear the interrupt flag.
    for spi_cnt = 0 to 4
            SSPBUF = SPI_Buf_out[spi_cnt]    ' Send the byte.
              While !SSPIF        ' Wait for send to complete.
            Wend
            SPI_Buf_in[spi_cnt] = SSPBUF    'receive data and put in array
            SSPIF = 0          ' reset flag
    next spi_cnt        
    '-------------------Calabration-----------------------------------------------
    ' spi returns a  12 bit number highest is 4095
    ' if the desplay is 320X240  x = 320  so-- 4095/320 = 12.80
    ' we must use integer math,  multiply the spi result by 100, 
    ' then devide that result by the calibration factor  1280 ( 12.80 * 100 )
    ' adjust this number to your display, then do the same for the Y
    '---------------------------------------------------------------------------
         high tp_cs                ' disable touch screen
         ts_y = SPI_Buf_in[1] <<5
         ts_y = 240-(((ts_y +  SPI_Buf_in[2] >>3)*100)/1800)   ' Calibration = 1800 very rough number, change to suit your scteen
         ts_x = SPI_Buf_in[3] <<5
         ts_x = 320-(((ts_x +  SPI_Buf_in[4] >>3)*100)/1244)     
    return
    '*************************************************  ******************************
    Print_Number:    ' need lcd_x , lcd_y , number, len, 
         temp5 = lcdy
       for i = len to 0 step -1
       char = number dig i  + 48
       gosub putclcdtext
       lcdy = temp5
        next i
    
    return
    '*************************************************  ******************************
    
    
    
    '*************************************************  ******************************
    
    '*************************************************  ******************************
    
    
    
    '*************************************************  ******************************
    
    TS_Init:       ' Touch initalization
    '---SPI ________________________________
    'SSPCON1.2 = 1
    SSPEN = 1         ' enable SPI pins  = 1
    CKP = 0           ' clock idle low
    CKE = 1           ' transmit on idle to active transition
    SSPIF = 0         ' clear buffer full status
    SMP = 0            ' sample in middle of data
    
    Return
    '---[INT - interrupt handler]---------------------------------------------------
    TS_INT:
     
    gosub LCD_HOME
    gosub clr_disp
    bcolor = white
    fcolor = black
     color = red
     sx = 159
     ex = 161
     sy = 119
     ey = 121
    gosub fill_rect      'Center dot to check calibration
    gosub LCD_HOME
    gosub  spi_write
    while pen_down = 0
    @ printstr2 125,20, "X = "
    @ printstr2 125,30, "Y = "
    lcdx = 165
    lcdy = 20
    len = 3
    number = ts_x
    gosub  print_number
    lcdx = 165
    lcdy = 30
    len = 3
    number = ts_y
    gosub  print_number   
    wend
       
    @ INT_RETURN
    
    
    ' **************************************************  **********
    ' * receive data from the USB bus                            *
    ' **************************************************  **********
    DoUSBIn:
       USBBufferCount = USBBufferSizeRX              ' RX buffer size
       USBIn 1, USBBuffer, USBBufferCount, DoUSBIn   ' read data, if available
       return
        
    ' **************************************************  **********
    ' * wait for USB interface to attach                         *
    ' **************************************************  **********
    DoUSBOut:
       USBBufferCount = USBBufferSizeTX              ' TX buffer size
       USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
       return
    ' **************************************************  **********
    ' * main program loop - remember, you must keep the USB      *
    ' * connection alive with a call to USBService every couple  *
    ' * of milliseconds or so...                                 *
    ' **************************************************  **********   
    ProgramStart: 
     gosub lcd_init
     gosub lcd_home
     gosub clr_disp
     pause 3000
     gosub lcd_test
     pause 3000
     gosub clr_disp
    
     color = blue
     sx = 0
     ex = 319
     sy = 0
     ey = 239
     gosub fill_rect
    
     color = black
     sx = 0
     ex = 319
     sy = 0
     ey = 70
     gosub fill_rect                
    
    fcolor = white
    bcolor = black
    @ printstr2 25,20, "Testing SSD2119 Controller"
     gosub lcd_home
     color = black
     sx = 20
     ex = 80
     sy = 90
     ey = 130
     gosub fill_rect
    
     color = yellow
     sx = 30
     ex = 90
     sy = 100
     ey = 140
     gosub fill_rect      
    
     color = black
     sx = 20
     ex = 80
     sy = 160
     ey = 200
     gosub fill_rect
    
     color = red
     sx = 30
     ex = 90
     sy = 170
     ey = 210
     gosub fill_rect  
    
      color = white
     sx = 195
     ex = 205
     sy = 71
     ey = 239
     gosub fill_rect 
    for k = 26 to 30
    glc_cx = 160
    glc_cy  = 120
    glc_r = k
    color = magenta
    gosub  gl_circ
    next k
    pause 2000
    gosub lcd_home
    gosub clr_disp
    big = 0
    bcolor = white
    fcolor = black
    @ printstr2 25,5, "Small"
    big = 1
    @ printstr2 25,20, "Bigger"
    big = 2
    @ printstr2 25,50, "Biggest"
    big = 0
    
    
    pause 3000
    gosub lcd_home
    gosub clr_disp
    
    glc_cx = 160
    glc_cy  = 120
    glc_r = 30
    color = green
    gosub  gl_circ
    gl_x1 = 10
    gl_x2 = 310
    gl_y1 =  10 
    gl_y2 = 230
    color = black
    gosub gl_rect
    gosub lcd_home
    bcolor = white
    fcolor = black
    @ printstr2 25,20, "SSD2119 Controller"
    @ printstr2 25,28, "Dave Cutliff "
    @ printstr2 25,36, "TFT Color LCD Model Rev 1.0"
    @ printstr2 25,44, "320xRGBx240"
    @ printstr2 25,60, "PicBasic Pro6.0 "
    @ printstr2 25,68, "Sept 8,2010"
    gosub ts_init
    Loop1:
    ' gosub DoUSBIn
    '  gosub DoUSBOut
    goto loop1
    This file just reads the SD card and displays BMP images. I took out all the other stuff to make it easier to see how to load a BMP file. The pictures stored on the card need to be 320X240 24bit color. You can fiddle with the code to view more pictures if you like.

    It start with a splash screen, then lists the files on the SD card and then loops through the pictures. Notice that BMP files store the image from bottom to top.

    BTW this is a 18F4550 @ 20Mhz

    enjoy

    Dave
    Code:
    '****************************************************************
    '*  Name    : SD_PicFrame_TFT.BAS                               *
    '*  Author  : Dave Cutliff                                      *
    '*  Notice  : Copyright (c) 2010 You can take all you want      *
    '*          : All Rights Reserved                               *
    '*  Date    : 9/21/2010                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    DEFINE OSC 20
    DEFINE LOADER_USED 1
    ADCON1 = $F       'port A digital
    CMCON = 7         'PortA Digital
    INTCON2.7 = 0     'weak pullups portB
    
    Include "SDFSR.pbp"
    SDC_UseHardSPI = TRUE
    
    SPI_Buf_out   var        byte[8]      'spi output buffer
    SPI_Buf_in   var        byte[8]       'spi input buffer
    spi_cnt      var        byte          ' Transmit counter
    ts_y      var        word
    ts_x      var        word
    ts_cs     var        PORTB.5
    number    var        word
    len       var        byte
    high      ts_cs
    ' LCD VARS__________________________________________________________
    
    LCD_Dat         var    PORTD
    LCD_CS          var    PORTE.2
    LCD_RS          var    PORTB.3
    LCD_RD          var    PORTE.0
    LCD_WR          var    PORTE.1
    LCD_RST         var    PORTC.6
    CMD             var    word
    DAT             var    word
    Color           var    word
    fColor           var    word
    bColor           var    word
    rgb              var    word
    cnt              var    word
    first            var    word
    
    
    ' Color
    RED        con  $f800
    GREEN    con  $07e0
    BLUE    con  $001f
    YELLOW    con  $ffe0
    CYAN    con  $07ff
    MAGENTA    con  $f81f
    BLACK    con  $0000
    WHITE    con  $ffff
    rlb   var    byte
    rhb   var    word
    b     var    byte
    c     var    byte
    i     var    long
    j     var    long
    k     var    long
    m     var    byte
    n     var    byte
    p     var    byte
    '** Graphic vars *************************************************************
    cx          var     long
    cy          var     long
    sx          var     long
    ex          var     long
    sy          var     long
    ey          var     long
    x           var     word
    y           var     word
    ypos        var     long
    rad         var     long
    rad2         var    long
    color_buf   var     word
    sx_buff      var     word
    ex_buff      var     word
    'Circle constants and variables
    gl_pi            con    2    'PI as an integer
    glc_x            var     BYTE    'Calculation var
    glc_y            var     BYTE    'Calculation var
    glc_s            var     WORD    'Slope
    glc_cx            var     BYTE    'Center x
    glc_cy          var     BYTE    'Center y
    glc_r            var     BYTE    'Radius
    gl_x1            var     word
    gl_x2           var     word
    gl_y1           var     BYTE
    gl_y2           var     BYTE
    b_inp1             var     BYTE
    b_inp2             var     BYTE
    b_inp3             var     BYTE
    gl_i        var    word
    gl_j        var BYTE
    gl_k        var    BYTE
    gl_l        var BYTE
    gl_m        var BYTE
    gl_x        var    WORD
    gl_y        var    WORD
    '===============================================================================
    Invert          var bit
    charsel          var byte[8]
    char_row         var byte
    lu1              var byte
    charpos          var byte
    addr             var word
    addrb            var byte
    addrb = 0
    addr1            var word
    char             var chardata[0]
    chardata         var byte[8]
    temp             var byte
    temp1            var byte
    temp5            var byte
    Im1              var word
    temp2            var byte
    a               var byte
    LCDx    var byte    '  Col position
    LCDy    var byte    '  Row position
    big     var byte
    big = 0
    Row var byte
    col var byte
    tmp_color        var       word
    tmp1_color        var       word
    
    buffer           var      byte[10]
    TempData         var      byte[3] 
    NoOfChar         var      byte
    TextBuffer       var      byte[64]
    File1            var      byte[11]
    File2            var      byte[11]
    File3            var      byte[11]
    File4            var      byte[11]
    File5            var      byte[11]
    File6            var      byte[11]
    FileNum          var      byte
    BMP_data_offset  var      byte[4]
    
    picdat  var byte
    
    lcdcharloop var byte
    lcdchardata var byte[8]
    tp_cs      var PORTB.5
    
    
    Pen_Down  var PORTB.2
    TRISA = %00000000
    TRISB = %00000101
    TRISC = %00000000
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    latD = %11111111
    high lcd_cs
    high lcd_RD
    high lcd_wr
    high lcd_rs
    high lcd_rst
    
    
    ASM    ;printstr2 to color LCD macro,    '@ printstr2 x,y, "string2 to lcd at x,y"
    printstr2    macro x2, y2, str2
            local thestring2, overstr2
        
            bra overstr2
    thestring2
            data str2,0
    overstr2
            MOVE?CB x2, _LCDx
            MOVE?CB y2, _Row
            MOVE?CW thestring2, _addr
            L?CALL _stringout2
            endm
    ENDASM
    
    
    pause 1000
    'include "USB_ASM_Service.pbp"
    lcd_dat = $FF
    goto programstart
    '******************************************************************************
    LCD_Write_CMD:
    high lcd_RD
    low lcd_rs
    low lcd_cs
    low lcd_wr
    lcd_dat = cmd.highbyte
    high lcd_wr
    low lcd_wr
    LCD_Dat = cmd.lowbyte
    high lcd_wr
    high lcd_rs
    high lcd_cs
    
    Return
    '******************************************************************************
    LCD_Write_Dat:
    high lcd_RD
    high lcd_rs
    low lcd_cs
    low lcd_wr
    lcd_dat = dat.highbyte
    high lcd_wr
    low lcd_wr
    LCD_Dat = dat.lowbyte
    high lcd_wr
    high lcd_cs
    
    return
    '******************************************************************************
    LCD_Read_Dat:           ' only works with 16 bit control
    TRISD = $FF
    color_buf = 0
    low lcd_cs
    high lcd_rs
    high lcd_wr
    
    
    low lcd_rd      'dummy read
    high lcd_rd
    
    low lcd_rd
    color_buf.lowbyte = lcd_dat 
    high lcd_rd
                                                            'lcd_dat
    low lcd_rd
    color_buf.highbyte = lcd_dat 
    high lcd_rd
    
                                                               'lcd_dat
    TRISD = $00
    high lcd_cs
    return
    '******************************************************************************
    
    LCD_RESET:
    low lcd_rst
    pause 500
    high lcd_rst
    pause 1000
    return
    '******************************************************************************
    LCD_Test:
    gosub lcd_home
    for i = 0 to 319
        for j = 0 to 239
            if i > 279 then 
            dat = black
            elseif i > 239 then 
            dat = blue
            elseif i > 199 then 
            dat = green
            elseif i > 159 then 
            dat = cyan
            elseif i > 119 then 
            dat = red
            elseif i > 79 then 
            dat = magenta
            elseif i > 39 then 
            dat = yellow
            else 
            dat = white
            
            endif
            gosub lcd_write_dat
        next j       
    
    
    
    
    next i
    return
    '******************************************************************************
    LCD_INIT:
    gosub lcd_reset
    cmd = $0028 : gosub lcd_write_CMD : dat = $0006 : gosub lcd_write_dat
    
    pause 10
    cmd = $0000 : gosub lcd_write_CMD : dat = $0001 : gosub lcd_write_dat ' Start OSC
    cmd = $0010 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $0001 : gosub lcd_write_CMD : dat = $30EF : gosub lcd_write_dat  ' Driver output  32EF
    cmd = $0002 : gosub lcd_write_CMD : dat = $0600 : gosub lcd_write_dat   
    cmd = $0003 : gosub lcd_write_CMD : dat = $6A64 : gosub lcd_write_dat   
    cmd = $0011 : gosub lcd_write_CMD : dat = $6830 : gosub lcd_write_dat   
    
    cmd = $000F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    
    cmd = $000B : gosub lcd_write_CMD : dat = $5308 : gosub lcd_write_dat
    cmd = $000C : gosub lcd_write_CMD : dat = $0003 : gosub lcd_write_dat
    cmd = $000D : gosub lcd_write_CMD : dat = $000A : gosub lcd_write_dat
    cmd = $000E : gosub lcd_write_CMD : dat = $2E00 : gosub lcd_write_dat
    
    cmd = $001E : gosub lcd_write_CMD : dat = $002B : gosub lcd_write_dat '
    cmd = $0025 : gosub lcd_write_CMD : dat = $8000 : gosub lcd_write_dat
    cmd = $0026 : gosub lcd_write_CMD : dat = $7000 : gosub lcd_write_dat 
    cmd = $004E : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $004F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    
    cmd = $0012 : gosub lcd_write_CMD : dat = $08D9 : gosub lcd_write_dat
     ' Gama Curve
    cmd = $0030 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
    cmd = $0031 : gosub lcd_write_CMD : dat = $0104 : gosub lcd_write_dat
    cmd = $0032 : gosub lcd_write_CMD : dat = $0100 : gosub lcd_write_dat
    cmd = $0033 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
    cmd = $0034 : gosub lcd_write_CMD : dat = $0505 : gosub lcd_write_dat
    cmd = $0035 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
    cmd = $0036 : gosub lcd_write_CMD : dat = $0707 : gosub lcd_write_dat
    cmd = $0037 : gosub lcd_write_CMD : dat = $0300 : gosub lcd_write_dat
    cmd = $003A : gosub lcd_write_CMD : dat = $1200 : gosub lcd_write_dat
    cmd = $003B : gosub lcd_write_CMD : dat = $0800 : gosub lcd_write_dat
    pause 150
    cmd = $0007 : gosub lcd_write_CMD : dat = $0033 : gosub lcd_write_dat
    pause 200
    
    Return
    '******************************************************************************
    LCD_HOME:
    
    cmd = $004E : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  ' RAM Addsress set X
    cmd = $004F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  ' RAM Addsress set Y
    cmd = $0044 : gosub lcd_write_CMD : dat = $EF00 : gosub lcd_write_dat  'Vertical start/end RAM address position
    cmd = $0045 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat  'Horizontal start RAM address position 
    cmd = $0046 : gosub lcd_write_CMD : dat = $013F : gosub lcd_write_dat   ' Horizontal end RAM address position
    cmd = $0022 : gosub lcd_write_CMD     'RAM data write/read
    
    return
    '******************************************************************************
    CLR_DISP:
    color = white
    for i = 0 to 319
        for j = 0 to 239
        dat = color
        gosub lcd_write_dat
        next j
    next i
    return
    '******************************************************************************
    '  Need sx (start x), ex (end x) sy (start y), ey (end y) and Color
    '
    '******************************************************************************
    Fill_Rect:
    ypos.highbyte = ey
    ypos.lowbyte = sy
    
    
    cmd = $004E : gosub lcd_write_CMD : dat = sx : gosub lcd_write_dat  ' RAM Addsress set X
    cmd = $004F : gosub lcd_write_CMD : dat = sy : gosub lcd_write_dat  ' RAM Addsress set Y
    cmd = $0044 : gosub lcd_write_CMD : dat = ypos: gosub lcd_write_dat  'Vertical start/end RAM address position
    cmd = $0045 : gosub lcd_write_CMD : dat = sx : gosub lcd_write_dat  'Horizontal start RAM address position 
    cmd = $0046 : gosub lcd_write_CMD : dat = ex : gosub lcd_write_dat   ' Horizontal end RAM address position
    cmd = $0022 : gosub lcd_write_CMD     'RAM data write/read
    x = ex - sx + 1
    y = ey - sy + 1
    dat = color
    for j = 0 to y
        for i = 0 to x
        gosub lcd_write_dat
        next i
    next j
    return
    
    '******************************************************************************
    '  Need cx (center x), cy (center y), rad (radius) and Color
    '
    '******************************************************************************
    
    '******************************************************************************
    '    need  x, y, color
    '
    '******************************************************************************
    Setdot:
    cmd = $004E : gosub lcd_write_CMD : dat = x : gosub lcd_write_dat  ' RAM Addsress counter set X
    cmd = $004F : gosub lcd_write_CMD : dat = y : gosub lcd_write_dat  ' RAM Addsress counter set Y
    cmd = $0022 : gosub lcd_write_CMD 
    dat = color
    gosub lcd_write_dat
    
    return
    
    ' ***** Set x,y Points *****
    set8:
        x = glc_x+glc_cx : y=glc_y+glc_cy            '1
        gosub setdot
        x = glc_cx-glc_x : y=glc_y+glc_cy        '2    
        gosub setdot
        x = glc_cx+glc_x : y=glc_cy-glc_y        '3    
        gosub setdot
        x = glc_cx-glc_x : y=glc_cy-glc_y        '4    
        gosub setdot
        x = glc_y+glc_cx : y=glc_x+glc_cy        '5
        gosub setdot            
        x = glc_cx-glc_y : y=glc_cy+glc_x        '6    
        gosub setdot
        x = glc_cx+glc_y : y=glc_cy-glc_x        '7    
        gosub setdot
        x = glc_cx-glc_y : y=glc_cy-glc_x        '8    
        gosub setdot
    return
    
    '*** gl_circle d = diameter r = radius x,y are point locations ***
    '***** Given Center = glc_cx,glc_cy and Radius = glc_r **********
    gl_circ:
      glc_x = 0
      glc_y = glc_r
      glc_s = gl_pi-2*glc_r
      
    
      while (glc_x <= glc_y) 
     
          gosub set8
    
        if (glc_s.15 =1) then
               glc_s = glc_s + (4*glc_x + 6)
             else
               glc_s = glc_s + (4*(glc_x-glc_y) + 10)
               glc_y = glc_y - 1
        endif
    
        glc_x = glc_x + 1
      wend
    
    return
    'Rectangle subroutine given gl_x1,gl_x2,gl_y1, gl_y2
    gl_rect:
    
            gosub chk_xy         
        for gl_i= gl_x1 to gl_x2 step 1
            x = gl_i
            y = gl_y1
            gosub setdot
                y = gl_y2
            gosub setdot
        next gl_i
    
        for gl_i= gl_y1 to gl_y2 step 1
            y = gl_i
            x = gl_x1
            gosub setdot
            x = gl_x2
            gosub setdot
        next gl_i
    
    return
    
    chk_xy:
        if gl_x1 > gl_x2 then
            swap gl_x1,gl_x2
            endif
        if gl_y1 > gl_y2 then
            swap gl_y1,gl_y2
            endif
    return
    
    
    
    '*******************************************************************************
    '           Text
    '*******************************************************************************
    stringout2:        
    lcdy = row
    Readcode addr, char : 
    If char = 0 then return 
    
    gosub putclcdtext : 
    addr = addr + 1 : 
    lcdx = lcdx + 1 : 
    
    lcdy = row 
    
    goto stringout2
    
    
    putclcdtext:    
    if char < 20 then return
     if char > $7f then return
     
     for char_row = 0 to 4
         if char < $50 then
            charpos  = (((char & $ff)- $20)*5)
            gosub table1
            
         endif
    
         if char > $4f then
            charpos  = (((char & $ff)- $50)*5)
            gosub table2
          endif 
    
    next char_row
    if big = 0 then      ' Normal 5x7 font
        for j = 0 to 7   ' data bits 0 - 7
                    
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
                       
            for k = 1 to 5
        
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next k
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        
        next j 
        lcdx = lcdx + 6
        
    
    elseif big = 1 then      ' big 10x14 font
        for j = 0 to 7   ' data bits 0 - 7
        for n = 0 to 1
                     
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
        
            for k = 1 to 5
            for m = 0 to 1    
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next m
            next k
            
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        next n
        next j 
        lcdx = lcdx + 10       '20X24
    elseif big = 2   then
        for j = 0 to 7   ' data bits 0 - 7
        for n = 0 to 3
                     
                    cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat  ' RAM Addsress counter set X
                    cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat  ' RAM Addsress counter set Y    
        
        
            for k = 1 to 5
            for m = 0 to 3    
                    dat = fcolor
                    temp = chardata[k]
                    if temp.0[j] = 0 then 
                        dat = bcolor
                    endif
                    cmd = $0022 : gosub lcd_write_CMD 
                    gosub lcd_write_dat
            next m
            next k
            
            dat = bcolor
            gosub lcd_write_dat
            lcdy = lcdy + 1
        next n
        next j 
        lcdx = lcdx + 24
    
    endif
    return
    
    '=================
    'FONT SAMPLE 5x7
    '=================
    
    Table1:
    lu1 = charpos + char_row
    
    lookup lu1, [0,0,0,0,0,_             'space
                $00,$00,$5f,$00,$00,_    '// 21 !
                $00,$07,$00,$07,$00,_    ' 22 "
                $14,$7f,$14,$7f,$14,_     ' 23 #
                $24,$2a,$7f,$2a,$12,_     ' 24 $
                $23,$13,$08,$64,$62,_    '  25%
                $36,$49,$55,$22,$50,_     ' 26 &
                $00,$05,$03,$00,$00,_     ' 27 '
                $00,$1c,$22,$41,$00,_     ' 28 (
                $00,$41,$22,$1c,$00,_     ' 29 )
                $14,$08,$3e,$08,$14,_     ' 2a *
                $08,$08,$3e,$08,$08,_     ' 2b +
                $00,$50,$30,$00,$00,_     ' 2c ,
                $08,$08,$08,$08,$08,_     ' 2d -
                $00,$60,$60,$00,$00,_     ' 2e .
                $20,$10,$08,$04,$02,_     ' 2f /
                $3e,$51,$49,$45,$3e,_     ' 30 0
                $00,$42,$7f,$40,$00,_     ' 31 1
                $42,$61,$51,$49,$46,_    ' 32 2
                $21,$41,$45,$4b,$31,_    ' 33 3
                $18,$14,$12,$7f,$10,_    ' 34 4
                $27,$45,$45,$45,$39,_    ' 35 5
                $3c,$4a,$49,$49,$30,_    ' 36 6
                $01,$71,$09,$05,$03,_    ' 37 7
                $36,$49,$49,$49,$36,_    ' 38 8
                $06,$49,$49,$29,$1e,_    '// 39 9
                $00,$36,$36,$00,$00,_    '// 3a :
                $00,$56,$36,$00,$00,_    '// 3b ;
                $08,$14,$22,$41,$00,_    '// 3c <
                $14,$14,$14,$14,$14,_    '// 3d =
                $00,$41,$22,$14,$08,_    '// 3e >
                $02,$01,$51,$09,$06,_    '// 3f ?
                $32,$49,$79,$41,$3e,_    '// 40 @
                $7e,$11,$11,$11,$7e,_    '// 41 A
                $7f,$49,$49,$49,$36,_    '// 42 B
                $3e,$41,$41,$41,$22,_    '// 43 C
                $7f,$41,$41,$22,$1c,_    '// 44 D
                $7f,$49,$49,$49,$41,_    '// 45 E
                $7f,$09,$09,$09,$01,_    '// 46 F
                $3e,$41,$49,$49,$7a,_    ''// 47 G
                $7f,$08,$08,$08,$7f,_    '// 48 H
                $00,$41,$7f,$41,$00,_    '// 49 I
                $20,$40,$41,$3f,$01,_    '// 4a J
                $7f,$08,$14,$22,$41,_    '// 4b K
                $7f,$40,$40,$40,$40,_    '// 4c L
                $7f,$02,$0c,$02,$7f,_    '// 4d M
                $7f,$04,$08,$10,$7f,_    '// 4e N
                $3e,$41,$41,$41,$3e],temp    '// 4f O
    chardata[char_row + 1] = temp
    
    
    Return
    
    Table2:
    lu1 = charpos + char_row
    
    lookup lu1, [$7f,$09,$09,$09,$06,_    '// 50 P
                $3e,$41,$51,$21,$5e,_    '// 51 Q
                $7f,$09,$19,$29,$46,_    '// 52 R
                $46,$49,$49,$49,$31,_    '// 53 S
                $01,$01,$7f,$01,$01,_    '// 54 T
                $3f,$40,$40,$40,$3f,_    '// 55 U
                $1f,$20,$40,$20,$1f,_    '// 56 V
                $3f,$40,$38,$40,$3f,_    '// 57 W
                $63,$14,$08,$14,$63,_    '// 58 X
                $07,$08,$70,$08,$07,_    '// 59 Y
                $61,$51,$49,$45,$43,_    '// 5a Z
                $00,$7f,$41,$41,$00,_    '// 5b [
                $02,$04,$08,$10,$20,_    '// 5c
                $00,$41,$41,$7f,$00,_    '// 5d
                $04,$02,$01,$02,$04,_    '// 5e
                $40,$40,$40,$40,$40,_    '// 5f
                $00,$01,$02,$04,$00,_    '// 60
                $20,$54,$54,$54,$78,_    '// 61 a
                $7f,$48,$44,$44,$38,_    '// 62 b
                $38,$44,$44,$44,$20,_    '// 63 c
                $38,$44,$44,$48,$7f,_    '// 64 d
                $38,$54,$54,$54,$18,_    '// 65 e
                $08,$7e,$09,$01,$02,_    '// 66 f
                $0c,$52,$52,$52,$3e,_    '// 67 g
                $7f,$08,$04,$04,$78,_    '// 68 h
                $00,$44,$7d,$40,$00,_    '// 69 i
                $20,$40,$44,$3d,$00,_    '// 6a j 
                $7f,$10,$28,$44,$00,_    '// 6b k
                $00,$41,$7f,$40,$00,_    '// 6c l
                $7c,$04,$18,$04,$78,_    '// 6d m
                $7c,$08,$04,$04,$78,_    '// 6e n
                $38,$44,$44,$44,$38,_    '// 6f o
                $7c,$14,$14,$14,$08,_    '// 70 p
                $08,$14,$14,$18,$7c,_    '// 71 q
                $7c,$08,$04,$04,$08,_    '// 72 r
                $48,$54,$54,$54,$20,_    '// 73 s
                $04,$3f,$44,$40,$20,_    '// 74 t
                $3c,$40,$40,$20,$7c,_    '// 75 u
                $1c,$20,$40,$20,$1c,_    '// 76 v
                $3c,$40,$30,$40,$3c,_    '// 77 w
                $44,$28,$10,$28,$44,_    '// 78 x
                $0c,$50,$50,$50,$3c,_    '// 79 y
                $44,$64,$54,$4c,$44,_    '// 7a z
                $00,$08,$36,$41,$00,_    '// 7b
                $00,$00,$7f,$00,$00,_    '// 7c
                $00,$41,$36,$08,$00,_    '// 7d
                $10,$08,$08,$10,$08,_    '// 7e
                $78,$46,$41,$46,$78], temp '    // 7f
    chardata[char_row + 1] = temp
    
    
    Return  
    '******************************************************************************
    
    Print_Number:    ' need lcd_x , lcd_y , number, len, 
         temp5 = lcdy
       for i = len to 0 step -1
       char = number dig i  + 48
       gosub putclcdtext
       lcdy = temp5
        next i
    
    return
    '*******************************************************************************
    
    ProgramStart: 
     gosub lcd_init
     gosub lcd_home
     gosub clr_disp
    
    bcolor = white
    fcolor = black
    @ printstr2 25,20, "SSD2119 Controller"
    @ printstr2 25,28, "Dave Cutliff "
    @ printstr2 25,36, "TFT Color LCD Model Rev 1.0"
    @ printstr2 25,44, "320xRGBx240"
    @ printstr2 25,60, "PicBasic Pro6.0 "
    @ printstr2 25,68, "Sept 8,2010"
    'gosub ts_init
    pause 2000
    gosub lcd_home
    gosub clr_disp
    Gosub FSInit
         
    @ printstr2 25,20, "INT: "
               
            lcdx = 50
            lcdy = 20
            len = 1
            number = FAT_error 
            gosub print_number    
                
             lcdx = 80
            lcdy = 20
            len = 2
            number = SDC_status 
            gosub print_number           
    
             lcdx = 120
            lcdy = 20
            len = 2
            number =  SDC_response 
            gosub print_number           
          
        
    If (FAT_error != 0) Then Stop
    
         'Display card directory
            lcdx = 50
            row = 70
        filenum = 1
    Gosub FINDfirst        ' Find first file on card
        While (FAT_error = 0)
           ' number of char = 11
            for b = 0 to 10
     
                
                select case filenum
                    case 1
                         for c = 0 to 10
                         file1[c] =  FAT_FileName[c]
                         next c
                    case 2
                         for c = 0 to 10
                         file2[c] =  FAT_FileName[c]
                         next c        
                    case 3
                         for c = 0 to 10
                         file3[c] =  FAT_FileName[c]
                         next c        
                    case 4
                         for c = 0 to 10
                         file4[c] =  FAT_FileName[c]
                         next c        
                    
                    case 5
                         for c = 0 to 10
                         file5[c] =  FAT_FileName[c]
                         next c        
                end select
                
            next b
                         lcdx = 50
                         for c = 0 to 10
                         char = FAT_FileName[c]
                         lcdy = row
                         gosub putclcdtext
                         next c
                         lcdy = row
    
                         
              Gosub FINDnext    ' Find next file on card
    
             filenum = filenum + 1
             row = row + 10
        Wend
        filenum = filenum - 1      'number of file on card
    
    pause 2000
    ImageLoop:
    for p = 1 to filenum   
         select case p
                    case 1
                         for c = 0 to 10
                         FAT_FileName[c] = file1[c]  
                         next c
                    case 2
                         for c = 0 to 10
                         FAT_FileName[c] = file2[c]
                         next c        
                    case 3
                         for c = 0 to 10
                         FAT_FileName[c] = file3[c]
                         next c         
                    case 4
                         for c = 0 to 10
                         FAT_FileName[c] = file4[c]
                         next c        
                    
                    case 5
                         for c = 0 to 10
                         FAT_FileName[c] = file5[c]
                         next c      
          end select
        
        ' Open a file for read
        FAT_mode = "r"        ' Read mode
        Gosub FSfopen        ' Open file pointed to by Byte array FAT_FileName
        
        If (FAT_error != 0) Then Stop
    
    
        ' Read and display the whole file
        FAT_count = 512    ' Read 512 byte to buffer at a time
        gosub clr_disp
        gosub  lcd_home
        lcdx = 0
        lcdy = 0
        x = 0
        cnt = 0
        rgb = 0
        first = 0
        gl_x = 0
        gl_y = 240
    
        Gosub FSfread
       if first = 0 then
          cnt = fat_dest[$0A]         'read where data starts
          first = 1
       else
           cnt = 0
       endif
       
    While (FAT_error = 0)
        While cnt < 512
              
                 
    
                    tmp_color = 0
                    tmp1_color = 0
                    select case rgb
                    case 0 
                     tmp_color = fat_dest[cnt]>>3
                     dat = tmp_color
                     k =k + 1
                    case 1
                     tmp_color = fat_dest[cnt]>>2
                     tmp1_color = tmp_color<< 5
                     dat = dat + tmp1_color
                     k =k + 1
                    case 2 
                     tmp_color = fat_dest[cnt]>>3
                     tmp1_color = tmp_color<< 11
                     color = dat + tmp1_color
                     
            
                    end select 
                    cnt = cnt + 1 
                    rgb = rgb + 1
                 if rgb = 3 then
                     y =  gl_y
                     gosub setdot
                     color = 0
                     x = x + 1
                     rgb = 0
                     if x >= 320 then
                         x = 0
                         gl_y = gl_y - 1
                     endif
                 endif
              wend 
    
            FAT_count = 512    ' Read 512 byte to buffer at a time
            cnt = 0
            Gosub FSfread
    Wend
            pause 5000
            pause 5000
    next p
    goto imageloop
    
    
    
    Loop1:
    ' gosub DoUSBIn
    '  gosub DoUSBOut
    goto loop1
    This article was originally published in forum thread: 3.5" Color LCD code example started by DaveC3 View original post