3.5" Color LCD code example


Closed Thread
Results 1 to 40 of 45

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    That is really cool, way beyond my ability.

    Thanks for sharing

  2. #2
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default 3.5" tft

    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

  3. #3
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

  4. #4
    Join Date
    Oct 2010
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    Thanks for sharing your code.
    The only thing that's not clear to me how do you have the PS3,PS2,PS1,PS1 jumper on the back of the board.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Edje11 View Post
    Hi Dave,

    Thanks for sharing your code.
    The only thing that's not clear to me how do you have the PS3,PS2,PS1,PS1 jumper on the back of the board.
    Hello,

    See post number 9 in this thread. Dave's program uses the 8bit mode. Solder jumpers PS2
    and PS3, remove solder from PS0 and PS1.

    I received my display Monday. It came with PS0, PS2 and PS3 soldered, which is the 16bit mode.

    With out a data sheet its a bit confusing at first. Unsoldered = 1 and soldered = 0, its because they use pull-up resistors.

    Mark

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark_s View Post

    With out a data sheet its a bit confusing at first. Unsoldered = 1 and soldered = 0, its because they use pull-up resistors.

    Mark
    Here it goes. This is the datasheet for the SSD2119 controller, which is what this display uses. The right PS combination is on page 28.

    http://www.crystalfontz.com/controllers/SSD2119.pdf
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    Here it goes. This is the datasheet for the SSD2119 controller, which is what this display uses. The right PS combination is on page 28.

    http://www.crystalfontz.com/controllers/SSD2119.pdf
    Thanks Robert,

    I have the controller data sheet, I ment data for the development board. It does not come with any schematics or info. But the pcb is clearly silk screened. It has a lot of features for the money. DC to DC converter for vlcd, touch screen controller, SD card socket, pads for eeprom expansion. The best part, is you don't have to deal with the 0.5mm FFC cable connections.

    @Dave,

    Have not fired it up yet, need to change my pcb to 3.3v. Will report back when I get it
    going with an interesting app.

    Thanks

  8. #8
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Also be sure you make the chip select for the touch screen controller high. If you leave it floating the SD card reader may not work (hard lesson learned ;-)

    If you guys make something cool be sure to show us.

    Take care

    Dave

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts