Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TFT LCD controller library

Status
Not open for further replies.

rezaf

Advanced Member level 4
Joined
Apr 11, 2009
Messages
106
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Montagram
Activity points
2,147
Hi,

I have an 2.4" TFT LCD Module with touch screen that I think the LCD's controller chip is S6D1121. I want to connect it to my At91SAM7X board but can't find any library for it. can you help me to find right header and library for it (most of libraries in the web are for arduino, firewire or are UTFT-base or other structures)?

Thanks.
 

You can not hope every chip have unique library just fit your controller.
Generally, you need make some modification based on current library to fit your needs.
It is not very complicated, I suppose.
 
this links has Modules that is similar to my module (the only thing that differ is this that the serial number in back of my LCD ends with 101014-HLY-B-1121 and don't end with S6D1121):


**broken link removed**

**broken link removed**

https://detail.1688.com/offer/1213777089.html

$(KGrHqRHJEMFHjHh7DQuBS!b!OuHI!~~60_57.JPG


I can't really understand why this similar modules has multiple controller chips.
I written this header with helping of arduino header but not work yet and I don't know really what is the controller of my LCD module.

Code:
#include <Headers\AT91SAM7X256.H> 
#include <Headers\delay.h>

/**********************************************
Define zone
**********************************************/
#define S6DLCD_DATAPORT_B             
#define S6DLCD_DATAPORT_OFFSET      2
#define S6DLCD_CONTROLPORT_B          
#define S6DLCD_RST                  18
#define S6DLCD_RS                   19
#define S6DLCD_CS                   20
#define S6DLCD_WR                   21
#define S6DLCD_RD                   22  

	#define _S6DLCD_DATAPORT_ID_	        AT91C_ID_PIOB
	#define _S6DLCD_DATAPORT_PER_	       *AT91C_PIOB_PER
	#define _S6DLCD_DATAPORT_PDR_	       *AT91C_PIOB_PDR
	#define _S6DLCD_DATAPORT_OER_	       *AT91C_PIOB_OER
	#define _S6DLCD_DATAPORT_ODR_	       *AT91C_PIOB_ODR
	#define _S6DLCD_DATAPORT_PUER_	   	 *AT91C_PIOB_PPUER
	#define _S6DLCD_DATAPORT_PUDR_	     *AT91C_PIOB_PPUDR
	#define _S6DLCD_DATAPORT_PDSR_	     *AT91C_PIOB_PDSR
	#define _S6DLCD_DATAPORT_SODR_	     *AT91C_PIOB_SODR
	#define _S6DLCD_DATAPORT_CODR_	     *AT91C_PIOB_CODR
	#define _S6DLCD_DATAPORT_PCER_       *AT91C_PMC_PCER
	#define _S6DLCD_DATAPORT_PCDR_       *AT91C_PMC_PCDR

	#define _S6DLCD_CONTROLPORT_ID_	       AT91C_ID_PIOB
	#define _S6DLCD_CONTROLPORT_PER_	   *AT91C_PIOB_PER
	#define _S6DLCD_CONTROLPORT_PDR_	   *AT91C_PIOB_PDR
	#define _S6DLCD_CONTROLPORT_OER_	   *AT91C_PIOB_OER
	#define _S6DLCD_CONTROLPORT_ODR_	   *AT91C_PIOB_ODR
	#define _S6DLCD_CONTROLPORT_PUER_	   *AT91C_PIOB_PPUER
	#define _S6DLCD_CONTROLPORT_PUDR_	   *AT91C_PIOB_PPUDR
	#define _S6DLCD_CONTROLPORT_SODR_	   *AT91C_PIOB_SODR
	#define _S6DLCD_CONTROLPORT_CODR_	   *AT91C_PIOB_CODR

#define S6DLCD_RST_LOW                 _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RST)
#define S6DLCD_RST_HIGH                _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RST)
#define S6DLCD_RS_LOW                  _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RS)
#define S6DLCD_RS_HIGH                 _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RS)
#define S6DLCD_CS_LOW                  _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_CS)
#define S6DLCD_CS_HIGH                 _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_CS)			
#define S6DLCD_RD_LOW                  _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RD)
#define S6DLCD_RD_HIGH                 _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RD)
#define S6DLCD_WR_LOW                  _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_WR)
#define S6DLCD_WR_HIGH                 _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_WR)    
#define S6DLCD_DATAPORT_INPUT		       _S6DLCD_DATAPORT_ODR_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET),_S6DLCD_DATAPORT_PER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)	   
#define S6DLCD_DATAPORT_INPUT_CLK_E		 _S6DLCD_DATAPORT_PCER_ = (1 << _S6DLCD_DATAPORT_ID_)
#define S6DLCD_DATAPORT_INPUT_CLK_D		 _S6DLCD_DATAPORT_PCDR_ = (1 << _S6DLCD_DATAPORT_ID_)
#define S6DLCD_DATAPORT_OUTPUT         _S6DLCD_DATAPORT_OER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)                      
#define S6DLCD_DATAPORT_CLEAR          _S6DLCD_DATAPORT_CODR_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)

#define HIGH 1
#define LOW  0

#define X_CONST   240
#define Y_CONST   320
#define PREC_TOUCH_CONST 10
#define PixSizeX  13.78
#define PixOffsX  411
#define PixSizeY  11.01
#define PixOffsY  378

#define WINDOW_XADDR_START   0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END     0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START   0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END     0x0053 // Vertical End Address Set
#define GRAM_XADDR           0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR           0x0021 // GRAM Vertical Address Set
#define GRAMWR               0x0022 // memory write

/* LCD color */
#define S6DLCD_White    0xFFFF
#define S6DLCD_Black    0x0000
#define S6DLCD_Blue     0x001F
#define S6DLCD_Blue2    0x051F
#define S6DLCD_Red      0xF800
#define S6DLCD_Magenta  0xF81F
#define S6DLCD_Green    0x07E0
#define S6DLCD_Cyan     0x7FFF
#define S6DLCD_Yellow   0xFFE0

/**********************************************
Val Zone
**********************************************/
int TP_X,TP_Y;
/**********************************************
Standard C functions zone
**********************************************/
void Write_Command(unsigned int c)
{
	S6DLCD_RS_LOW;               //LCD_RS=0;
	S6DLCD_CS_LOW;               //LCD_CS =0;!
	S6DLCD_DATAPORT_OUTPUT;
	S6DLCD_DATAPORT_CLEAR;
	_S6DLCD_DATAPORT_SODR_ = ((c>>8) << S6DLCD_DATAPORT_OFFSET);  //LCD_DataPortH=DH>>8;
	S6DLCD_WR_LOW;              //LCD_WR=0;

	S6DLCD_WR_HIGH;             //LCD_WR=1;!
	S6DLCD_DATAPORT_CLEAR;
	_S6DLCD_DATAPORT_SODR_ = ((c) << S6DLCD_DATAPORT_OFFSET);   //LCD_DataPortH=DH;
	S6DLCD_WR_LOW;             //LCD_WR=0;
	S6DLCD_WR_HIGH;            //LCD_WR=1;
	S6DLCD_CS_HIGH ;            //LCD_CS =0;
}
void Write_Data(unsigned int c)
{
	S6DLCD_RS_HIGH;             //LCD_RS=0;
	S6DLCD_CS_LOW;              //LCD_CS =0;!
	S6DLCD_DATAPORT_OUTPUT;
	S6DLCD_DATAPORT_CLEAR;
	_S6DLCD_DATAPORT_SODR_ = ((c>>8) << S6DLCD_DATAPORT_OFFSET);  //LCD_DataPortH=DH>>8;
	S6DLCD_WR_LOW;              //LCD_WR=0;
	S6DLCD_WR_HIGH;              //LCD_WR=1;!
	S6DLCD_DATAPORT_CLEAR;
	_S6DLCD_DATAPORT_SODR_ = ((c) << S6DLCD_DATAPORT_OFFSET);   //LCD_DataPortH=DH;
	S6DLCD_WR_LOW;              //LCD_WR=0;
	S6DLCD_WR_HIGH;             //LCD_WR=1;
	S6DLCD_CS_HIGH;              //LCD_CS =0;
}
void Write_Command_Data(unsigned int cmd,unsigned int dat)
{
	Write_Command(cmd);
	Write_Data(dat);
}
void Lcd_Init()
{
	S6DLCD_DATAPORT_INPUT_CLK_E;
	_S6DLCD_DATAPORT_PER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
	_S6DLCD_DATAPORT_OER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
	_S6DLCD_DATAPORT_PUER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
	_S6DLCD_CONTROLPORT_PER_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
	_S6DLCD_CONTROLPORT_OER_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
	_S6DLCD_CONTROLPORT_PUDR_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
	_S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RST) | (1 << S6DLCD_CS) | (1 << S6DLCD_RD); 
	_S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_WR);

  S6DLCD_RST_HIGH;
  delay_ms(500);
  S6DLCD_RST_LOW;
  delay_ms(500);

  S6DLCD_RST_HIGH;
	S6DLCD_CS_HIGH;
	S6DLCD_WR_HIGH;
  delay_ms(1000);
 
	 Write_Command_Data(0x0011,0x2004);
	 Write_Command_Data(0x0013,0xCC00);
	 Write_Command_Data(0x0015,0x2600);
	 Write_Command_Data(0x0014,0x252A);
	// Write_Command_Data(0x14,0x002A);
	 Write_Command_Data(0x0012,0x0033);
	 Write_Command_Data(0x0013,0xCC04);
	 //delayms(1);
	 Write_Command_Data(0x0013,0xCC06);
	 //delayms(1);
	 Write_Command_Data(0x0013,0xCC4F);
	 //delayms(1);
	 Write_Command_Data(0x0013,0x674F);
	 Write_Command_Data(0x0011,0x2003);
	 //delayms(1);
	 Write_Command_Data(0x0030,0x2609);
	 Write_Command_Data(0x0031,0x242C);
	 Write_Command_Data(0x0032,0x1F23);
	 Write_Command_Data(0x0033,0x2425);
	 Write_Command_Data(0x0034,0x2226);
	 Write_Command_Data(0x0035,0x2523);
	 Write_Command_Data(0x0036,0x1C1A);
	 Write_Command_Data(0x0037,0x131D);
	 Write_Command_Data(0x0038,0x0B11);
	 Write_Command_Data(0x0039,0x1210);
	 Write_Command_Data(0x003A,0x1315);
	 Write_Command_Data(0x003B,0x3619);
	 Write_Command_Data(0x003C,0x0D00);
	 Write_Command_Data(0x003D,0x000D);

	 Write_Command_Data(0x0016,0x0007);
	 Write_Command_Data(0x0002,0x0013);
	 Write_Command_Data(0x0003,0x0003);
	 Write_Command_Data(0x0001,0x0127);
	 //delayms(1);
	 Write_Command_Data(0x0008,0x0303);
	 Write_Command_Data(0x000A,0x000B);
	 Write_Command_Data(0x000B,0x0003);
	 Write_Command_Data(0x000C,0x0000);
	 Write_Command_Data(0x0041,0x0000);
	 Write_Command_Data(0x0050,0x0000);
	 Write_Command_Data(0x0060,0x0005);
	 Write_Command_Data(0x0070,0x000B);
	 Write_Command_Data(0x0071,0x0000);
	 Write_Command_Data(0x0078,0x0000);
	 Write_Command_Data(0x007A,0x0000);
	 Write_Command_Data(0x0079,0x0007);
	 Write_Command_Data(0x0007,0x0051);
	 //delayms(1);
	 Write_Command_Data(0x0007,0x0053);
	 Write_Command_Data(0x0079,0x0000);
	 Write_Command_Data(0x0007,0x0051);
   Write_Command(0x0022);
	 delay_ms(500);
}


void SetXY(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
	Write_Command_Data(0x0046,(x1 << 8)| x0);
	//Write_Command_Data(0x0047,x1);
	Write_Command_Data(0x0047,y1);
	Write_Command_Data(0x0048,y0);
	Write_Command_Data(0x0020,x0);
	Write_Command_Data(0x0021,y0);
	Write_Command (0x0022);
	//LCD_WriteCMD(GRAMWR);
}

void Pant(unsigned int color)
{
	 int i,j;

	 SetXY(0,239,0,319);
		
		 for(i=0;i<320;i++)
		 {
			 for (j=0;j<240;j++)
				{
					Write_Data(color);
				}
		 }
	 }

void LCD_clear()
{
		unsigned int i,j;
	
		SetXY(0,239,0,319);
	
		 for(i=0;i<X_CONST;i++)
		 {
		   for(j=0;j<Y_CONST;j++)
			 {
		     Write_Data(0x0000);
			 }
		 }
}
 

I give you a suggestion: do not use any LCD module without any resources, do not kill time on them. It may saved you pennies, but cost your much more time, which I think is valuable.
 

Yes you are right, but this is the only LCD that has my required dimension and resolution (in the markets of my location) and also has a few resources in the web.
 

It is only a 2.4" dimension TFT LCD with resolution 320*240, very common part for mobile phone in early years. It won't be difficult to find substitutes.
 

if you wanna get a tft library , i think it is impossible . you could find the tft register user mannual ,an find out key regester to program and write your own library .
 
  • Like
Reactions: rezaf

    rezaf

    Points: 2
    Helpful Answer Positive Rating
I written the library with usage of libraries in the web but with changing the InitLCD and SetXY and SetPixel functions and the library worked. with this work I found that I can work with every LCD and controller but with a few changes in this 3 functions because other functions only use this 3 functions to work.
 

pleas i need the link that you followed to get library.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top