📄 lcd.c
字号:
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
/**************************************************************
在LCD屏幕上画一个矩形
**************************************************************/
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屏幕上用颜色填充一个矩形
**************************************************************/
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屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
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 ;
}
}
}
/**************************************************************
**************************************************************/
void Test_Lcd_Tft_16Bpp_240_320(void)
{
//unsigned int x,y ;
//U32 c;
#define DELAY_TIME 36000
#ifdef DEBUG
Uart_Printf("\nTest LTV350QV_POE (TFT LCD)!\n");
#endif
Lcd_Port_Init();
Lcd_Init();
Lcd_EnvidOnOff(1); //turn on vedio
Lcd_ClearScr(0xffff); //fill all screen with some color 0xffff
Glib_FilledRectangle( 12, 12, 308, 228,0x0000); //fill a Rectangle with some color
Glib_FilledRectangle( 24, 24, 296,88,0xf800); //fill a Rectangle with some color
Glib_FilledRectangle( 24, 89,296,152,0x07e0); //fill a Rectangle with some color
Glib_FilledRectangle(24, 153,296,216,0x001f); //fill a Rectangle with some color
Glib_FilledRectangle( 110, 70, 210, 170,0xf7e0); //fill a Rectangle with some color
Glib_FilledRectangle( 130, 90, 190, 150,0x07ff); //fill a Rectangle with some color
Glib_FilledRectangle(150, 110, 170, 130,0xf81f); //fill a Rectangle with some color
#ifdef DEBUG
Uart_Printf( "\nrGPBCON=0x%x\n", rGPBCON );
Uart_Printf( "\trGPBUP=0x%x\n", rGPBUP );
Uart_Printf( "rGPCCON=0x%x\n", rGPCCON );
Uart_Printf( "\trGPCUP=0x%x\n", rGPCUP );
Uart_Printf( "rGPDCON=0x%x\n", rGPDCON );
Uart_Printf( "\trGPDUP=0x%x\n", rGPDUP );
Uart_Printf( "rGPGCON=0x%x\n", rGPGCON );
Uart_Printf( "\trGPGUP=0x%x\n\n", rGPGUP );
Uart_Printf( "rLCDCON1=0x%x\n", rLCDCON1 );
Uart_Printf( "rLCDCON2=0x%x\n", rLCDCON2 );
Uart_Printf( "rLCDCON3=0x%x\n", rLCDCON3 );
Uart_Printf( "rLCDCON4=0x%x\n", rLCDCON4 );
Uart_Printf( "rLCDCON5=0x%x\n\n", rLCDCON5 );
Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
Uart_Printf( "rLCDINTMSK=0x%x\n", rLCDINTMSK );
Uart_Printf( "rLPCSEL=0x%x\n", rLPCSEL );
Uart_Printf( "rTPAL=0x%x\n\n", rTPAL );
#endif
//Paint_Bmp( 0, 0,320,240, xyx_240_320 ); //paint a bmp
}
/*****************************************
* *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*10;i++) ; //about 180 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, 0x0204);
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 + -