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

📄 lcd_8cun.c

📁 ads下2410的测试程序
💻 C
字号:
/****************************************************************************
【文  件  名  称】LCD_8cun.c
【功  能  描  述】FFT-2410教学平台实验程序
【程  序  版  本】3.0
【创建及创建日期】傅立业公司/2005-XX-XX
【修改及修改日期】2005-5-23
****************************************************************************/
//头文件定义
#include "def.h"
#include "2410addr.h"
#include "board.h"
#include "2410slib.h"
#include "LCD_LTS350Q1_PE1.h"

extern void printf(char *f, ...) ;
extern unsigned char xyx_240_320[];	//宽240,高320

#define	FRAME_BUFFER_ADDR	0x33700000//0x33fd0000

U16 *LCD_BUFER = (U16 *)FRAME_BUFFER_ADDR;

/***************************************************************************
Function name: Lcd_Port_Init
Parameter    : void
Description  : 320×240 16Bpp TFT LCD数据和控制端口初始化
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_Port_Init(void)
{
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaa56a9; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 

    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
}

/***************************************************************************
Function name: Lcd_Init
Parameter    : void
Description  : 320×240 16Bpp TFT LCD功能模块初始化
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_Init(void)
{
	rLCDCON1=(CLKVAL_TFT_640480<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
    	// TFT LCD panel,12bpp TFT,ENVID=off
	rLCDCON2=(VBPD_640480<<24)|(LINEVAL_TFT_640480<<14)|(VFPD_640480<<6)|(VSPW_640480);
	rLCDCON3=(HBPD_640480<<19)|(HOZVAL_TFT_640480<<8)|(HFPD_640480);
	rLCDCON4=(MVAL<<8)|(HSPW_640480);
	rLCDCON5=(1<<11)|(0<<9)|(0<<8)|(0<<6)|(BSWP<<1)|(HWSWP);	//FRM5:6:5,HSYNC and VSYNC are inverted

	rLCDSADDR1=(((U32)LCD_BUFER>>22)<<21)|M5D((U32)LCD_BUFER>>1);
	rLCDSADDR2=M5D( ((U32)LCD_BUFER+(SCR_XSIZE_TFT_640480*LCD_YSIZE_TFT_640480*2))>>1 );
	rLCDSADDR3=(((SCR_XSIZE_TFT_640480-LCD_XSIZE_TFT_640480)/1)<<11)|(LCD_XSIZE_TFT_640480/1);
	rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
	rLPCSEL&=(~7); // Disable LPC3600
	rTPAL=0; // Disable Temp Palette
}

/***************************************************************************
Function name: Lcd_EnvidOnOff
Parameter    : onoff:
Description  : LCD视频和控制信号输出或者停止,1开启视频输出
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_EnvidOnOff(int onoff)
{
    if(onoff==1)
	rLCDCON1|=1; // ENVID=ON
    else
	rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}

/***************************************************************************
Function name: Lcd_Lpc3600Enable
Parameter    : void
Description  : LPC3600 is a timing control logic unit for LTS350Q1-PD1 or LTS350Q1-PD2
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_Lpc3600Enable(void)
{
    rLPCSEL&=~(7);
    rLPCSEL|=(7); // 640480,Enable LPC3600
}    

/***************************************************************************
Function name: Lcd_PowerEnable
Parameter    : 
Description  : 320×240 8Bpp TFT LCD 电源控制引脚使能
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_PowerEnable(int invpwren,int pwren)
{
    //GPG4 is setted as LCD_PWREN
    rGPGUP = rGPGUP|(1<<4); // Pull-up disable
    rGPGCON = rGPGCON|(3<<8); //GPG4=LCD_PWREN
    //Enable LCD POWER ENABLE Function
    rLCDCON5 = rLCDCON5&(~(1<<3))|(pwren<<3);   // PWREN
    rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
}

/***************************************************************************
Function name: LcdBlkLtSet
Parameter    : HiRatio:背光控制参数
Description  : 背光控制
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void LcdBkLtSet(U32 HiRatio)
{
#define FREQ_PWM1		1000

	if(!HiRatio)
	{
		rGPBCON  = rGPBCON & (~(3<<2)) | (1<<2) ;	//GPB1设置为output
		rGPBDAT &= ~(1<<1);
		return;
	}
	rGPBCON = rGPBCON & (~(3<<2)) | (2<<2) ;		//GPB1设置为TOUT1
	
	if( HiRatio > 100 )
		HiRatio = 100 ;	
	
	rTCON = rTCON & (~(0xf<<8)) ;			// clear manual update bit, stop Timer1

	rTCFG0 	&= 0xffffff00;					// set Timer 0&1 prescaler 0

	rTCFG1 	&= 0xffffff0f;					// set Timer 1 MUX 1/16
	rTCFG1  |= 0x00000030;					// set Timer 1 MUX 1/16

	rTCNTB1	 = ( GetMasterClock()>>4 )/FREQ_PWM1;		//if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
	rTCMPB1  = ( rTCNTB1*(100-HiRatio))/100 ;	//if set inverter on,  when TCNT2<=TCMP2, TOUT is low,  TCNT2>TCMP2, TOUT is high

	rTCON = rTCON & (~(0xf<<8)) | (0x0e<<8) ;
	//自动重装,输出取反关闭,更新TCNTBn、TCMPBn,死区控制器关闭
	rTCON = rTCON & (~(0xf<<8)) | (0x0d<<8) ;		//开启背光控制
}

/***************************************************************************
Function name: Lcd_Palette_Init
Parameter    : void
Description  : 320×240 8Bpp TFT LCD 颜色初始化
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_Palette_Init(void)
{
    unsigned char cdata, p_red, p_green, p_blue;
    U32 *palette;
    
	//#define PALETTE     0x4d000400    //Palette start address
    palette=(U32 *)PALETTE;
    *palette++=0; //black
    for(cdata=1;cdata<255;cdata++)
    {
		p_red=(cdata & 0xe0);
		p_green=(cdata & 0x1c);
		p_blue=(cdata & 0x03);
    	*palette++=((U32)((p_red<<8)|(p_green<<6)|(p_blue<<3)));
    }
    *palette=0xffff; //white
}


/***************************************************************************
Function name: PutPixelColor
Parameter    : x,y : 要在LCD上显示的点的坐标
			   c   : 要显示的数据,也就是色彩	   
Description  : 在LCD上显示给定坐标的像素点
Return	     : void
Argument     : 320×240 16Bpp TFT LCD单个象素的显示数据输出
Autor & date :
****************************************************************************/
void PutPixel(U32 x,U32 y, U32 c )
{
	if ( (x < SCR_XSIZE_TFT_640480) && (y < SCR_YSIZE_TFT_640480) )
		LCD_BUFER[ y*SCR_XSIZE_TFT_640480 + x ] = c;
}


/***************************************************************************
Function name: GetPixel
Parameter    : x,y : 要在LCD上显示的点的坐标
			   mem : 存放像素点的色彩信息	   
Description  : 
Return	     : void
Argument     : 320×240 16Bpp TFT LCD单个象素的显示数据获得
Autor & date :
****************************************************************************/
int GetPixel(U32 x,U32 y, U16 *mem)
{
	if ( (x < SCR_XSIZE_TFT_640480) && (y < SCR_YSIZE_TFT_640480) )
	{
		*mem = LCD_BUFER[ y*SCR_XSIZE_TFT_640480 + x ] ;
		return 0 ;
	}

	return -1;
}

/***************************************************************************
Function name: Lcd_ClearScr
Parameter    : c : 清屏的色彩			   
Description  : 以不同的色彩清屏
Return	     : void
Argument     : 320×240 16Bpp TFT LCD全屏填充特定颜色单元或清屏
Autor & date :
****************************************************************************/
void Lcd_ClearScr( U32 c)
{
	unsigned int x,y ;
		
    for( y = 0 ; y < SCR_YSIZE_TFT_640480 ; y++ )
    {
    	for( x = 0 ; x < SCR_XSIZE_TFT_640480 ; x++ )
    	{
			LCD_BUFER[y*SCR_XSIZE_TFT_640480+x] = c;
    	}
    }
}

/***************************************************************************
Function name: Glib_ClearScr
Parameter    : c : 清屏的色彩			   
Description  : 以不同的色彩清屏
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Glib_ClearScr( U32 c )
{	
	unsigned int x,y ;
		
    for( y = 0 ; y < SCR_YSIZE_TFT_640480 ; y++ )
    {
    	for( x = 0 ; x < SCR_XSIZE_TFT_640480 ; x++ )
    	{
			LCD_BUFER[y*SCR_XSIZE_TFT_640480+x] = c;
    	}
    }
}


/***************************************************************************
Function name: Glib_Line
Parameter    : x1,y1,x2,y2:要显示的线的两点坐标
			   color : 显示的色彩
Description  : LCD画线函数
Return	     : void
Argument     : 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
Autor & date :
****************************************************************************/
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;
				}
			}
		}	
	}
}

/***************************************************************************
Function name: Glib_Rectangle
Parameter    : x1,y1,x2,y2:矩形的对角线的坐标	
			   color :边框要显示的色彩			   
Description  : 根据提供的对角线坐标来画不同色彩的矩形框
Return	     : void
Argument     : 在LCD屏幕上画一个矩形
Autor & date :
****************************************************************************/
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);
}

/***************************************************************************
Function name: Glib_FiledRectangle
Parameter    : x1,y1,x2,y2:矩形的对角线的坐标	
			   color :矩形框内要填充的色彩			   
Description  : 根据提供的对角线坐标来填充不同色彩的矩形
Return	     : void
Argument     : 在LCD屏幕上用颜色填充一个矩形
Autor & date :
****************************************************************************/
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);
}

/***************************************************************************
Function name: Lcd_C256_Bmp
Parameter    : x0,y0,x1,y1:要显示的图片的区域的对角线坐标
			   bmp[]:要显示的图片的像素点数组
Description  : 将bmp所保存的图片信息在LCD上显示出来
Return	     : void
Argument     : 在LCD屏幕上指定坐标点画一个指定大小的图片
Autor & date :
****************************************************************************/
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 ( ( (x0+x) < SCR_XSIZE_TFT_640480) && ( (y0+y) < SCR_YSIZE_TFT_640480) )
			LCD_BUFER[y*SCR_XSIZE_TFT_640480+x] = c;
			
    		p = p + 2 ;
    	}
    }
}


/***************************************************************************
Function name: Lcd_Tft_LTS350Q1_PE1_Init
Parameter    : void
Description  : 320×240 8Bpp TFT LCD 初始化
Return	     : void
Argument     : 
Autor & date :
****************************************************************************/
void Lcd_Tft_LTS350Q1_PE1_Init(void)
{
	#ifdef DEBUG
    	printf("\nTest LTS350Q1_PE1 (TFT LCD)!\n");
	#endif	

    Lcd_Port_Init();		//LCD端口初始化
    Lcd_Init();				//LCD初始化
    Lcd_EnvidOnOff(1);		//turn on vedio
}

/*************************************************************/

⌨️ 快捷键说明

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