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

📄 test_lcd2c.c

📁 三星2410 LCD
💻 C
字号:
#include <string.h>
#include "test_lcd2h.h"
#include "DEMO256.h"

extern unsigned int (*frameBuffer16BitTft240320)[SCR_XSIZE_TFT_240320/2];  

extern void Lcd_Port_Init(void);
extern void Lcd_Init(void); 
extern void Lcd_EnvidOnOff(int onoff);
extern void Lcd_Lpc3600Enable(void);
extern void Lcd_PowerEnable(int invpwren,int pwren);

 
//void (*PutPixel)(unsigned int,unsigned int,unsigned int); 


//void PutTft16Bit_240320(unsigned int x,unsigned int y,unsigned int c)
void PutPixel(unsigned int x,unsigned int y,unsigned int c)
{
    if(x<SCR_XSIZE_TFT_240320 && y<SCR_YSIZE_TFT_240320)
    
        frameBuffer16BitTft240320[(y)][(x)/2]=( frameBuffer16BitTft240320[(y)][x/2]
        & ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16) );
} 

/*************************************************************
void Lcd_Palette8Bit_Init(void)
{
    int i;	
    U32 *palette;
    rLCDCON5|=(1<<11); // 5:6:5 Palette Setting
    palette=(U32 *)PALETTE;
    for(i=0;i<256;i++)
	*palette++=DEMO256pal[i];
}
*************************************************************/


// LCD display is flipped vertically LCD屏幕显示垂直翻转 画线
// But, think the algorithm by mathematics point.
//   3I2
//   4 I 1
//  --+--   <-8 octants  mathematical cordinate
//   5 I 8
//   6I7
void Glib_Line(int x1,int y1,int x2,int y2,int 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屏幕上画一个矩形
**************************************************************/
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);
}




/**************************************************************
320×240 16Bpp TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/

void Glib_ClearScr(unsigned int c)
{	
    int i,j;
	for(j=0;j<SCR_YSIZE_TFT_240320;j++)
            for(i=0;i<SCR_XSIZE_TFT_240320;i++)
		        PutPixel(i,j,c);
   
}


//主程序
void Test_Lcd_Tft_16Bit_240320(void)
{
    int i,j,k;
    rGPBCON=0x000001;		/*设置I/O口GPB0为输出属性* KEYBOARD脚*/
	rGPBUP=0xffff   ;	   /*禁止GPB端口的上拉*/
	rGPBDAT=0x0;          //初始化GPB的脚
    
    Lcd_Port_Init();
    Lcd_Init();
  //  Glib_Init();
    Lcd_Lpc3600Enable(); // Enable LPC3600
    Lcd_PowerEnable(0, 1);
    Lcd_EnvidOnOff(1);
  //  Uart_Printf("[TFT 64K COLOR(16bit/1pixel) LCD TEST]\n");
  
        Glib_ClearScr(0);
    	Glib_FilledRectangle(0,0,230,159,0xf800);    
    	Glib_FilledRectangle(0,160,230,300,0xf800);    
   		// Uart_Printf("TFT 64K color mode test 1. Press any key!\n");
  		//  Uart_Getch();  	
    

    	Glib_ClearScr(0);
    	Glib_Rectangle(0,0,230,300,0x07e0);   
    	Glib_FilledRectangle(0,0,20,20,65535);   
    	Glib_Rectangle(220,300,230,300,65535);   
    	Glib_Line(0,0,230,300,0x1f);        
    	Glib_Line(230,0,0,300,0xf800);
   		// Uart_Printf("TFT 64K color mode test 2. Press any key!\n");
   		// Uart_Getch();  	

    	Glib_ClearScr(0);
    	k=0;
    	for(i=80;i<240;i+=10)
  		  {
    		for(j=60;j<180;j+=10)
    			{
    	    		Glib_FilledRectangle(j,i,j+9,i+9,k);
    	    		k++;
    			}
    		}

    	Glib_Rectangle(0,0,230,300,65535);   
    	Glib_Line(0,0,230,300,65535);        
    	Glib_Line(0,300,230,0,65535);
         rGPBDAT=~rGPBDAT;        //GPB的脚 
   	   //  Lcd_Palette8Bit_Init();
   	     for(j=0;j<320;j++)
            for(i=0;i<240;i++)
             PutPixel(i,j,((int)DEMO256[k++]));
   	    //Glib_Rectangle(0+240,0,239+240,319,255);
    	//Glib_Line(0+240,0,239+240,319,255);        
    	//Glib_Line(0+240,319,239+240,0,255);
    
    	//Glib_Rectangle(0,0+320,239,319+320,255);
    	//Glib_Line(0,0+320,239,319+320,255);        
    	//Glib_Line(0,319+320,239,0+320,255);
    
    	//Glib_Rectangle(0+240,0+320,239+240,319+320,255);
    	//Glib_Line(0+240,0+320,239+240,319+320,255);     
    	//Glib_Line(0+240,319+320,239+240,0+320,255);
    	//Glib_Rectangle(40+240,40+320,480-41,640-41,0x1f);

   		// Uart_Printf("Virtual Screen Test(TFT 64K color). Press any key[ijkm\\r]!\n");
  		//  MoveViewPort(MODE_TFT_16BIT_240320);
  		//  Lcd_MoveViewPort(0,0,MODE_TFT_16BIT_240320);
  		//  Lcd_EnvidOnOff(0);
  		//  Lcd_Port_Return();
    
}

⌨️ 快捷键说明

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