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

📄 lcd640.c

📁 u-us/os2系统
💻 C
字号:
#include <stdarg.h>
#include <stdio.h>
#include "..inc/lcd320.h"
#include "..inc/lib.h"
#include "inc/macro.h"
#include "inc/drv/reg2410.h"

#define LCDCON1_CLKVAL		(1<<8)
#define LCDCON1_MMODE		(0<<7)
#define LCDCON1_PNRMODE	(0x3<<5)
#define LCDCON1_BPPMODE		(0xc<<1)
#define LCDCON1_ENVID		(1)

#define LCDCON2_VBPD 32//32
#define LCDCON2_LINEVAL 479
#define LCDCON2_VFPD 9//9
#define LCDCON2_VSPW 1//

#define LCDCON3_HBPD 47//49
#define LCDCON3_HOZVAL 639
#define LCDCON3_HFPD 15//14

#define LCDCON4_HSPW 95//95

#define LCDCON5_FRM565 1//
#define LCDCON5_INVVCLK 0
#define LCDCON5_INVVLINE 1
#define LCDCON5_INVVFRAME 1
#define LCDCON5_INVVD 0
#define LCDCON5_INVVDEN 0
#define LCDCON5_INVPWREN 0
#define LCDCON5_INVLEND 0
#define LCDCON5_PWREN 1
#define LCDCON5_ENLEND 0
#define LCDCON5_BSWP 0
#define LCDCON5_HWSWP 1
#define BPP24BL 0
#define TPALEN 1
#define LPC_EN 1
#define FIWSEL 0
#define INT_FrSyn 1
#define INT_FiCnt 1
#define MVAL 13

#define LCD_MEM_BASE	0x32096000

#define BITS_PER_PIXEL	16

#define	SCREEN_WIDTH	640
#define SCREEN_HEIGHT	480

#define CHAR_WIDTH	12
#define CHAR_HEIGHT	14

#define	LINE_WIDTH	
#define LINE_HEIGHT	CHAR_HEIGHT*2+4

U16* pLCDBuffer16I1=(U16*)0x32000000;
U16* pLCDBuffer16I2=(U16*)0x32096000;
U32 LCDBufferII2[LCDHEIGHT][LCDWIDTH];
U16 LCDBufferII1[307200];

extern int mask_high;
extern int mask_low;
int flag;
void LCD_Init()
{
	U32 i;
	U32 LCDBASEU,LCDBASEL,LCDBANK;

    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]
      
    rLCDCON1=0|LCDCON1_BPPMODE|LCDCON1_PNRMODE|LCDCON1_MMODE|LCDCON1_CLKVAL;//|LCDCON1_MMODE;    
	    // disable
	rLCDCON2=(LCDCON2_VBPD<<24)|(LCDCON2_LINEVAL<<14)|(LCDCON2_VFPD<<6)|LCDCON2_VSPW;
	    //320x240LCD  LINEBLANK=15 (without any calculation) 
	rLCDCON3=(LCDCON3_HBPD<<19)|(LCDCON3_HOZVAL<<8)|LCDCON3_HFPD;
    rLCDCON4=LCDCON4_HSPW|(MVAL<<8);
	rLCDCON5=(BPP24BL<<12)|(LCDCON5_FRM565<<11)|(LCDCON5_INVVCLK<<10)|(LCDCON5_INVVLINE<<9)|(LCDCON5_INVVFRAME<<8)|(LCDCON5_INVVD<<7)|\
		     (LCDCON5_INVVDEN<<6)|(LCDCON5_INVPWREN<<5)|(LCDCON5_INVLEND<<4)|(LCDCON5_PWREN<<3)|(LCDCON5_ENLEND<<2)|(LCDCON5_BSWP<<1)|LCDCON5_HWSWP;
	
	LCDBANK=0x32000000>>22;
	LCDBASEU=0x0;	  
	LCDBASEL=LCDBASEU+(480)*640;
	//rLCDADDR1=0x33000000>>1;
	rLCDADDR1= (LCDBANK<<21)|LCDBASEU;    
	rLCDADDR2=LCDBASEL;	
	rLCDADDR3= (640)|(0<<11);
	rLCDINTMSK=(INT_FrSyn<<1)|INT_FiCnt;//|(FIWSEL<<2);
	rLCDLPCSEL=0;
	rTPAL=(0<<24);	    
	for(i=0;i<640*480;i++)
		//*(pLCDBuffer161+i)=0xffff;
		*(pLCDBuffer16I1+i)=0x0;					
	//hudelay(5000);	
    rLCDCON1+=LCDCON1_ENVID;	
  
}

void LCD_Refresh()
{
	int i,j;
	U32 lcddata;
	U16 pixcolor;	//一个像素点的颜色	
	U8* pbuf=(U8*)LCDBufferII2[0];
	U32 LCDBASEU,LCDBASEL,LCDBANK;
	for(i=0;i<LCDWIDTH*LCDHEIGHT;i++){	
			pixcolor=((pbuf[0]&0xf8)<<11)|((pbuf[1]&0xfc)<<6)|(pbuf[2]&0xf8);	//变换RGB		
			pbuf+=4;	
		    //LCDBufferII1[i]=pixcolor;
		    *(pLCDBuffer16I2+i)=pixcolor;
	}
	
	//for(i=0;i<LCDWIDTH*LCDHEIGHT;i++)
	//*(pLCDBuffer16I2+i)=LCDBufferII1[i];
	
	LCDBANK=0x32096000>>22;
	LCDBASEU=(0x32096000<<9)>>10;	  
	LCDBASEL=LCDBASEU+(480)*640;
	//rLCDADDR1=0x33000000>>1;
	rLCDADDR1= (LCDBANK<<21)|LCDBASEU;    
	rLCDADDR2=LCDBASEL;	
	rLCDADDR3= (640)|(0<<11);
}
void drawstripe(int row_num)
{
	int i;
	unsigned short *tmp = (unsigned short *)LCD_MEM_BASE;
	if(row_num>=0&&row_num<15)
	for(i=0,tmp+=row_num*320*16;i<320*16;i++,tmp++) 
		*tmp=0xffff;
	return;
}

void convertstripe(int row_num)
{
	int i;
	unsigned short *tmp = (unsigned short *)LCD_MEM_BASE;
	if(row_num>=0&&row_num<15)
	for(i=0,tmp+=row_num*320*16;i<320*16;i++,tmp++)
		*tmp=(*tmp)^0xffff;
	return;
}


static void drawpixel(int x, int y, unsigned short color_mask)
{
	unsigned int bits = (SCREEN_WIDTH*y+x)*BITS_PER_PIXEL;
	unsigned char *tmp;

	unsigned short mask_high = 0xff00&color_mask;
	unsigned short mask_low  = 0x00ff&color_mask;
	
	tmp = (unsigned char *)LCD_MEM_BASE+bits/8;
	mask_high>>=8;
	
	

	if (bits%8)
	{
		*tmp = (0xff&mask_low);
		tmp ++;
		*tmp = (0xff&mask_high);
	}else
	{
		*tmp = (0xff&mask_low);
		tmp ++;
		*tmp = (0xff&mask_high);
	}

	return;
}

void drawchar(unsigned char c,unsigned short color_mask)
{
	unsigned short *p = helvB12_bits+(c-0x20)*14;
	int i,j;
	int x, y;
	
	if (c == '\n')
	{
		flag++;
		cur_x = 0;
		cur_y += LINE_HEIGHT;
		if ((cur_y+6) >= SCREEN_HEIGHT)
			//clearscreen();
			up_a_line_screen();
		return;
	}
	if (c == '\t' || c == '\r')
	{
		cur_x = 0;
		return;
	}

	if (cur_x+CHAR_WIDTH >= SCREEN_WIDTH)
	{
		cur_x = 0;
		cur_y += LINE_HEIGHT;
		if ((cur_y+6) >= SCREEN_HEIGHT)
			//clearscreen();
			up_a_line_screen();
	}

	x = cur_x; y = cur_y;

	for (i=0;i<CHAR_HEIGHT;i++)
	{
		unsigned short tmp = p[i];

		for (j=0;j<CHAR_WIDTH;j++)
		{
			if (tmp & 0x8000)
			{
				drawpixel(x+j,y+i*2,color_mask);	
				drawpixel(x+j,y+i*2+1,color_mask);	
			}
			tmp = tmp << 1;
		}
	}
	
	cur_x += helvB12_width[c-0x20] + 1;
	
	return;
}
#ifdef GB16
void drawgb(unsigned short g,unsigned short color_mask)
{
	unsigned char c1=(g&0xff)-0xa1, c2=((g&0xff00)>>8)-0xa1;
	unsigned short *p = gb16x16song_bits+(c1*94+c2)*16;

	int i,j,x, y;
	
	if (cur_x+16 > SCREEN_WIDTH)
	{
		cur_x = 0;
		cur_y += 16;
		if (cur_y > SCREEN_HEIGHT)
			clearscreen();
			
	}

	x = cur_x; y = cur_y;

	for (i=0;i<16;i++)
	{
		unsigned short tmp = p[i];

		for (j=0;j<16;j++)
		{
			if (tmp & 0x8000)
				drawpixel(x+j,y+i,color_mask);		
			tmp = tmp << 1;
		}
	}
	
	cur_x += 16;
	
	return;
}
#endif

void drawstring(char *s,unsigned short color_mask)
{
	unsigned char *tmp = (unsigned char *)s;
	
	while (*tmp)
	{
		if(*tmp >= 0xa1)
		{
#ifdef GB16
			drawgb(*((unsigned short *)tmp),color_mask);
			tmp += 2;
#endif
		}
		else		
		{
			drawchar(*tmp,color_mask);
			tmp ++;
		}
	}
	
	return;
}

void drawversion(int row_num)
{
	static int old_x,old_y;
	if(row_num>=0&&row_num<15)
	{
		old_x=cur_x;old_y=cur_y;
		cur_x=160;cur_y=224;
		drawstring("JL-BSP version 2.00",0xffff);
		cur_x=old_x;cur_y=old_y;
	}
	return;
}



void drawlogo(void)
{
#if 1
	int i,j;
	unsigned int *p1=(unsigned int *)LCD_MEM_BASE;

	j=320*240*2/4;
	for(i=0; i<j; i++)
	{
		p1[i]=0x1f001f;
		
	}

#endif

#if 0
	int i,j;
	unsigned int *p1=(unsigned int *)LCD_MEM_BASE;
	unsigned int *s1=(unsigned int *)kjbmp0_color;
	j=30*320;
	for(i=0; i<3*j; i++)
	{
		p1[i]=s1[i];
	}	
	
	for(i=3*j; i<4*j; i++)
	{
  		 p1[i]=s1[i];
	}	
	
#endif

	rLCDCON1=0|LCDCON1_BPPMODE|LCDCON1_PNRMODE|LCDCON1_MMODE|LCDCON1_CLKVAL|LCDCON1_ENVID;

}

void clearscreen(void)
{
	int i, n;
	unsigned long *tmp;
	unsigned long offset;
	
	n = SCREEN_WIDTH*SCREEN_HEIGHT*BITS_PER_PIXEL/32;
	tmp = (unsigned long *)LCD_MEM_BASE;
	offset = SCREEN_WIDTH*LINE_HEIGHT*BITS_PER_PIXEL/32;

	for (i=0;i<n+(int)offset;i++)
		*tmp++ = 0x1f001f;
	
	//cur_x = cur_y = 0;
	cur_x = 0;
	cur_y = SCREEN_HEIGHT-LINE_HEIGHT-6;

	return;
}
void up_a_line_screen(void)
{
	int i, n;
	unsigned long offset;
	unsigned long *tmpnew;
	unsigned long *tmp;

	offset = SCREEN_WIDTH*(LINE_HEIGHT)*BITS_PER_PIXEL/32;
	n = SCREEN_WIDTH*SCREEN_HEIGHT*BITS_PER_PIXEL/32;
	tmpnew = (unsigned long *)LCD_MEM_BASE;
	tmp = (unsigned long *) LCD_MEM_BASE+offset;
	
	for (i=0;i<n;i++)
		*tmpnew++ = *tmp++;
	for (i=n;i<n+offset;i++)
		*tmpnew++=0x1f001f;
	
	cur_x =  0;
	cur_y = SCREEN_HEIGHT-LINE_HEIGHT-6;
	
	return;
}

/*void Screen_GetString(int whichUart, char *string)
{
    char *string2=string;
    char c;
    while((c=Uart_Getch(whichUart))!='\r')
    {
		if(c=='\b')
		{
		    if(	(int)string2 < (int)string )
		    {
				Uart_Printf(whichUart,"\b \b");
				string--;
				DelChar(*string);
		    }
		}
		else 
		{
		    *string++=c;
		    Uart_SendByte(whichUart,c);
		    drawchar(c,0x7e0);
		}
    }
    *string='\0';
    Uart_SendByte(whichUart,'\r');
    Uart_SendByte(whichUart,'\n');
    drawstring("\n",0xffe0);
    
}*/
void DelChar(char c)
{
	if (cur_x>0)
	{
		cur_x = cur_x - ( helvB12_width[c-0x20]+1);
		drawchar(c,0x1f001f);//  用背景色显示???
		//drawchar(c,0x1f);
		cur_x = cur_x - ( helvB12_width[c-0x20]+1);
	}
}

void drawline(int x,int y,int length,int flag,unsigned short color_mask)
{
	int i;
	
	if (flag)
		for (i=0;i<length;i++)
			drawpixel(x+i,y,color_mask);
	else
		for (i=0;i<length;i++)
			drawpixel(x,y+i,color_mask);
	/*for (i=0;i<length;i++)
	{
		drawpixel(x+length/2,y-length/2+i,color_mask);
	}*/
	
}
void draw_char(int x,int y,unsigned char c,unsigned short color_mask)
{
	int i,j,t;
	unsigned short *p = helvB12_bits+(c-0x20)*14;
	
	for (i=0;i<CHAR_HEIGHT;i++)
	{
		unsigned short tmp = p[i];

		for (j=0;j<CHAR_WIDTH;j++)
		{
			if (tmp & 0x8000)
			{
				/*drawpixel(x+j,y+i*2,color_mask);	
				drawpixel(x+j,y+i*2+1,color_mask);*/
					
				/*drawpixel(x+j*2,y+i*2,color_mask);	
				drawpixel(x+j*2,y+i*2+1,color_mask);	
				drawpixel(x+j*2+1,y+i*2,color_mask);
				drawpixel(x+j*2+1,y+i*2+1,color_mask);*/
				for (t=0;t<4;t++)
				{
					drawpixel(x+j*4+t,y+i*4,color_mask);	
					drawpixel(x+j*4+t,y+i*4+1,color_mask);	
					drawpixel(x+j*4+t,y+i*4+2,color_mask);	
					drawpixel(x+j*4+t,y+i*4+3,color_mask);	
				}
			}
			tmp = tmp << 1;
		}
	}
}


void draw_keyboard(void)
{
	int i;
	
	for (i=0;i<5;i++)
	{
		drawline(80,80+i*80,480,1,0xffff);
		drawline(80,81+i*80,480,1,0xffff);
	}
	for (i=0;i<5;i++)
	{
		drawline(80+i*120,80,320,0,0xffff);
		drawline(81+i*120,80,320,0,0xffff);
	}
	for (i=0;i<3;i++)
	{
		draw_char(80+46+i*120,80+12,'1'+i,0x7e0);
		draw_char(80+46+i*120,160+12,'4'+i,0x7e0);
		draw_char(80+46+i*120,240+12,'7'+i,0x7e0);
	}
	
	draw_char(80+46,320+12,'0',0x7e0);
	draw_char(200+48,320+24,'*',0x7e0);
	draw_char(320+44,320+12,'#',0x7e0);
	
	for (i=0;i<4;i++)
	{
		draw_char(440+32,80+12+i*80,'F',0xf800);
		draw_char(440+60,80+12+i*80,'1'+i,0xf800);
	}
}

void draw_charline(unsigned char c,unsigned short color_mask)
{
	int i,j,n,x,y;
	unsigned long offset,*tmpnew;
	unsigned short *p = helvB12_bits+(c-0x20)*14;
	
	offset = SCREEN_WIDTH*(LINE_HEIGHT)*BITS_PER_PIXEL/32;
	n = SCREEN_WIDTH*(SCREEN_HEIGHT-LINE_HEIGHT-6)*BITS_PER_PIXEL/32;
	tmpnew = (unsigned long *)LCD_MEM_BASE;	
	for (i=0;i<n;i++) tmpnew++;
	
	if (c == '\n' || c == '\r')
	{
		cur_x = 0;
		cur_y += LINE_HEIGHT;
		return;
	}
	else 
	{
		if (cur_y>=SCREEN_HEIGHT-6)
		{
		for (i=n;i<n+offset;i++)
			*tmpnew++=0x1f001f;
		cur_x =  0;
		cur_y = SCREEN_HEIGHT-LINE_HEIGHT-6;
		}
		x=cur_x;y=cur_y;
		for (i=0;i<CHAR_HEIGHT;i++)
		{
			unsigned short tmp = p[i];

			for (j=0;j<CHAR_WIDTH;j++)
			{
				if (tmp & 0x8000)
				{
					drawpixel(x+j,y+i*2,color_mask);	
					drawpixel(x+j,y+i*2+1,color_mask);
				}
				tmp = tmp << 1;
			}
		}
		cur_x += helvB12_width[c-0x20] + 1;
		return;
	}
	
}



void draw_stringline(char *s,unsigned short color_mask)
{
	unsigned char *tmp = (unsigned char *)s;
	
	while (*tmp)
	{
		draw_charline(*tmp,color_mask);
		tmp ++;	
	}
}

⌨️ 快捷键说明

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