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

📄 lcdlib.c

📁 S3C2410上RS485驱动源码,用ADS1.2编译工程,已测试通过.内附文档.
💻 C
📖 第 1 页 / 共 2 页
字号:
*/
void DrawFrame(int xS, int yS, int xE, int yE, int width, COLOR mcolor)
{
	while(width)
	{
		width--;
		
		line(xS + width, yS + width, xE - width, yS + width, mcolor);
		line(xE - width, yS + width, xE - width, yE - width, mcolor);
		line(xE - width, yE - width, xS + width, yE - width, mcolor);
		line(xS + width, yE - width, xS + width, yS + width, mcolor);
	}
}

//取返色函数
void fillreverserectangle(int x0,int y0,int x1,int y1)
{
	int x,y;
	COLOR mcolor;
	
	if (x0 > x1)
	{	
		x = x0;
		x0 = x1;
		x1 = x;
	}
	if (y0 > y1)
	{	
		y = y0;
		y0 = y1;
		y1 = y;
	}
	
	for(x=x0;x<=x1;x++)
	   for(y=y0;y<=y1;y++)
	   {
	   	mcolor = getpixel(x,y);
	    setpixel(x,y,~mcolor);
	   }
}

void ascii_168(int x0,int y0,char *code,int zoom,int pencolor)
{
	char mask[]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};		// 掩码
	char mat[16];											// 字模数组
	char *charPos;								// 该字模的物理地址
	int offset;									// 该字模在字库中的位置
	int i,j;									// 循环控制变量
	
	offset = (*code) * 16;						// 求出该字模在字库的位置
	charPos = (char *)(asciibufbase + offset);	// 求出字模的物理地址
	
	memcpy(mat, charPos, 16);					// 字模复制到字模数组 mat[] 中
	
	// 在LCD上显示ASCII字符
	for (i=0; i<16; i++)
		for (j=0; j<8; j++)
			if (mask[j%8] & mat[i])
				setpixel(x0+zoom*j, y0-zoom*i, pencolor);
}

//写ASCII字符串函数
int drawascii168(int x0,int y0,char *c,int zoom,int space,int pencolor)             
{    
	int x,y,counter;
	x=x0;
	y=y0;
	counter=0;
	while(*c!='\0')    /*while don't reach to the end of the string*/
	{
		while(x<g_xMax && (*c!='\0'))   /*while the X coordinate don't exceed the scope of X limit*/
		{
			ascii_168(x,y,c,zoom,pencolor);  /*display the character*/
			x+=8*zoom+space;
			c+=1;
			counter+=1;
		}
        	x=0;  /*exchange the next row*/                                              
        	y+=16*zoom;
    }
     return(counter);
}       


void get_hz(int x,int y,char incode[],int zoom,int pencolor)                   
{	 
	char mask[]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};		// 掩码
	char mat[32];											// 字模数组
	char section,position;						// 区位码(section,区号;position,位号)
	char *chCharPos;							// 该字模的物理地址
	int offset;									// 该字模在字库中的位置
	int i,j,k;									// 循环控制变量

	section = incode[0] - 0xA0;					// 求出区号
	position = incode[1] - 0xA0;				// 求出位号
	offset = (94 * (section - 1) + (position - 1)) * 32;	// 求出该字模在字库的位置
	chCharPos = (char *)(hzbufbase + offset);				// 求出字模的物理地址

	memcpy(mat, chCharPos, 32);					// 字模复制到字模数组 mat[] 中

	// 在LCD上显示汉字
	for (i=0; i<16; i++)
		for (j=0; j<2; j++)
			for (k=0; k<8; k++)
				if (mask[k%8] & mat[2*i+j])
					setpixel(x+zoom*(8*j+k), y-zoom*i,pencolor);
}

 //写汉字函数 
int drawtext(int x,int y,char *c,int zoom,int space,int pencolor)             
{
	int counter = 0;						// 计算已显示汉字的数量
	
	// 如果遇到字符串结束符就结束显示汉字
	while(*c!='\0')
	{
		// 如果汉字坐标不超过LCD界限就显示
		while(x<g_xMax && (*c!='\0'))
		{
			get_hz(x,y,c,zoom,pencolor);  // 在LCD上显示汉字
			x += 16 * zoom + space;		// 下一个汉字的x坐标
			c += 2;							// 指向下一个汉字(一个汉字占两个字节)
			counter += 1;					// 显示汉字计数
		}
			x = 0;							// 换行后的x坐位
			y += 32 * zoom;				// 换行后的y坐位
	}
	
	return(counter);						// 返回已显示汉字数量
}

int drawletter(int x0,int y0,char *c,int zoom,int space,int pencolor)
{
	int x,y,counter,ag = 0;
	x=x0;
	y=y0;
	counter=0;
	while (*c!='\0')
	{
		/*if don't reach to the end of the string display the character in LCD*/
		while (x<g_xMax && (*c!='\0'))
		{
			if ((*c <= 0x7f) && ( *c > 0 ))
			{
				if (ag == 1)
				{
					x++;
					ag = 0;
				}
				ascii_168(x, y-2, c, zoom, pencolor);  /*display the character*/
				x += 8*zoom + space;
				c++;
				counter++;
			}
			else
			{
				if (ag == 0)
				{
					x++;
					ag = 1;
				}
				get_hz(x, y, c, zoom, pencolor);  /*display the Chines character*/
				x += 16*zoom + space;
				c += 2;
				counter++;
			}
		}
        	x=0;                                                
        	y+=32*zoom;
     }
     return counter;	
}



int Rewriteletter(int x0,int y0,char *c,int zoom,int space,int pencolor,int colorin)
{
	int x,y,i,k,counter,ag = 0;
	x=x0;
	y=y0;
	counter=0;
	while (*c!='\0')
	{
		/*if don't reach to the end of the string display the character in LCD*/
		while (x<g_xMax && (*c!='\0'))
		{
			if ((*c <= 0x7f) && ( *c > 0 ))
			{
				if (ag == 1)
				{
					for (i=0; i<(zoom*16); i++)
			  		{
			  			setpixel(x,y-i,colorin);
		 	   		}
					x++;
					ag = 0;
				}
				
				for (i=0; i<(zoom*16); i++)				//填色
			  	{
			  		for (k=0; k<(zoom*8); k++)
			  		{
			  			setpixel(x+k,y-i,colorin);
		 	   		}
		 	   	}
				ascii_168(x, y-2, c, zoom, pencolor);  /*display the character*/
				
				x += 8*zoom;
				for (k=0; k<(zoom*space); k++)				//填色
			  	{
			  		for (i=0; i<(zoom*16); i++)
			  		{
			  			setpixel(x+k,y-i,colorin);
		 	   		}
		 	   	}
				x += space;
				c++;
				counter++;
			}
			else
			{
				if (ag == 0)
				{
					for (i=0; i<(zoom*16); i++)
			  		{
			  			setpixel(x,y-i,colorin);
		 	   		}
					x++;
					ag = 1;
				}
				for (i=0; i<(zoom*16); i++)				//填色
			  	{
			  		for (k=0; k<(zoom*16); k++)
			  		{
			  			setpixel(x+k,y-i,colorin);
		 	   		}
		 	   	}
				
				get_hz(x, y, c, zoom, pencolor);  /*display the Chines character*/
				x += 16*zoom;
				for (k=0; k<(zoom*space); k++)				//填色
			  	{
			  		for (i=0; i<(zoom*16); i++)
			  		{
			  			setpixel(x+k,y-i,colorin);
		 	   		}
		 	   	}
				x += space;
				c += 2;
				counter++;
			}
		}
        	x=0;                                                
        	y+=32*zoom;
     }
     return counter;	
}

/*	c:The written data
/	TextColor: The color of data
/	x_start:开始点x坐标
/	y_start:开始点y坐标
/	x_end:结束点x坐标
/	y_end:结束点y坐标
/	EditID:ID号					
/	'$'代表换行
*/
void PrintTextEdit(char *c,int pencolor,int x_start,int y_start,int x_end,int y_end,int EditID)
{
	int ag = 0;
#ifndef	STN
	int i,j;
#endif	
	
	if (TextEdit_id != EditID)
	{
		TextEdit_x = x_start;
		TextEdit_y = y_start;
		TextEdit_id = EditID;
	} 
	
	while (*c!='\0')
	{
		/*if don't reach to the end of the string display the character in LCD*/
#ifdef	STN
		if(TextEdit_y <= (y_end+16))
		{
			TextEdit_y = y_start;
			fillrectangle(x_start,y_start,x_end,y_end,RGB(140,140,255));
		}	
#else
		if(TextEdit_y < (y_end+32))
		{
			if (mGuiOrientation == GUI_HORIZONTAL)
			{
				for(j = y_start; j >= TextEdit_y;j--)
					for(i = x_start; i < x_end; i++)
					{
						*(short *)(VideoAddrStart+(i*g_yMax+j)*2) = *(short *)(VideoAddrStart+(i*g_yMax+j-16)*2);
					}
			}
			else
			{
				for(j=y_start; j>=TextEdit_y; j--)
					for(i=x_start; i<x_end; i++)
						*(short *)(VideoAddrStart+(((g_yMax-j)*g_xMax+i)<<1)) = *(short *)(VideoAddrStart+(((g_yMax-j+16)*g_xMax+i)<<1));
			}
			TextEdit_y += 16;	
		}
#endif
		
			
		while ( (*c!='\0') && (*c!='$') )
		{
			if ((*c <= 0x7f) && ( *c > 0 ))
			{
				if (TextEdit_x >= (x_end-8))
					goto nextline;
					
				if (ag == 1)
				{
					TextEdit_x++;
					ag = 0;
				}
				ascii_168(TextEdit_x, TextEdit_y-2, c, 1, pencolor);  /*display the Ascii character*/
				TextEdit_x += 8;
				c++;
			}
			else
			{
				if (TextEdit_x >= (x_end-16))
					goto nextline;
				
				if (ag == 0)
				{
					TextEdit_x++;
					ag = 1;
				}
				get_hz(TextEdit_x, TextEdit_y, c, 1, pencolor);  /*display the Chines character*/
				TextEdit_x += 16;
				c += 2;
			}
		}
		
		if ((*c == '$'))
		{
			c++ ; 
nextline:
			TextEdit_y -= 16;
    		TextEdit_x = x_start;		   /* exchange the next row */
		}
		
     }
}


//风格函数
void WIN_WaterTek(char *ch)
{
	clrsrc(RGB(130,130,240));
#ifdef STN
	fillrectangle(0,0,640,30,RGB(0,0,128));
	fillrectangle(0,450,640,480,RGB(0,0,128));
	drawascii168(230,21,"www.watertek.com",1,1,RGB(255,255,255));
	drawletter(15,472,ch,1,0,RGB(255,255,255));

#else
	fillrectangle(0,0,g_xMax,30,RGB(0,0,128));
	fillrectangle(0,g_yMax-30,g_xMax,g_yMax,RGB(0,0,128));
	drawascii168((g_xMax-140)/2,21,"www.watertek.com",1,1,RGB(255,255,255));
	drawletter(15,g_yMax-8,ch,1,0,RGB(255,255,255));
#endif

}

int LcdOrientation(void)
{
	if(mGuiOrientation == GUI_VERTICAL)
	{
		LcdHorizontal();
	}
	else
	{
		LcdVertical();
	}
	return mGuiOrientation;
}

void LcdVertical(void)
{
	mGuiOrientation = GUI_VERTICAL;
	g_xMax = 240;
	g_yMax = 320;
}

void LcdHorizontal(void)
{
	mGuiOrientation = GUI_HORIZONTAL;
	g_xMax = 320;
	g_yMax = 240;
}

//void LcdOrientationInit(void)
//{
//	mGuiOrientation = GUI_VERTICAL;
//	g_xMax = 240;
//	g_yMax = 320;
//}

⌨️ 快捷键说明

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