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

📄 lcdlib.c

📁 嵌入式开发中的一些图形函数与汉字处理程序
💻 C
📖 第 1 页 / 共 2 页
字号:
			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 Glib_ClearScr(U8 c)
{	
    //Very inefficient function.
    
    int i,j;
	
    for(j=0;j<SCR_YSIZE;j++)
    	for(i=0;i<SCR_XSIZE;i++)
	    PutPixel(i,j,c);
}

/************display one chinese character(16*16)***************/
void Chinese_input(U32 x,U32 y,U8 c,U16 * chinese)
{U16 a,b,i,j;

 for(i=0;i<16;i++)
    {
     b=*(chinese+i);
     for(j=0;j<16;j++)
        {
	a=(b)&(1);
	b=b>>1;
	if(a==1) PutPixel(x+16-j,y+i,c);
	else PutPixel(x+16-j,y+i,0);
	}
    }	
}
void Button_Chinese_input(U32 x,U32 y,U8 c,U16 * chinese)
{U16 a,b,i,j;

 for(i=0;i<16;i++)
    {
     b=*(chinese+i);
     for(j=0;j<16;j++)
        {
	a=(b)&(1);
	b=b>>1;
	if(a==1) PutPixel(x+16-j,y+i,c);
	}
    }	
}
/************display one chinese character(24*24)***************/
void Chinese_input24(U32 x,U32 y,U8 c,U32 * chinese)
{U8 a,i,j;
 U32 b;

 for(i=0;i<24;i++)
    {
     b=*(chinese+i);
     for(j=0;j<24;j++)
        {
	a=b&(1);
	b=b>>1;
	if(a==1) PutPixel(x+24-j,y+i,15-c);
	else PutPixel(x+24-j,y+i,15);
	}
     }	
}
/********************** show a english or number character******************/
void English_input(U32 x,U32 y,U8 c,U16 * Engcharacter)          //8*16
{U16 a,b,i,j;

 for(i=0;i<8;i++)
    {
     b=*(Engcharacter+i);
     for(j=0;j<16;j++)
        {
	a=(b)&(1);
	b=b>>1;
	if(a==1) PutPixel(x+8-i,y+16-j,c);
	else PutPixel(x+8-i,y+16-j,0);
	}
    }	
}
void Button_English_input(U32 x,U32 y,U8 c,U16 * Engcharacter)          //8*16
{U16 a,b,i,j;

 for(i=0;i<8;i++)
    {
     b=*(Engcharacter+i);
     for(j=0;j<16;j++)
        {
	a=(b)&(1);
	b=b>>1;
	if(a==1) PutPixel(x+8-i,y+16-j,c);
	}
    }	
}
/*****************show bmp******************/
void Show_Bmp(U32 x,U32 y,U8 c)
{int a,b,i,j,k;
 U16 (*p)[4];
 p=Nwbmp;
 for(j=0;j<51;j++)
    {for(k=3;k>=0;k--)
        {b=*(*(p+j)+k);//Nwbmp[j][k];
	for(i=0;i<16;i++)
	   {a=(b)&(1);
	    b=b>>1;
	    if(a==1) PutPixel(x+15-i+16*k,y+j,c);
	    else PutPixel(x+15-i+16*k,y+j,0);
	   }
	}
     }
}
 
/*************************Out Button **************************/
void Button(U32 x1,U32 y1,U32 x2,U32 y2)
{	Glib_FilledRectangle(x1+2,y1+2,x2-2,y2-2,BlackGray);
	Glib_Line(x1,y1,x1,y2,BlackGray-2);
	Glib_Line(x1,y1,x2,y1,BlackGray-2);
	Glib_Line(x2,y1,x2,y2,BlackGray+4);
	Glib_Line(x1,y2,x2,y2,BlackGray+4);
	Glib_Line(x1+1,y1+1,x1+1,y2-1,BlackGray-2);
	Glib_Line(x1+1,y1+1,x2-1,y1+1,BlackGray-2);
	Glib_Line(x2-1,y1+1,x2-1,y2-1,BlackGray+4);
	Glib_Line(x1+1,y2-1,x2-1,y2-1,BlackGray+4);
}


/********************location a chinese character*************************/
U16 * LCD_GetCnFont(U8* ptr8)
{
	U16 * ptr16;
	U16 i;
	U16 * ptrA;

	ptr16 = (U16 *)ptr8;
	ptrA = (U16 *)cnTxtTbl;

	for (i=0; *(ptrA+i) != 0; i++) {
		if (*(ptrA + i) == *ptr16)		
			return (U16 *)ziku0[i];
	}
	return (U16 *)0;
}

/************
style can be one of the followed prometer:OVERLAY =0;AND=1 ;OR=2; XOR=3
***********************/
void LCD_TextOut(U16 x, U16 y,U8 style,U8 c, const char *format,...)
{	int i;
	va_list v_list;
	U8 *ptr;
	char tbuf[256];

	va_start(v_list, format);     	// Initialize variable arguments. 
	vsprintf(tbuf, format, v_list ); 
	va_end(v_list);

	ptr= (U8 *)tbuf;
	for(i=0;ptr[i]!=0; )
		if(ptr[i]>=0x20)
		{
		 if(ptr[i]>127)
			{if(x>304){x=0;y+=16;}
			 if(LCD_GetCnFont((U8 *)(&ptr[i])))
				{if(style==OVERLAY) 
					Chinese_input(x,y,c,LCD_GetCnFont((U8 *)(&ptr[i])));
				 else if(style==OR)
					Button_Chinese_input(x,y,c,LCD_GetCnFont((U8 *)(&ptr[i])));

				}
			 x+=16;
			 i+=2;
			}
		 else if(ptr[i]<127)
		     { if(x>312){x=0;y+=16;}
			if(style==OVERLAY)English_input(x,y,c,ziku1[ptr[i]-0x20]);
			else if(style==OR)Button_English_input(x,y,c,ziku1[ptr[i]-0x20]);

			x+=8;
			i++;
		     }
		}
}


void LcdOutputFloat(U16 x,U16 y,U8 c,float f)
{char Freq[6];
 U8 a,i;
 U16 f1;
 f1=(U16)(f*100);
 for(i=0;i<5;i++)
	{a=(U8)(f1%10);
	 f1/=10;
	 Freq[5-i]=a+16;
	}
 Freq[0]=Freq[1];
 Freq[1]=Freq[2];
 Freq[2]=Freq[3];
 Freq[3]=14;

 for(i=0;i<6;i++)
	English_input(x+8*i,y,15,ziku1[Freq[i]]) ;
}

void LcdOutputNum(U16 x,U16 y,U8 c,S16 N)
{U8 Freq[6];
 U8 i,a;
 S16 Num;
 if(N<0){Freq[0]=13;
	Num=~N+1;}
 else {Num=N;  
	Freq[0]=0;}
 for(i=0;i<5;i++)
	{a=(U8)(Num%10);
	 Num/=10;
	 Freq[5-i]=a+16;
	}
 for(i=0;i<6;i++)
	English_input(x+8*i,y,15,ziku1[Freq[i]]) ;
 LCD_TextOut(x-32,y,OVERLAY,15,"Num:");
}

/***********************test lcd screen***********************/
void Show_Screen(U8 scrnum)
{U8 i;
 int LcdBuffer=0;
 U16 (*ch)[16];
 U16 (*en)[8];
 ch=ziku0;
 en=ziku1;
  if(M5D(rLCDSADDR1)!=M5D((U32)frameBuffer16>>1)) LcdBuffer=0;
 	//because the second lcd buffer have been used,so let lcdbuffer equal 0;
 else LcdBuffer=240;//let lcdbuffer =240;
       
  Glib_FilledRectangle(0,24+LcdBuffer,319,186+LcdBuffer,0);
//		LcdOutputFloat(128,200+LcdBuffer,15,(float)GetTouchX());
//		LcdOutputFloat(248,200+LcdBuffer,15,(float)GetTouchY());

 switch(scrnum)
	{case 0: Button(77, 85+LcdBuffer,227,107+LcdBuffer);
		LCD_TextOut(80,88+LcdBuffer,OR,15,"Waveform");

		Button(77, 145+LcdBuffer,227,167+LcdBuffer);
		LCD_TextOut(80,148+LcdBuffer,OR,15,"Programer:  Y Chen");
		Lcd_MoveViewPort(0,LcdBuffer);
		break;
	case 1:  Button(270, 145+LcdBuffer,310,167+LcdBuffer);
		LCD_TextOut(272,147+LcdBuffer,OR,15,"Back");
		LCD_TextOut(16,64+LcdBuffer,OVERLAY,15,"Chen Yun(1978-?): Post-graduate in Electric and electronic Department,Zhejiang Universty.");

		Lcd_MoveViewPort(0,LcdBuffer);
		break;
	case 2:  Button(270, 145+LcdBuffer,310,167+LcdBuffer);
		LCD_TextOut(272,147+LcdBuffer,OR,15,"Back");

		Lcd_MoveViewPort(0,LcdBuffer);
		break;
	case 3:  break;
	}

} 

void Show_corporationname(U8 LcdBuffer)
{
 U16 (*ch)[16];
 U16 (*en)[8];
 ch=ziku0;
 en=ziku1;   
	//Show_Bmp(0,189+LcdBuffer,15);
	//LCD_TextOut(72,192+LcdBuffer,OVERLAY,15,"杭州BingHeRTOS有限公司");
	//LCD_TextOut(64,110+LcdBuffer,OVERLAY,15,"UC/OS-2 IS RUNING NOW!");
	//LCD_TextOut(64,220+LcdBuffer,OVERLAY,15,"Hangzhou BingheRTOS Corporation");
         LCD_TextOut(8,8+LcdBuffer,OVERLAY,15,"文件");
         LCD_TextOut(50,8+LcdBuffer,OVERLAY,15,"编辑");
         LCD_TextOut(92,8+LcdBuffer,OVERLAY,15,"视图");
         LCD_TextOut(132,8+LcdBuffer,OVERLAY,15,"工具");
         LCD_TextOut(180,8+LcdBuffer,OVERLAY,15,"帮助");	 
         Glib_FilledRectangle(280,31,309,234,BlackGray+6);
         Button(282,50,307,90);

         Glib_Line(5,5,310,5,BlackGray+8);
         Glib_Line(5,5,5,30,BlackGray+8);
         Glib_Line(5,30,310,30,BlackGray+8);
         Glib_Line(310,5,310,30,BlackGray+8);
        
          Glib_Line(5,30,5,235,BlackGray+8);
          Glib_Line(5,235,310,235,BlackGray+8);
          Glib_Line(310,235,310,30,BlackGray+8);
          LCD_TextOut(10,100+LcdBuffer,OVERLAY,15,"浙江工程学院陈仲信");
          Button(10,35,40,50);
          Button(50,35,80,50);
          Button(90,35,120,50);
}
















⌨️ 快捷键说明

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