📄 lcd_vga_640_480.c
字号:
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++)
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 = y0 ; y < l ; y++ )
{
for( x = x0 ; x < h ; x++ )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( x < SCR_XSIZE_TFT_640480) && ( y < SCR_YSIZE_TFT_640480) )
LCD_BUFER[y][x] = c ;
p = p + 2 ;
}
}
}
/**************************************************************
**************************************************************/
void Lcd_Port_Init( void );
void Test_Lcd_VGA_640_480(void)
{
#ifdef DEBUG
printf("\nTest VGA 640×480 !\n");
#endif
Lcd_Ctrl_Save();
Lcd_Port_Init();
Lcd_Init();
Lcd_EnvidOnOff(1); //turn on vedio
/*
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ) ; //clear screen
printf( "\nLCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
*/
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x1f) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
Lcd_ClearScr( (0x00<<11) | (0x3f<<5) | (0x00) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x00<<5) | (0x00) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
/*
Lcd_ClearScr( (0x00<<11) | (0x3f<<5) | (0x1f) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x00<<5) | (0x1f) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x00) ) ; //clear screen
printf( "LCD clear screen is finished! press any key to continue!\n" );
getch() ; //wait uart input
*/
Lcd_ClearScr(0xffff); //fill all screen with some color
#define LCD_BLANK 30
#define C_UP ( LCD_XSIZE_TFT_640480 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_640480 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_640480 - LCD_BLANK*4 ) / 6 )
Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE_TFT_640480 - LCD_BLANK ), ( LCD_YSIZE_TFT_640480 - LCD_BLANK ),0x0000); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*0), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*1),0x001f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*1), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*2),0x07e0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*2), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*3),0xf800); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*3), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*4),0xffe0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*4), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*5),0xf81f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*5), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*6),0x07ff); //fill a Rectangle with some color
printf( "LCD color test, please look! press any key to continue!\n" );
getch() ; //wait uart input
#ifdef DEBUG
printf( "\nrGPBCON=0x%x\n", rGPBCON );
printf( "\trGPBUP=0x%x\n", rGPBUP );
printf( "rGPCCON=0x%x\n", rGPCCON );
printf( "\trGPCUP=0x%x\n", rGPCUP );
printf( "rGPDCON=0x%x\n", rGPDCON );
printf( "\trGPDUP=0x%x\n", rGPDUP );
printf( "rGPGCON=0x%x\n", rGPGCON );
printf( "\trGPGUP=0x%x\n\n", rGPGUP );
printf( "rLCDCON1=0x%x\n", rLCDCON1 );
printf( "rLCDCON2=0x%x\n", rLCDCON2 );
printf( "rLCDCON3=0x%x\n", rLCDCON3 );
printf( "rLCDCON4=0x%x\n", rLCDCON4 );
printf( "rLCDCON5=0x%x\n\n", rLCDCON5 );
printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
printf( "rLCDINTMSK=0x%x\n", rLCDINTMSK );
printf( "rLPCSEL=0x%x\n", rLPCSEL );
printf( "rTPAL=0x%x\n\n", rTPAL );
#endif
Paint_Bmp(200,80,440,400, xyx_240_320); //paint a bmp
printf( "LCD paint a bmp, please look! press any key to continue! \n" );
getch() ; //wait uart input
Lcd_EnvidOnOff(0); //turn on vedio
Lcd_Ctrl_Restore();
}
//*************************************************************
static char Test_Lcd_VGA_640_480_Title[] = "VGA 640×480实验";
static char Test_Lcd_VGA_640_480_Tip[] = "VGA 640×480显示实验,显示各种颜色及图片";
TEST_PROGRAM_ITEM Test_Lcd_VGA_640_480_Item = {
(TEST_PROGRAM)Test_Lcd_VGA_640_480 ,
Test_Lcd_VGA_640_480_Title ,
Test_Lcd_VGA_640_480_Tip ,
0};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -