📄 lcd_320x240.c
字号:
}
}
/*-----------------------------------------------------------------------------
* LCD屏幕显示垂直翻转
* LCD display is flipped vertically
* But, think the algorithm by mathematics point.
* 3I2
* 4 I 1
* --+-- <-8 octants mathematical cordinate
* 5 I 8
* 6I7
*/
static void Glib_Line(int x1, int y1, int x2, int y2, U16 color)
{
int dx, dy, e;
dx = x2 - x1;
dy = y2 - y1;
if(dx >= 0)
{
if(dy >= 0) // dy>=0
{
if(dx >= dy) // 1/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 // 2/8 octant
{
e = dx-dy/2;
while(y1 <= y2)
{
PutPixel(x1, y1, color);
if(e > 0) {x1+=1; e-=dy;}
y1 += 1;
e += dx;
}
}
}
else // dy<0
{
dy = -dy; // dy=abs(dy)
if(dx >= dy) // 8/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 // 7/8 octant
{
e = dx-dy/2;
while(y1 >= y2)
{
PutPixel(x1, y1, color);
if(e > 0) {x1+=1; e-=dy;}
y1 -= 1;
e += dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/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 // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
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屏幕上画一个矩形
*/
static void Glib_Rectangle(int x1, int y1, int x2, int y2, U16 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, U16 color)
{
int i;
for(i = y1; i <= y2; i++) { // 用n条直线填满区域!
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 ;
}
}
}
/*-----------------------------------------------------------------------------
* test LTV350QV-F05
*/
void Test_Lcd_LTV350QVF05(void)
{
int i;
Lcd_Port_Init();
Lcd_Init();
Lcd_EnvidOnOff(1);
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ); //clear screen
// Lcd_ClearScr(0xffff); //fill all screen with some color
// Glib_FilledRectangle( 50, 50, 270, 190, 0x0000); //fill a Rectangle with some color
// Glib_FilledRectangle( 100, 100, 220, 140, 0xf800); //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
//LOGO
Glib_FilledRectangle(0, 0, 320, 35, 0x0);
Delay(50);
Glib_FilledRectangle( 5, 35, 315, 40, 0xf800); //Red,top
Glib_FilledRectangle(10, 40, 310, 45, 0x07e0); //Green,top
Glib_FilledRectangle(15, 45, 305, 50, 0x001f); //Blue,top
Delay(50);
Glib_FilledRectangle( 5, 37, 9, 200, 0xf800); //Red,left
Glib_FilledRectangle(10, 45, 15, 195, 0x07e0); //Green,left
Glib_FilledRectangle(16, 50, 20, 190, 0x001f); //Blue,left
Delay(50);
Glib_FilledRectangle(311, 40, 315, 200, 0xf800); //Red,right
Glib_FilledRectangle(305, 45, 310, 195, 0x07e0); //Green,right
Glib_FilledRectangle(300, 50, 304, 190, 0x001f); //Blue,right
Delay(50);
Paint_Bmp(20, 50, 280, 190, uCdragon_logo); //picture
Delay(50);
Glib_FilledRectangle( 5, 200, 315, 206, 0xf800); //Red,button
Glib_FilledRectangle( 10,195, 310, 200, 0x07e0); //Green,button
Glib_FilledRectangle( 16,190, 304, 195, 0x001f); //Blue,button
Glib_FilledRectangle(0, 206, 320, 240, 0x0);
}
/* the lcd_240x320.c end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -