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

📄 lcdd.c

📁 uCos for 320240LCD of s3c2410
💻 C
字号:



// To Drive The LCD 




#define LCD_G
#include "sysincludes.h"
#include "word.h"
#include "word.c"


U32 (*frameBuffer16BitTft240320)[SCR_XSIZE_TFT_240320/2];
#define VideoAddrStart (0x32000000)


//volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];


unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON; 
unsigned lcd_count;

void Lcd_Port_Init(void)
{
    save_rGPCCON=rGPCCON;
    save_rGPCDAT=rGPCDAT;
    save_rGPCUP=rGPCUP;
    save_rGPDCON=rGPDCON;
    save_rGPDDAT=rGPDDAT;
    save_rGPDUP=rGPDUP;
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
    
    printf("\r\nInitalize the LCD Port\r\n ");
}


#define BSWP		(0)		//Byte swap control      8月8日修改
#define HWSWP		(0)		//Half word swap control  8月8日修改



void LcdInit( void ) 
{
   frameBuffer16BitTft240320=(U32 (*)[SCR_XSIZE_TFT_240320/2])LCDFRAMEBUFFER;
   //  frameBuffer16BitTft240320=(U32 (*)[LCD_XSIZE_TFT_240320/2])LCDFRAMEBUFFER;
   
   
   rLCDCON2=0x14FC081;
   rLCDCON3=0x188EF0F;
   rLCDCON4=0xD;
   //rLCDCON5=(1<<11)|(1<<9)|(1<<8)|(0<<6)|(1<<3);
   rLCDCON5=0xB09;
  // rLCDSADDR1=0x18000000;
   rLCDSADDR1=(((U32)VideoAddrStart>>22)<<21)|M5D((U32)VideoAddrStart>>1);
  // rLCDSADDR2=0x12c00;
  rLCDSADDR2 = (((U32)VideoAddrStart + 320*240*2) & 0x003FFFFE) >>1;
   rLCDCON1=0x479;
   rLCDSADDR3=0x0;
   rREDLUT=0x0;
   rGREENLUT=0x0;
   rBLUELUT=0x0;
   rDITHMODE=0x0;
   rTPAL=0x0;
   rLCDINTPND=0x0;
   rLCDSRCPND=0x0;
   rLCDINTMSK=0x3;
   rLPCSEL=0x4;
   
   
   
    
	/*rLCDCON1=(CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
	
    	// TFT LCD panel,12bpp TFT,ENVID=off
	rLCDCON2=(VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320);
	
	rLCDCON3=(HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320);
	
	rLCDCON4=(MVAL<<8)|(HSPW_240320);
	
	
	rLCDCON5=(1<<11)|(1<<9)|(1<<8)|(0<<6)|(1<<3)|(BSWP<<1)|(HWSWP);
	//rLCDCON5=(1<<11)|(1<<9)|(1<<8)|(0<<6)|(1<<3);
	//rLCDCON5=(1<<11)|(1<<9)|(1<<8);	//FRM5:6:5,HSYNC and VSYNC are inverted   8月8日修改
	
	rLCDSADDR1=(((U32)frameBuffer16BitTft240320>>22)<<21)|M5D((U32)frameBuffer16BitTft240320>>1);
	
	
	//rLCDSADDR2 = (((U32)frameBuffer16BitTft240320 + 320*240*2) & 0x003FFFFE) >>1;
	rLCDSADDR2=M5D( ((U32)frameBuffer16BitTft240320+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
	
	rLCDSADDR3=(((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)|(LCD_XSIZE_TFT_240320/1);
	
	//rLCDSADDR3 = (0<<11) | (640);
	
	rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
	
	rLPCSEL&=(~7); // Disable LPC3600
	
	rTPAL=0; // Disable Temp Palette*/
	
	printf("%x\n",rLCDCON1 ) ;
	printf("%x\n",rLCDCON2 ) ;
	printf("%x\n",rLCDCON3 ) ;
	printf("%x\n",rLCDCON4 ) ;
	printf("%x\n",rLCDCON5 ) ; 
	printf("%x\n",rLCDSADDR1 ) ;
	printf("%x\n",rLCDSADDR2 ) ;
	printf("%x\n",rLCDSADDR3 ) ;


}



void Lcd_Lpc3600Enable(void)
{
    rLPCSEL&=~(7);
    rLPCSEL|=(7); // 240320,Enable LPC3600
}    



void Lcd_EnvidOnOff(int onoff)
{
    if(onoff==1)
	rLCDCON1|=1; // ENVID=ON
    else
	rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}

    
#define x_size (240)
#define x_limit (320)
#define y_limit (240)
#define ERROR		(0)

/// Lcd Opetion Function 
int PutPixel(int x,int y,unsigned short pencolor)
{
	int movetop;   //THE PIXEL ADDRESS
	short *p;
	if (x<0||x>(int)x_limit) return ERROR;
	if (y<0||y>(int)y_limit) return ERROR;
	y=240-y;
	//指向所要显示的像素偏移地址
	movetop=(x*x_size+y)*2;//一个像素占两个字节   
	p=(short *)(VideoAddrStart+movetop);
	*p=pencolor;
	//return 1;
}


/*void PutPixel(U32 x,U32 y,U32 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) );
        
  	//if ( (x < SCR_XSIZE_TFT_240320) && (y < SCR_YSIZE_TFT_240320) )
	//frameBuffer16BitTft240320[(y)][(x)] = c;
}*/
   
   
   


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

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;
				}
			}
		}	
	}
}



void Character_Show(int x,int y,int col,char *Catch_word)	//文字显示程序
{	int i,j,m=0x80;
	for(i=0;i<16;i++)
		for(j=0;j<16;j++)
			{	if(*Catch_word&m)
					PutPixel(i+x,j+y,0xffff);
				else	PutPixel(i+x,j+y,col);
				m>>=1;
				if(m==0)
				{	Catch_word++;
					m=0x80;
				}			
			}
}


void LcdTest( void )
{
    
    Lcd_Port_Init() ; 
    LcdInit() ;
   // Lcd_Lpc3600Enable() ; 
   // Lcd_EnvidOnOff(1) ;  
      
    Glib_ClearScr( 0, 0 ) ; 
    
    Glib_Line(0,0,320,240,0xf800);  
    
    Glib_ClearScr( 0, 0 ) ;
    
    Character_Show(160-48,100,0x0,zhong1);
	Character_Show(176-48,100,0x0,hua2);
	Character_Show(192-48,100,0x0,ren2);
	Character_Show(208-48,100,0x0,ming2);
	Character_Show(224-48,100,0x0,gong4);
	Character_Show(240-48,100,0x0,he2);
	Character_Show(256-48,100,0x0,guo2);
   // Glib_Line(0,0,320,240,0xf800);       
   // Glib_Line(240,0,0,320,0x8f00);

   // while( 1 ) ; 


}


void WriteLcdMems( uint off, U16 c ) 
{
       
    uint x, y ; 
    
    y = off/320 ; x = off%320 ; 
    PutPixel(x,y,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) );*/
}


⌨️ 快捷键说明

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