Using the tjctm24024-spi display

Hello,

I bought a 2.4" tjctm24024-spi display and I am having a little bit of trouble with it.

The TFT example from the Arduino does not work and when I try to compile the Adafruit libraries I get various errors. I don’t know why because I have not touched them.

I am using a 3.3V arduino pro mini 328 at the moment.

I found a demo code here:
http://www.elecfreaks.com/store/24-tft-lcd-tft0124sp-p-785.html

#include "pins_arduino.h"
#define LCD_CS		2
#define LCD_REST	3
#define LCD_DC		4
#define LCD_MOSI	5
#define LCD_CLK		6


volatile uint8_t *P_SCK,*P_MOSI,*P_DC,*P_RST,*P_CS;
volatile uint8_t B_SCK,B_MOSI,B_DC,B_RST,B_CS;



#define LCD_W	240
#define LCD_H	320
//color define
#define WHITE         	 0xFFFF
#define BLACK         	 0x0000	  
#define BLUE         	 0x001F  
#define BRED             0XF81F
#define GRED 			 0XFFE0
#define GBLUE			 0X07FF
#define RED           	 0xF800
#define MAGENTA       	 0xF81F
#define GREEN         	 0x07E0
#define CYAN          	 0x7FFF
#define YELLOW        	 0xFFE0
#define BROWN 			 0XBC40 
#define BRRED 			 0XFC07 
#define GRAY  			 0X8430 



void LCD_Write_Bus(char dat)
{
  *P_CS &= ~B_CS;
  for(uint8_t i=0;i<8;i++)
  {
    if(dat&0x80)
      *P_MOSI |= B_MOSI;
    else
      *P_MOSI &= ~B_MOSI;
    dat <<= 1;
    *P_SCK &= ~B_SCK;
    asm("nop");
    *P_SCK |= B_SCK;
  }
  *P_CS |= B_CS;
}

void LCD_WR_DATA8(char dat)
{
	digitalWrite(LCD_DC,HIGH);
	LCD_Write_Bus(dat);
}
void LCD_WR_DATA(int dat)
{
	digitalWrite(LCD_DC,HIGH);
	LCD_Write_Bus(dat>>8);
	LCD_Write_Bus(dat);
}
void LCD_WR_REG(char dat)
{
	digitalWrite(LCD_DC,LOW);
	LCD_Write_Bus(dat);
}
void LCD_WR_REG_DATA(int reg,int dat)
{
	LCD_WR_REG(reg);
	LCD_WR_DATA(dat);
}
void Address_set(unsigned int x1,unsigned y1,unsigned int x2,unsigned int y2)
{
	LCD_WR_REG(0x2a);
   	LCD_WR_DATA8(x1>>8);
   	LCD_WR_DATA8(x1);
   	LCD_WR_DATA8(x2>>8);
   	LCD_WR_DATA8(x2);
  
   	LCD_WR_REG(0x2b);
   	LCD_WR_DATA8(y1>>8);
   	LCD_WR_DATA8(y1);
   	LCD_WR_DATA8(y2>>8);
   	LCD_WR_DATA8(y2);

   	LCD_WR_REG(0x2C);
}
void LCD_Init(void)
{
        P_SCK	= portOutputRegister(digitalPinToPort(LCD_CLK));
        B_SCK	= digitalPinToBitMask(LCD_CLK);
	P_MOSI	= portOutputRegister(digitalPinToPort(LCD_MOSI));
	B_MOSI	= digitalPinToBitMask(LCD_MOSI);
	P_DC	= portOutputRegister(digitalPinToPort(LCD_DC));
	B_DC	= digitalPinToBitMask(LCD_DC);
	P_RST	= portOutputRegister(digitalPinToPort(LCD_REST));
	B_RST	= digitalPinToBitMask(LCD_REST);
	P_CS	= portOutputRegister(digitalPinToPort(LCD_CS));
	B_CS	= digitalPinToBitMask(LCD_CS);
        *P_RST &= ~B_RST;
	delay(20);
        *P_RST |= B_RST;

 	LCD_WR_REG(0xCB);  
      LCD_WR_DATA8(0x39); 
      LCD_WR_DATA8(0x2C); 
      LCD_WR_DATA8(0x00); 
      LCD_WR_DATA8(0x34); 
      LCD_WR_DATA8(0x02); 
  
      LCD_WR_REG(0xCF);  
      LCD_WR_DATA8(0x00); 
      LCD_WR_DATA8(0XC1); 
      LCD_WR_DATA8(0X30); 
   	
  	LCD_WR_REG(0xE8);  
      LCD_WR_DATA8(0x85); 
      LCD_WR_DATA8(0x00); 
      LCD_WR_DATA8(0x78); 
   	
  	LCD_WR_REG(0xEA);  
      LCD_WR_DATA8(0x00); 
      LCD_WR_DATA8(0x00); 
   	
  	LCD_WR_REG(0xED);  
      LCD_WR_DATA8(0x64); 
      LCD_WR_DATA8(0x03); 
      LCD_WR_DATA8(0X12); 
      LCD_WR_DATA8(0X81); 
  
      LCD_WR_REG(0xF7);  
      LCD_WR_DATA8(0x20); 
     
      LCD_WR_REG(0xC0);    //Power control 
      LCD_WR_DATA8(0x23);   //VRH[5:0] 
     
      LCD_WR_REG(0xC1);    //Power control 
      LCD_WR_DATA8(0x10);   //SAP[2:0];BT[3:0] 
   
      LCD_WR_REG(0xC5);    //VCM control 
      LCD_WR_DATA8(0x3e); 
      LCD_WR_DATA8(0x28); 
   
      LCD_WR_REG(0xC7);    //VCM control2 
      LCD_WR_DATA8(0x86);  //--
   
      LCD_WR_REG(0x36);    // Memory Access Control 
      LCD_WR_DATA8(0x48); //	   
  
      LCD_WR_REG(0x3A);    
      LCD_WR_DATA8(0x55); 
  
      LCD_WR_REG(0xB1);    
      LCD_WR_DATA8(0x00);  
      LCD_WR_DATA8(0x18); 
 
    LCD_WR_REG(0xB6);    // Display Function Control 
    LCD_WR_DATA8(0x08); 
    LCD_WR_DATA8(0x82);
    LCD_WR_DATA8(0x27);  
 	
	LCD_WR_REG(0xF2);    // 3Gamma Function Disable 
    LCD_WR_DATA8(0x00); 
 	
	LCD_WR_REG(0x26);    //Gamma curve selected 
    LCD_WR_DATA8(0x01); 
 
 	LCD_WR_REG(0xE0);    //Set Gamma 
    LCD_WR_DATA8(0x0F); 
    LCD_WR_DATA8(0x31); 
    LCD_WR_DATA8(0x2B); 
    LCD_WR_DATA8(0x0C); 
    LCD_WR_DATA8(0x0E); 
    LCD_WR_DATA8(0x08); 
    LCD_WR_DATA8(0x4E); 
    LCD_WR_DATA8(0xF1); 
    LCD_WR_DATA8(0x37); 
    LCD_WR_DATA8(0x07); 
    LCD_WR_DATA8(0x10); 
    LCD_WR_DATA8(0x03); 
    LCD_WR_DATA8(0x0E); 
    LCD_WR_DATA8(0x09); 
    LCD_WR_DATA8(0x00); 

    LCD_WR_REG(0XE1);    //Set Gamma 
    LCD_WR_DATA8(0x00); 
    LCD_WR_DATA8(0x0E); 
    LCD_WR_DATA8(0x14); 
    LCD_WR_DATA8(0x03); 
    LCD_WR_DATA8(0x11); 
    LCD_WR_DATA8(0x07); 
    LCD_WR_DATA8(0x31); 
    LCD_WR_DATA8(0xC1); 
    LCD_WR_DATA8(0x48); 
    LCD_WR_DATA8(0x08); 
    LCD_WR_DATA8(0x0F); 
    LCD_WR_DATA8(0x0C); 
    LCD_WR_DATA8(0x31); 
    LCD_WR_DATA8(0x36); 
    LCD_WR_DATA8(0x0F); 
 
	LCD_WR_REG(0x2A);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0xEF);
  
    LCD_WR_REG(0x2B);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x01);
    LCD_WR_DATA8(0x3F);
    LCD_WR_REG(0x11);    //Exit Sleep 
    delay(120); 
			
    LCD_WR_REG(0x29);    //Display on 
    LCD_WR_REG(0x2c); 
}
void LCD_Clear(unsigned int color)
{
	unsigned int i,j;  	
	Address_set(0,0,LCD_W-1,LCD_H-1);
    for(i=0;i<LCD_W;i++)
 	{
    	for (j=0;j<LCD_H;j++)
	   	{
        	LCD_WR_DATA(color);	 			 
	    }
	}
}

void setup()
{
  unsigned char p;
  for(p=0;p<14;p++)
    pinMode(p,OUTPUT);

  LCD_Init();
}

void loop()
{
    LCD_Clear(RED);
  delay(1000);
  LCD_Clear(BLUE);
  delay(1000);
  LCD_Clear(GREEN);
  delay(1000);
}

It works great. I want to add text to it and I would like some advice on the things I have to do. In the end I would like to be able to write text of various size and color and use the SD card. The touch function would be a nice bonus.

I don’t understand what they mean on the page when they say "TFT01_2.4 SP is a 2.4 “SPI TFT LCD Screen Module, 10pins interface, compatible LCD5110 interface.” I used the 5110 display and managed to make it work with libraries and without libraries.

I assume that first I would have to do is add the ASCII characters. Something like this:

static const byte ASCII[][5] =
{
{
    0x7e, 0x11, 0x11, 0x11, 0x7e                            } // 41 A
  ,{
    0x7f, 0x49, 0x49, 0x49, 0x36                            } // 42 B
  ,{
    0x3e, 0x41, 0x41, 0x41, 0x22                            } // 43 C
}