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

📄 lcd_v16c6448ac.c

📁 基于WINCE的FM发射程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************
The initial and control for 640×480 16Bpp TFT LCD----V16C6448AC
**************************************************************/

#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h" 

#define CLKVAL_TFT_640480	(1)		
//元太6.4寸TFT液晶屏V16C6448AC时钟频率典型值为25.175MHz
//FCLK = 180MHz, HCLK = PCLK = 90MHz
//VCLK = HCLK / [(CLKVAL+1) * 2]     ( CLKVAL >= 0 )
//VCLK = 45MHz		//  34MHz < VCLK < 40MHz

#define MVAL		(13)
#define MVAL_USED 	(0)		//0=each frame   1=rate by MVAL
#define BSWP		(0)		//Byte swap control
#define HWSWP		(1)		//Half word swap control

#define M5D(n) ((n) & 0x1fffff)	// To get lower 21bits

//TFT 640480
#define LCD_XSIZE_TFT_640480 	(640)	
#define LCD_YSIZE_TFT_640480 	(480)

//TFT 640480
//#define SCR_XSIZE_TFT_640480 	(640)
//#define SCR_YSIZE_TFT_640480 	(480)
#define SCR_XSIZE_TFT_640480 	(640)
#define SCR_YSIZE_TFT_640480 	(480)

//TFT640480
#define HOZVAL_TFT_640480	(LCD_XSIZE_TFT_640480-1)
#define LINEVAL_TFT_640480	(LCD_YSIZE_TFT_640480-1)

//以下参数只针对元太6.4寸TFT液晶屏V16C6448AC
#define VGA350_MODE		0
#define FREEDOM_MODE		1

#if VGA350_MODE
	#define VBPD_640480		(33)	//垂直同步信号的后肩		VGA350模式,都是负极性
	#define VFPD_640480		(10)		//垂直同步信号的前肩
	#define VSPW_640480		(2)		//垂直同步信号的脉宽

	#define HBPD_640480		(48)		//水平同步信号的后肩
	#define HFPD_640480		(16)		//水平同步信号的前肩
	#define HSPW_640480		(96)		//水平同步信号的脉宽
#elif   FREEDOM_MODE
	#define VBPD_640480		(20)	//垂直同步信号的后肩		FREEDOM模式,都是正极性
	#define VFPD_640480		(16)		//垂直同步信号的前肩
	#define VSPW_640480		(2)		//垂直同步信号的脉宽

	#define HBPD_640480		(48)		//水平同步信号的后肩
	#define HFPD_640480		(16)		//水平同步信号的前肩
	#define HSPW_640480		(96)		//水平同步信号的脉宽
#endif

extern void Uart_Printf(char *f, ...) ;

extern unsigned char girl3_640_480[] ;		//宽640,高480

volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_640480][SCR_XSIZE_TFT_640480];

/**************************************************************
640×480 16Bpp TFT LCD功能模块初始化
**************************************************************/
static void Lcd_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]

	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
    rTCONSEL&=~((1<<4)|1); // Disable LCC3600, LPC3600
	rTPAL=0; // Disable Temp Palette
}

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

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

/**************************************************************
640×480 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void Lcd_MoveViewPort(int vx,int vy)
{
    U32 addr;

    SET_IF(); 
	#if (LCD_XSIZE_TFT_640480<32)
    	    while((rLCDCON1>>18)<=1); // if x<32
	#else	
    	    while((rLCDCON1>>18)==0); // if x>32
	#endif
    
    addr=(U32)LCD_BUFER+(vx*2)+vy*(SCR_XSIZE_TFT_640480*2);
	rLCDSADDR1= ( (addr>>22)<<21 ) | M5D(addr>>1);
	rLCDSADDR2= M5D(((addr+(SCR_XSIZE_TFT_640480*LCD_YSIZE_TFT_640480*2))>>1));
	CLR_IF();
}    

/**************************************************************
640×480 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void MoveViewPort(void)
{
    int vx=0,vy=0,vd=1;

    Uart_Printf("\n*Move the LCD view windos:\n");
    Uart_Printf(" press 8 is up\n");
    Uart_Printf(" press 2 is down\n");
    Uart_Printf(" press 4 is left\n");
    Uart_Printf(" press 6 is right\n");
    Uart_Printf(" press Enter to exit!\n");

    while(1)
    {
    	switch( Uart_GetKey() )
    	{
    	case '8':
	    if(vy>=vd)vy-=vd;    	   	
        break;

    	case '4':
    	    if(vx>=vd)vx-=vd;
    	break;

    	case '6':
                if(vx<=(SCR_XSIZE_TFT_640480-LCD_XSIZE_TFT_640480-vd))vx+=vd;   	    
   	    break;

    	case '2':
                if(vy<=(SCR_YSIZE_TFT_640480-LCD_YSIZE_TFT_640480-vd))vy+=vd;   	    
   	    break;

    	case '\r':
   	    return;

    	default:
	    break;
		}
	Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
	Lcd_MoveViewPort(vx,vy);
    }
}

/**************************************************************
640×480 16Bpp TFT LCD单个象素的显示数据输出
**************************************************************/
static void PutPixel(U32 x,U32 y, U32 c )
{
	if ( (x < SCR_XSIZE_TFT_640480) && (y < SCR_YSIZE_TFT_640480) )
		LCD_BUFER[(y)][(x)] = c;
}

/**************************************************************
640×480 16Bpp TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/
static 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][x] = 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,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;

⌨️ 快捷键说明

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