⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tx06d18_init.c

📁 三星2410芯片的一个DEMO程式
💻 C
字号:
/******************************************************************************
The initial for 320×240 16Bpp TFT LCD----TX06D18
Version:1.0
Date:2003/10/21
Writer:Gong Jun
******************************************************************************/

#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"

#include "TX06D18_Init.h"

#define TX06D18_ID    0

#if (TX06D18_ID == 0)
	#define INDEX_SET		0x70
	#define STATUS_RD		0x71
	#define DATA_WR		0x72
	#define DATA_RD		0x73
#else
	#define INDEX_SET		0x74
	#define STATUS_RD		0x75
	#define DATA_WR		0x76
	#define DATA_RD		0x77
#endif

//LCD RESET		:		GPC0
#define    LCD_RST_H    ( rGPCDAT |= (1) )
#define    LCD_RST_L    ( rGPCDAT &= (~(1)) )

//LCD ID		:		GPG4
#define    LCD_ID_H     ( rGPGDAT |= (1<<4) )
#define    LCD_ID_L     ( rGPGDAT &= (~(1<<4)) )

//LCD CS		:		GPC5
#define    LCD_CS_H     ( rGPCDAT |= (1<<5) )
#define    LCD_CS_L     ( rGPCDAT &= (~(1<<5)) )

//LCD SDI(i)	:		GPC6(o)
#define    LCD_SDI_H    ( rGPCDAT |= (1<<6) )
#define    LCD_SDI_L    ( rGPCDAT &= (~(1<<6)) )

//LCD SCL(i)	:		GPC7(o)
#define    LCD_SCL_H    ( rGPCDAT |= (1<<7) )
#define    LCD_SCL_L    ( rGPCDAT &= (~(1<<7)) )

//LCD SDO(o)	:		GPB10(i)
#define    LCD_SDO      ( rGPBDAT & (1<<10) )

U16 LCD781_My_Tab[]=
{
	0x0100,0x0000,		//power supply setup
	0x0111,0x0000,
	0x0110,0x0100,
	0xFFFF,0x5,			//Delay 100uS	
	0x0111,0x0004,		//VRH,VC
	0x0110,0x0101,
	0xFFFF,0x5,			//Delay 100uS	
 	0x0111,0x023F,		//VDC,VCM
 	0x0110,0x0102,
	0xFFFF,0x5,			//Delay 100uS	
 	0x0111,0x0A00,		//CA
 	0x0110,0x0101,
	0xFFFF,0x5,			//Delay 100uS	
	0x0111,0x19C0,		//GS,NL,SCN
 	0x0110,0x0106,
	0xFFFF,0x5,			//Delay 100uS	
 	0x0111,0x0138,		//NSL
 	0x0110,0x0101,
	0xFFFF,0x5,			//Delay 100uS	
	0x0100,0x0330,		//Power 1
 	0x0111,0x0406,		
 	0x0110,0x0100,		//GON=1
	0xFFFF,0x120,			//Delay 20ms	
 	0x0111,0x0284,		//Power 2
 	0x0110,0x0101,		//PON=1
	0xFFFF,0x120,			//Delay 20ms
 	0x0001,0x0100,		
 	0x0002,0x0700,	
 	0x0003,0x1210,
	0x0007,0x0101,	
 	0x0008,0x0808,	
 	0x000B,0x2000,			
 	0x000C,0x0000,	
 	0x000D,0x0014,
 	0x0012,0x0000,			
 	0x0013,0x0000,	 
 	0x0015,0x0000,
 	0x0200,0x0000,			
 	0x0201,0x0000,
 	0x0203,0x0000,				
 	0x0204,0x0000,
 	0x0210,0x0000,
 	0x0211,0x00EF,
 	0x0212,0x0000,
 	0x0213,0x013f,		//
 	0x0300,0x0100,			
 	0x0301,0x0707,	
 	0x0302,0x0102,
 	0x0303,0x0705,			
 	0x0304,0x0506,	
 	0x0305,0x0000,				
 	0x0306,0x0706,
 	0x0307,0x0507,			
 	0x0308,0x0808,	
 	0x0309,0x0808,				
 	0x0400,0x0027,
	
	0x0111,0x0b00,		//(add by gongjun)
 	0x0110,0x0106,		//(add by gongjun)
	0xFFFF,0x5,			//Delay 100uS(add by gongjun)
 	
 	0x0401,0x0001,
 	0x0402,0x0000,
 	0x0403,0x013f,
 	0x0404,0x0000,	
 	0x0111,0x0C06,
 	0x0110,0x0100,
	0xFFFF,0x5,			//Delay 100uS
  	0x0007,0x0103,	
  	0xFFFF,0x20,			//Delay 1000uS	
 	0x0007,0x0113,		
	0x000C,0x0110,		//(add by gongjun)
  	0xFFFF,0x50,			//Delay 5mS	
	0x0202,0x0000,		//(add by gongjun)
	0x8888,0x8888		//finish !!!
};


/******************************************************************************
set index register
******************************************************************************/
void TX06D18_Index_Reg_Set(U16 d)
{
	U8 m ;
	U8 cmd = INDEX_SET ;
	
	LCD_CS_L ;		//CS = 0
	
	for ( m = 0 ; m < 8 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (cmd&0x80) == 0x80 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		cmd = cmd<<1 ;
	}

	for ( m = 0 ; m < 16 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (d&0x8000) == 0x8000 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		d = d<<1 ;
	}

	LCD_CS_H ;		//CS = 1
}

/******************************************************************************
read status
******************************************************************************/
U16 TX06D18_Status_Read(void)
{
	U8 m ;
	U8 cmd = STATUS_RD ;
	U16 d ;
	
	LCD_CS_L ;		//CS = 0
	
	for ( m = 0 ; m < 8 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (cmd&0x80) == 0x80 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		cmd = cmd<<1 ;
	}

	for ( m = 0 ; m < 8 ; m++ )		//Dummy Read
	{
		LCD_SCL_L ;		//SCL = 0
		Delay(1) ;		//
		LCD_SCL_H ;		//SCL = 1
	}

	for ( m = 0 ; m < 16 ; m++ )
	{
		d = d<<1 ;

		LCD_SCL_L ;		//SCL = 0
		Delay(1) ;		//
		LCD_SCL_H ;		//SCL = 1

		if( LCD_SDO>1 )		d |= 0x0001 ;
		else d &= 0xfffe ;
	}

	LCD_CS_H ;		//CS = 1
	return d ;
}

/******************************************************************************
write instruction or ram data
******************************************************************************/
void TX06D18_Cmd_Data_Write(U16 d)
{
	U8 m ;
	U8 cmd = DATA_WR ;
	
	LCD_CS_L ;		//CS = 0
	
	for ( m = 0 ; m < 8 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (cmd&0x80) == 0x80 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		cmd = cmd<<1 ;
	}

	for ( m = 0 ; m < 16 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (d&0x8000) == 0x8000 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		d = d<<1 ;
	}

	LCD_CS_H ;		//CS = 1
}

/******************************************************************************
read instruction or ram data
******************************************************************************/
U16 TX06D18_Cmd_Data_Read(void)
{
	U8 m ;
	U8 cmd = DATA_RD ;
	U16 d ;
	
	LCD_CS_L ;		//CS = 0
	
	for ( m = 0 ; m < 8 ; m++ )
	{
		LCD_SCL_L ;		//SCL = 0
		
		if( (cmd&0x80) == 0x80 )		LCD_SDI_H ;		//SDI = 1
		else	LCD_SDI_L ;		//SDI = 0
		
		LCD_SCL_H ;		//SCL = 1
		cmd = cmd<<1 ;
	}

	for ( m = 0 ; m < 40 ; m++ )		//Dummy Read
	{
		LCD_SCL_L ;		//SCL = 0
		Delay(1) ;		//
		LCD_SCL_H ;		//SCL = 1
	}

	for ( m = 0 ; m < 16 ; m++ )
	{
		d = d<<1 ;

		LCD_SCL_L ;		//SCL = 0
		Delay(1) ;		//
		LCD_SCL_H ;		//SCL = 1

		if( LCD_SDO>1 )		d |= 0x0001 ;
		else d &= 0xfffe ;
	}

	LCD_CS_H ;		//CS = 1
	return d ;
}

/******************************************************************************
write instruction or ram data to some register
******************************************************************************/
void TX06D18_Set_Register(U16 addr, U16 data)
{
	//U16 m ;
	
	TX06D18_Index_Reg_Set( addr ) ;		//set index register
	TX06D18_Cmd_Data_Write( data ) ;		//write instruction or ram data
}

/******************************************************************************
Tx06D18 Init
******************************************************************************/
void TX06D18_Init(void)
{
	U16 m ;
	
	#ifdef DEBUG
    	Uart_Printf("\nInit TX06D18(TFT LCD) By SPI Bus!\n");
	#endif	
	
	rGPCCON = ( rGPCCON & 0xffff03fc )| 0x5401 ;		//GPC0567 is output
	rGPCUP |= (0xf<<4) ;		//pull-up function is disable
	
	rGPBCON &= (~(3<<20)) ;		//GPB10 is input
	rGPBUP |= (1<<10) ;		//pull-up function is disable
	
	rGPGCON = ( rGPGCON & 0xfffffcff )| 0x0100 ;		//GPG4 is output
	rGPGUP |= (0xf<<4) ;		//pull-up function is disable
	
	if ( TX06D18_ID == 0 )
		LCD_ID_L ;		//ID is low (ID=0)
	else LCD_ID_H ;		//ID is high (ID=1)
	
	LCD_CS_H ;		//LCD CS is high (CS=1)
	LCD_SCL_H ;		//SCL = 1
	
	//*************************************************************************
	// e ---> a    [Power supply off -----> Power supply on]
	LCD_RST_H ;		//RESET
	LCD_RST_L ;		//RESET
	Delay(20) ;		//delay 1 ms
	LCD_RST_H ;		//RESET

	TX06D18_Set_Register( 0x0000, 0x0001 ) ;		//set some register
	Delay(120) ;		//delay 20 ms

	TX06D18_Index_Reg_Set(0x0);		//
	Delay(10) ;		//delay 1 ms
	m = TX06D18_Cmd_Data_Read();
	
	#ifdef DEBUG
		Uart_Printf( "\t\tChip Reg 0 data is 0x%4x\n", m );
		
		if(m == 0x0781)  Uart_Printf( "\t\tChip ID is OK!!!\n" );
		else Uart_Printf( "\t\tChip ID is error!!!\n" );
	#endif	

	//*************************************************************************
	for ( m = 0 ; LCD781_My_Tab[m] != 0x8888 ;  )
	{
		if ( LCD781_My_Tab[m] == 0xffff )	Delay( LCD781_My_Tab[m+1] ) ;
		else 	TX06D18_Set_Register( LCD781_My_Tab[m], LCD781_My_Tab[m+1] ) ;		//set some register
		m = m + 2 ;
	}
	//*************************************************************************
}
//*****************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -