SSD1289 GLCD Support

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
skartalov
Posts: 37
Joined: Fri Apr 09, 2010 10:50 am
Location: BULGARIA

SSD1289 GLCD Support

Post by skartalov » Thu Mar 07, 2013 8:43 am

Come on guys, there are so cheap TFT's on the market, for example this one,
available for $14 with touch screen and SD card socket!

http://www.ebay.co.uk/itm/3-2-TFT-LCD-M ... 51a340b1fa

It uses SSD1289 controller.
There is a demo written in c+, but I started to convert it for use with SF.

There are some things I cannot understand in C+, please help me out to make it work and I will post the final code here (after testing).

This is the example code in C+:

Code: Select all


extern sfr char  TFT_DP_Lo;
extern sfr char TFT_DP_Hi;
extern sfr sbit TFT_WR;
extern sfr sbit TFT_RD;
extern sfr sbit TFT_CS;
extern sfr sbit TFT_RS;
extern sfr sbit TFT_RST;


extern sfr char  TFT_DP_Lo_Direction;
extern sfr char  TFT_DP_Hi_Direction;
extern sfr  TFT_WR_Direction;
extern sfr  TFT_RD_Direction;
extern sfr  TFT_CS_Direction;
extern sfr  TFT_RS_Direction;
extern sfr  TFT_RST_Direction;


const unsigned int Black = 0;
const unsigned int Red = 63488;
const unsigned int Green = 2016;
const unsigned int Blue = 31;
const unsigned int White = 65535;
const unsigned int Purple = 61727;
const unsigned int Yellow = 65504;
const unsigned int Cyan = 2047;
const unsigned int d_gray = 21130;
const unsigned int l_gray = 31727;


const char FONT_8x8[784] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // ' (forward slash)
0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p 0x70
0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00, // DEL
0x60,0x90,0x90,0x60,0x00,0x00,0x00,0x00,  // DEGREE use:€
0x22,0x77,0x7f,0x7f,0x3e,0x1c,0x08,0x00         //HEART use:

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Thu Mar 07, 2013 10:10 am

In addition to standard data types like bytes and words, C has a 'pointer' data type.
Pointers hold the address of some other data type, and can be used to indirectly access the thing pointed to.
That's what the '*' operator is used for... to declare pointers and to do indirect access.

Swordfish doesn't have a native pointer type, but there are ways around this.

- You can normally change 'char *' declarations to a string ie 'char *s' becomes 's as string'

- If the pointer is used as a parameter in a subroutine call, then you can usually change the declaration of the
sub to use 'byref' instead of the normal 'byval' for that parameter, get rid of the '*', and you're done.

- Another trick is to use the PIC hardware TABLEPTR and/or FSR registers to do the access, but this is pretty
low-level and requires a good knowledge of what's going on, what's being pointed at, and how the PIC uses these
special registers.


In the code shown, I see two uses of '*'

Code: Select all

Sub TFT_Text(unsigned Char* S,unsigned int x,unsigned int y,Char DimFont,unsigned int Fcolor,unsigned int Bcolor)
This one's pretty simple... change 'unsigned Char* S' to 'S as string' and you're done.


The other is in Sub TFT_Char(), and that one's a little trickier.
First off, you're going to want to change the global 'FONT_8x8' and 'FONT_16x16' array names to make it easier to see
what's going on.


Change
Const Char FONT_8x8[784] = (
Const Char FONT_16x16[3040] = (

to
const _FONT_8x8(784) as byte =
const _FONT_16x16(3040) as byte =

In the TFT_Char sub you can get rid of the use of the pointer entirely. It's not the most efficient way, but it's the simplest.

Code: Select all

Sub TFT_Char(C As Char,x,y As Integer,DimFont As Char,Fcolor,Bcolor As Integer)

dim font_ix as word		// replaces 'Const Char *PtrFont'

If (DimFont = 8) Then

     font_ix = (C-32)*8

     For k = 0 To 7
      font8x8[k] = _FONT_8x8(font_ix)
      Inc(font_ix)
     Next

	<SNIP>
	
Elseif (DimFont = 16)
     font_ix = (C-32)*8

     For k = 0 To 15
      font16x16[k] = _FONT_16x16(font_ix)
      Inc(font_ix)
      font16x16[k] = (font16x16[k] << 8)
      font16x16[k] = font16x16[k] + _FONT_16x16(font_ix)
      Inc(font_ix)
     Next

	<SNIP>

Post Reply