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

📄 lcd_240x320.c

📁 s3c2410功能实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
static void Glib_Rectangle(int x1,int y1,int x2,int y2,int color)
{
    Glib_Line(x1,y1,x2,y1,color);
    Glib_Line(x2,y1,x2,y2,color);
    Glib_Line(x1,y2,x2,y2,color);
    Glib_Line(x1,y1,x1,y2,color);
}
*/
/**************************************************************
在LCD屏幕上用颜色填充一个矩形
**************************************************************/
static void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color)
{
    int i;

    for(i=y1;i<=y2;i++)
	Glib_Line(x1,i,x2,i,color);
}

/**************************************************************
在LCD屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[])
{
	int x,y;
	U32 c;
	int p = 0;

//本图片显示是正的显示方式
    for( y = 0 ; y < l ; y++ )
    {
    	for( x = 0 ; x < h ; x++ )
    	{
    		c = bmp[p+1] | (bmp[p]<<8) ;

			if ( ( (x0+x) < SCR_XSIZE_TFT_320240) && ( (y0+y) < SCR_YSIZE_TFT_320240) )
			LCD_BUFER[y0+y][x0+x] = c ;

    		p = p + 2 ;
    	}
    }

/*本图片显示是倒过来的,是旋转了180度的显示方式	
    for( y = l ; y > 0 ; y-- )
    {
    	for( x = h ; x > 0 ; x-- )
    	{
    		c = bmp[p+1] | (bmp[p]<<8) ;

			if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
			LCD_BUFER[y0+y][x0+x] = c ;

    		p = p + 2 ;
    	}
    }
*/
}

void Lcd_Tft_240X320_Init( void )
{
    Lcd_Port_Init();

	//***********************************
	//LTV350QV_Reset();	         //reset LCD panel
	LTV350QV_Power_ON();
	//***********************************
	
    Lcd_Init();
    Lcd_EnvidOnOff(1);		//turn on vedio

	Lcd_ClearScr(0xffff);		//fill all screen with some color
	#define LCD_BLANK		16
	#define C_UP		( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
	#define C_RIGHT		( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
	#define V_BLACK		( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
	Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE_TFT_320240 - LCD_BLANK ), ( LCD_YSIZE_TFT_320240 - LCD_BLANK ),0x0000);		//fill a Rectangle with some color

	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*0), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*1),(C_RIGHT), 0x001f);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*1), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*2),(C_RIGHT), 0x07e0);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*2), (LCD_BLANK*2),(LCD_BLANK*2 + V_BLACK*3),(C_RIGHT), 0xf800);		//fill a Rectangle with some color
	Glib_FilledRectangle(  (LCD_BLANK*2 + V_BLACK*3), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*4),(C_RIGHT),0xffe0);		//fill a Rectangle with some color
	Glib_FilledRectangle(  (LCD_BLANK*2 + V_BLACK*4), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*5),(C_RIGHT),0xf81f);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*5), (LCD_BLANK*2),  (LCD_BLANK*2 + V_BLACK*6),(C_RIGHT),0x07ff);		//fill a Rectangle with some color
}

/**************************************************************
**************************************************************/
void Test_Lcd_Tft_240X320( void )
{
	#ifdef DEBUG
    	Uart_Printf("\nTest 240*320 TFT LCD !\n");
	#endif	

      //Lcd_Port_Init();

	//***********************************
	//LTV350QV_Reset();	         //reset LCD panel
	//LTV350QV_Power_ON();
	//***********************************
	
      //Lcd_Init();
      //Lcd_EnvidOnOff(1);		//turn on vedio
    
    /*	
	Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00)  )  ;		//clear screen
	Uart_Printf( "\nLCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x1f)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x00<<11) | (0x3f<<5) | (0x00)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x1f<<11) | (0x00<<5) | (0x00)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x00<<11) | (0x3f<<5) | (0x1f)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x1f<<11) | (0x00<<5) | (0x1f)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input

	Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x00)  )  ;		//clear screen
	Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input
*/
	Lcd_ClearScr(0xffff);		//fill all screen with some color
	#define C_UP		( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
	#define C_RIGHT		( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
	#define V_BLACK		( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
	Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE_TFT_320240 - LCD_BLANK ), ( LCD_YSIZE_TFT_320240 - LCD_BLANK ),0x0000);		//fill a Rectangle with some color

	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*0), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*1),(C_RIGHT), 0x001f);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*1), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*2),(C_RIGHT), 0x07e0);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*2), (LCD_BLANK*2),(LCD_BLANK*2 + V_BLACK*3),(C_RIGHT), 0xf800);		//fill a Rectangle with some color
	Glib_FilledRectangle(  (LCD_BLANK*2 + V_BLACK*3), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*4),(C_RIGHT),0xffe0);		//fill a Rectangle with some color
	Glib_FilledRectangle(  (LCD_BLANK*2 + V_BLACK*4), (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*5),(C_RIGHT),0xf81f);		//fill a Rectangle with some color
	Glib_FilledRectangle( (LCD_BLANK*2 + V_BLACK*5), (LCD_BLANK*2),  (LCD_BLANK*2 + V_BLACK*6),(C_RIGHT),0x07ff);		//fill a Rectangle with some color
   	Uart_Printf( "LCD color test, please look! press any key to continue!\n" );
    Uart_Getch() ;		//wait uart input
/*
	Lcd_ClearScr(0x00);		//fill all screen with some color
    Paint_Bmp( 0,0,240,320, girl13_240_320 ) ;		//paint a bmp
    MoveViewPort();
    Lcd_MoveViewPort(0,0);
*/
    Lcd_ClearScr(0x00);		//fill all screen with some color
    Paint_Bmp( 0,0,320,240, xyx_240_320 ) ;		//paint a bmp
    //MoveViewPort();
    //Lcd_MoveViewPort(0,0);
    //LTV350QV_Powen_OFF();
}

/*****************************************
*  *for LTV350QV_POE TFT LCD
*****************************************/
//short delay for about 90*time ns 
void LTV350QV_Short_Delay(U8 time)
{
	U8 i;
	for(i=0;i<time*15;i++) ;                 //about 360 ns
}

//****************************************
void LTV350QV_Reset(void)
{
	RST_L;
	Delay(100);
	RST_H;
	Delay(1);
}

void LTV350QV_Register_Write(LTV350QV_SPI_Data regdata)
{
	U8 i,temp1;
	U16 temp2;
	U32 temp3;

	//write index
	temp1=regdata.Device_ID<<2 | 0<<1 | 0<<0;          //register index
	temp2=regdata.Index;
	temp3=(temp1<<24) | (temp2<<8);

	CS_L;
	LTV350QV_Short_Delay(1);
	for(i=0;i<24;i++)
		{
			SCLK_L;
			if(temp3 & (1<<(31-i)) )              //if is H
				SDI_H;
			else 
				SDI_L;
			LTV350QV_Short_Delay(1);      //setup time
			SCLK_H;
			LTV350QV_Short_Delay(1);     //hold time
		}
	CS_H;
	
	LTV350QV_Short_Delay(5);
	
	//write instruction
	temp1=regdata.Device_ID<<2 | 1<<1 | 0<<0;       //instruction
	temp2=regdata.Structure;
	temp3=(temp1<<24) | (temp2<<8);
	
	CS_L;
	LTV350QV_Short_Delay(1);
	for(i=0;i<24;i++)
		{
			SCLK_L;
			if(temp3 & (1<<(31-i)) )             //if is H
				SDI_H;
			else
				SDI_L;
			LTV350QV_Short_Delay(1);
			SCLK_H;
			LTV350QV_Short_Delay(1);
		}
	CS_H;
}

U16 LTV350QV_Register_Read(U8 index)
{
	U8 i,temp1;
	U16 temp2;
	U32 temp3;

	//write index
	temp1=LTV350QV_POE<<2 | 0<<1 | 1<<0;          //register index
	temp2=index;
	temp3=(temp1<<24) | (temp2<<8);

	CS_L;
	LTV350QV_Short_Delay(1);
	for(i=0;i<24;i++)
		{
			SCLK_L;
			if(temp3 & (1<<(31-i)) )              //if is H
				SDI_H;
			else 
				SDI_L;
			LTV350QV_Short_Delay(1);      //setup time
			SCLK_H;
			LTV350QV_Short_Delay(1);     //hold time
		}
	CS_H;
	
	LTV350QV_Short_Delay(5);
	
	//read instruction
	temp1=LTV350QV_POE<<2 | 1<<1 | 1<<0;       //instruction
	temp3=temp1<<24;
	
	CS_L;
	LTV350QV_Short_Delay(1);
	for(i=0;i<8;i++)                                          //send device ID
		{
			SCLK_L;
			if(temp3 & (1<<(31-i)) )              //if is H
				SDI_H;
			else 
				SDI_L;
			LTV350QV_Short_Delay(1);      //setup time
			SCLK_H;
			LTV350QV_Short_Delay(1);     //hold time
		}

	temp2=0;
	rGPCCON &=~(1<<20);      //SDI input
	for(i=0;i<16;i++)                                         //read data from the register
		{
			SCLK_L;
			LTV350QV_Short_Delay(1);
			SCLK_H;
			LTV350QV_Short_Delay(1);
			if(SDI_STATE)                     //if H
				temp2 |=1<<(15-i);
			else                                   //if L
				;
			LTV350QV_Short_Delay(1);
		}
	CS_H;

	return temp2;
}

/****************************************
*  *
****************************************/
void LTV350QV_Write(U16 index, U16 regdata)
{
	LTV350QV_SPI_Data WriteData;
	
	WriteData.Device_ID=LTV350QV_POE;  //0x1d
	WriteData.Index=index;                     //
	WriteData.Structure=regdata;

	LTV350QV_Register_Write(WriteData);
}

/****************************************
*  *power ON sequence
****************************************/
void LTV350QV_Power_ON(void)
{	
 	LTV350QV_Write(9, 0x0000);
 	Delay(150);
 	LTV350QV_Write(9, 0x4000);
 	LTV350QV_Write(10, 0x2000);
 	LTV350QV_Write(9, 0x4055);
 	Delay(550);
 	LTV350QV_Write(1, 0x409d);
 	LTV350QV_Write(2, 0x0284);
	 LTV350QV_Write(3, 0x0100);
 	LTV350QV_Write(4, 0x3000);
 	LTV350QV_Write(5, 0x4003);
 	LTV350QV_Write(6, 0x000a);
 	LTV350QV_Write(7, 0x0021);
 	LTV350QV_Write(8, 0x0c00);
 	LTV350QV_Write(10, 0x0103);
	 LTV350QV_Write(11, 0x0301);
 	LTV350QV_Write(12, 0x1f0f);
 	LTV350QV_Write(13, 0x1f0f);
 	LTV350QV_Write(14, 0x0707);
 	LTV350QV_Write(15, 0x0307);
 	LTV350QV_Write(16, 0x0707);
 	LTV350QV_Write(17, 0x0000);
 	LTV350QV_Write(18, 0x0004);
 	LTV350QV_Write(19, 0x0000);

 	Delay(200);
 	LTV350QV_Write(9, 0x4a55);
 	LTV350QV_Write(5, 0x5003);
}

/**********************************
*  *power OFF sequence
**********************************/
void LTV350QV_Powen_OFF(void)
{

	 /* GON -> 0, POC -> 0 */
	 LTV350QV_Write(9, 0x4055);
	 /* DSC -> 0 */
	 LTV350QV_Write(5, 0x4003);
 	/* VCOMG -> 0 */
 	LTV350QV_Write(10, 0x0000);

 	Delay(20);

	 /* AP[2:0] -> 000 */
	 LTV350QV_Write(9, 0x4000);
}
//*************************************************************

⌨️ 快捷键说明

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