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

📄 gui12864.c

📁 AVR单片机驱动128×64LCD实现3D图像的旋转显示
💻 C
字号:
/***********************************************************************************************
*  FILE NAME: gui12864.c
*  PURPOSE: lcd1286418 GUI Firmware
*  DESCRIPTION: ONLY FOR 128*64 PIXEL LCD 
*  DEVELOPMENT HISTORY:
*    Date         Author         Release                   Description Of Change
*  --------    ------------     ---------     ------------------------------------------------
*  08-04-11     XuGuohong         1.0                        Testing Edition    	     
/**********************************************************************************************/

/* Include Global Parameters */
#include <iom128v.h>
#include "avr.h"
#include "gui12864.h"

/* Include Global Parameters */


/* Declare Prototypes */
void GuiDrawLine(unsigned char,unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDrawCircle(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDrawSquare(unsigned char,unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisCharF3(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisStringF3(unsigned char,unsigned char,unsigned char *,unsigned char);
//void GuiDisCharF2(unsigned char,unsigned char,unsigned char,unsigned char);
//void GuiDisCharF1(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisLogo(unsigned char);
void GuiDisRoolStringF3(unsigned char,unsigned char,unsigned char,unsigned char *,unsigned char);
void GuiDisBattery(unsigned char,unsigned char,unsigned char);
void GuiDisUsb(unsigned char,unsigned char);
void GuiDisAcin(unsigned char,unsigned char);
void GuiDisTemp(unsigned char,unsigned char,signed char);
void GuiDisShortIcon(unsigned char,unsigned char,unsigned char);
void GuiDisMainMenu(void);
void GuiDisMenuIcon(unsigned char,unsigned char,unsigned char);

/*****************************************
*  FUNCTION NAME: GuiDrawLine
*  DESCRIPTION: Draw A Line From Between
*               Any 2-Point
*  (x1,y1) as start point
*  (x2,y2) as end point
*  Based On "Breshenham Line"
/*****************************************/
void  GuiDrawLine(unsigned char  x1, unsigned char  y1, unsigned char  x2, unsigned char  y2, unsigned char color) 
{
    unsigned char temp;
	int p;	   		 	 		 	 		 /* p-取值判断因子 */
	unsigned char x;						 /* x-坐标 */
	unsigned char y;						 /* y-坐标 */
	int dx;						             /* x方向差值 */
	int dy;						             /* y方向差值 */
	char signx;	  							 /* x方向标识 */
	char signy;								 /* Y方向标识 */
    if(x1>123 | y1>63 | x2>123 | y2>63)
	    return;
	x = x1;
	y = y1;
	 /* 1.计算X方向的参数 */
	if(x2 > x1)								
	{
	    dx = x2 - x1;	
		signx = 1;					 
	}
	else if(x2 < x1)
	{
	    dx = x1 - x2;	
		signx = -1;					 
	}
	else
	{
	    dx = 0;	
		signx = 0;					 
	}
	 /* 2.计算Y方向的参数 */
	if(y2 > y1)								
	{
	    dy = y2 - y1;	
		signy = 1;					 
	}
	else if(y2 < y1)
	{
	    dy = y1 - y2;	
		signy = -1;					 
	}
	else
	{
	    dy = 0;	
		signy = 0;
	}
	/* 3.计算首个判断因子 */
	p = 2*dy -dx;	
    /* 4a.以X方向增长画图 */				 		 
	if(dx >= dy)								
	{
		for(temp=0; temp<dx; temp++)
		{
	        LcdDisplayDot(x,y,color);		/* 画点 */
			if(p >= 0)						/* 根据P来判断画哪一点 */
			{
			    x = x + signx;
				y = y + signy;
				p = p + 2*(dy - dx);		/* dy,dx需要定义定义成有符号的,才能得到正确的值 */
			}
			else
			{
				x = x + signx;
				y = y;
				p = p + 2*dy;
			}
		}
    }
	else								
	{
		for(temp=0; temp<dy; temp++)
		{
	        LcdDisplayDot(x,y,color);		/* 画点 */
			if(p >= 0)						/* 根据P来判断画哪一点 */
			{
			    y = y + signy;
				x = x + signx;
				p = p + 2*(dx - dy);
			}
			else
			{
				y = y + signy;
				x = x;
				p = p + 2*dx;
			}
		}
    }
    LcdDisplayDot(x2,y2,color);		        /* 画最后一个点 */
}

/*****************************************
*  FUNCTION NAME: GuiDrawCircle
*  DESCRIPTION: Draw Circle
*  Based On "Breshenham Circle"
/*****************************************/
void GuiDrawCircle(unsigned char  x0, unsigned char  y0, unsigned char  r, unsigned char  color)
{ 
    int  draw_x0, draw_y0;                  /* 绘制图点坐标变量 */
    int  draw_x1, draw_y1;         
    int  draw_x2, draw_y2;         
    int  draw_x3, draw_y3;         
    int  draw_x4, draw_y4;         
    int  draw_x5, draw_y5;         
    int  draw_x6, draw_y6;         
    int  draw_x7, draw_y7;         
    int  xx, yy;                           /* 画圆控制变量 */ 
    int  di;                               /* 决策变量 */
    /* 参数过滤 */ 
    if(r==0) 
        return; 
   /* 计算出8个特殊点(0、45、90、135、180、225、270度),进行显示 */ 
   draw_x0 = draw_x1 = x0; 
   draw_y0 = draw_y1 = y0 + r; 
   LcdDisplayDot(draw_x0, draw_y0, color);                // 90度 
   draw_x2 = draw_x3 = x0; 
   draw_y2 = draw_y3 = y0 - r; 
   LcdDisplayDot(draw_x2, draw_y2, color);                // 270度 
   draw_x4 = draw_x6 = x0 + r; 
   draw_y4 = draw_y6 = y0; 
   LcdDisplayDot(draw_x4, draw_y4, color);                // 0度 
   draw_x5 = draw_x7 = x0 - r; 
   draw_y5 = draw_y7 = y0; 
   LcdDisplayDot(draw_x5, draw_y5, color);                // 180度    
   if(r==1) 
       return;                                            // 若半径为1,则已圆画完 

   /* 使用Bresenham法进行画圆 */ 
   di = 3 - 2*r;                                          // 初始化决策变量 
   xx = 0; 
   yy = r;         
   while(xx<yy) 
   { 
      if(di<0) 
      { 
         di += 4*xx + 6; 
      } 
      else 
      { 
         di += 4*(xx - yy) + 10; 
           
         yy--; 
         draw_y0--; 
         draw_y1--; 
         draw_y2++; 
         draw_y3++; 
         draw_x4--; 
         draw_x5++; 
         draw_x6--; 
         draw_x7++; 
      } 
           
      xx++; 
      draw_x0++; 
      draw_x1--; 
      draw_x2++; 
      draw_x3--; 
      draw_y4++; 
      draw_y5++; 
      draw_y6--; 
      draw_y7--; 
         
      /* 要判断当前点是否在有效范围内 */ 
      LcdDisplayDot(draw_x0, draw_y0, color); 
      LcdDisplayDot(draw_x1, draw_y1, color); 
      LcdDisplayDot(draw_x2, draw_y2, color); 
      LcdDisplayDot(draw_x3, draw_y3, color); 
      LcdDisplayDot(draw_x4, draw_y4, color); 
      LcdDisplayDot(draw_x5, draw_y5, color); 
      LcdDisplayDot(draw_x6, draw_y6, color); 
      LcdDisplayDot(draw_x7, draw_y7, color); 
   } 
} 

/*****************************************
*  FUNCTION NAME: GuiDrawSquare
*  DESCRIPTION: Draw Square
*  (x0,y0)----------------------------
*     |	 	      		 		      |
*	  |				 				  |
*	  | 		                      |					  
*	  |								  |
*	  |								  |
*      -----------------------------(x1,y1)
/*****************************************/
void GuiDrawSquare(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char color)
{
     GuiDrawLine(x0, y0, x0, y1, color);
	 GuiDrawLine(x0, y0, x1, y0, color);
	 GuiDrawLine(x0, y1, x1, y1, color);
	 GuiDrawLine(x1, y0, x1, y1, color);
}

/*****************************************
*  FUNCTION NAME: GuiDisCharF3
*  DESCRIPTION: Display ASCII Char
*      ---------------------------->
*     |	  	      x(0-20) 		      
*	  |				 				  
*	  | y(0-7) 		                      					  
*	  |								  
*	  |								  
/*****************************************/
void GuiDisCharF3(unsigned char x,unsigned char y,unsigned char data,unsigned char color)
{
    unsigned char temp,offset;
	offset = x * 6;		                     	  			   /* Display Place */
	for(temp=0; temp<6; temp++)
	{
	    if(color == 0)
		    LcdDisplaySeg(y,offset+temp,~font6x8[data-32][temp]);
		else
		    LcdDisplaySeg(y,offset+temp,font6x8[data-32][temp]);
	}
}

/*****************************************
*  FUNCTION NAME: GuiDisStringF3
*  DESCRIPTION: Display ASCII String
*      (x0,y0) display start place 
*      Auto Change Line...
*      ---------------------------->
*     |	  	      x(0-20) 		      
*	  |				 				  
*	  | y(0-7) 		                      					  
*	  |								  
*	  |								  
/*****************************************/
void GuiDisStringF3(unsigned char x0,unsigned char y0,unsigned char *p,unsigned char color)
{
	while(*p != 0x00)
	{
		if(x0 == 21)
		{
		    x0 = 0;
			y0 = y0+1;
		}
		GuiDisCharF3(x0,y0,*(p++),color);
		x0++;
	}
}

/*****************************************
*  FUNCTION NAME: GuiDisLogo
*  DESCRIPTION: Display One Full Screen
*               Picture 128X64...						  
/*****************************************/
void GuiDisLogo(unsigned char color)
{
    unsigned char x=0,y=0;
	unsigned int count=0;
	for(count=0;count<128*8;count++)
	{
	    if(x ==128)
		{
		    x = 0;
			y = y +1;
		}
		if(color == 0)
	        LcdDisplaySeg(y,x,~startlogo[count]);
		else
	        LcdDisplaySeg(y,x,startlogo[count]);  
		x++;	
	}
}

/****************************************************
*  FUNCTION NAME: GuiDisRoolStringF3
*  DESCRIPTION: Display One Line With  Left Rolling	
*      ---------------------------->
*     |	  	      x(0-127) 		      
*	  |				 				  
*	  | y(0-7) 		                      					  
*	  |								  
*	  |				  
/****************************************************/
void GuiDisRoolStringF3(unsigned char x0,unsigned char x1,unsigned char y,unsigned char *p,unsigned char color)
{
    unsigned int dislength = x1 - x0 + 1;	      	   			   /* 显示区域的宽度 */
	unsigned int textlength=0; 	   				  				   /* 要显示内容的总段数 */
	unsigned int totallength;			                           /* 要移动的总长度 */
	unsigned int step=0;					      				   /* 移动长度计数 */
	unsigned char n;							  				   /* 字库字偏移地址 */
	unsigned char a;							  				   /* 字库段偏移地址 */
	unsigned int temp1,temp2,temp3;
	unsigned int i;
	while(*(p+textlength) != 0x00)								   /* 计算显示内容的总段数 */
	{
	    textlength++;
	}
	textlength = textlength*6;
	totallength = dislength + textlength;						   /* 计算总移显示内容的长度 */
	for(i=0; i<totallength; i++)
	{
		step++;
		if(step <= dislength)
		{
		        for(temp1=0; temp1<step; temp1++)
			   {
			        if((temp1 +1) > textlength)
				    { 	
				        LcdDisplaySeg(y,x1+1-step+temp1,0x00);
				    }
					else
					{
					    LcdDisplaySeg(y,x1+1-step+temp1,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
						Delay10ms(10);
					} 
			    }
		}
		else if(step > textlength)
		{
		    temp2 = 0;
			for(temp1= step - dislength; temp1<step; temp1++)
			{
				if((temp1 +1) > textlength)
				{	
				    LcdDisplaySeg(y,x0 + temp2,0x00);
				} 
				else
				{	
				    LcdDisplaySeg(y,x0 + temp2,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
					Delay10ms(10);
				}
				temp2++;
			}
		}
		else
		{
			temp2 = 0;
			for(temp1= step - dislength; temp1<step; temp1++)
			{
				LcdDisplaySeg(y,x0 + temp2,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
				Delay10ms(10);
				temp2++;
			}
		}
	}
}

/************************************************************
*  FUNCTION NAME: GuiDisBattery
*  DESCRIPTION: Display Battery Icon
*       level- 0 warn,1 low,2 20%,3 40%,4 60%,5 80%,6 full
*       x - 0-112
*       y - 0-7		  
/************************************************************/
void GuiDisBattery(unsigned char x,unsigned char y,unsigned char level)
{
    unsigned char temp;
	for(temp=0; temp<16; temp++)
	{
	    LcdDisplaySeg(y,x+temp,battery[level][temp]);
	}
}

/************************************************************
*  FUNCTION NAME: GuiDisUsb
*  DESCRIPTION: Display USB Icon  
/************************************************************/
void GuiDisUsb(unsigned char x,unsigned char y)
{
    unsigned char temp;
	for(temp=0; temp<13; temp++)
	{
	    LcdDisplaySeg(y,x+temp,~usb[temp]);
	}
}

/************************************************************
*  FUNCTION NAME: GuiDisAcin
*  DESCRIPTION: Display AC Input Icon
/************************************************************/
void GuiDisAcin(unsigned char x,unsigned char y)
{
    unsigned char temp;
	for(temp=0; temp<6; temp++)
	{
	    LcdDisplaySeg(y,x+temp,acin[temp]);
	}
}


/************************************************************
*  FUNCTION NAME: GuiDisMainMenu
*  DESCRIPTION: Display MainMenu Square
/************************************************************/
void GuiDisMainMenu(void)
{
     unsigned char temp1;
	 for(temp1=0; temp1<128; temp1++)
     {
	     LcdDisplaySeg(0,temp1,0XFF);
		 LcdDisplaySeg(1,temp1,0X07);
	 }
	 GuiDrawSquare(0,0,127,54,1);
}

/************************************************************
*  FUNCTION NAME: GuiDisShortIcon
*  DESCRIPTION: Display Short-Cut Icon
*     0:
*     1:
*     2:
*     3:
*     4:
/************************************************************/
void GuiDisShortIcon(unsigned char x,unsigned char y,unsigned char type)
{
    unsigned char temp1,temp2;
	for(temp1=0; temp1<2; temp1++)
	{
	    for(temp2=0; temp2<16; temp2++)
		{
		    LcdDisplaySeg(y+temp1,x+temp2,~shorticon1[temp1][temp2]);		
		}
	}
}

/************************************************************
*  FUNCTION NAME: GuiDisMenuIcon
*  DESCRIPTION: Display MainMenu Name
/************************************************************/
void GuiDisMenuIcon(unsigned char x,unsigned char y,unsigned char type)
{
    unsigned char temp1,temp2;
	for(temp1=0; temp1<2; temp1++)
	{
	    for(temp2=0; temp2<34; temp2++)
		{
		    LcdDisplaySeg(y+temp1,x+temp2,~menuicon1[temp1][temp2]);		
		}
	}
}

/************************************************************
*  FUNCTION NAME: GuiDisTemp
*  DESCRIPTION: Display temperature icon and value
*  temperature display range from -99 to +99
/************************************************************/
void GuiDisTemp(unsigned char x,unsigned char y,signed char value)
{
    unsigned char temp;	 
	signed char sign;	 	  			 	  /* 写SIGNED才表明书有符号数 */
	for(temp=0; temp<11; temp++)
	{
	    LcdDisplaySeg(y,x+temp,~temperature[temp]);
	}
	if(value > 0)
	{
	    GuiDisCharF3(x/6 + 2,y,'+',1);
		sign = 1;
	}
	else if(value < 0)
	{
	    GuiDisCharF3(x/6 + 2,y,'-',1);
		sign = -1;
	} 
	else
	{
	    GuiDisCharF3(x/6 + 2,y,' ',1);
		sign = 0;
	}  
	value = sign * value;
	GuiDisCharF3(x/6 + 3,y,(value/10 + 0X30),1);
    GuiDisCharF3(x/6 + 4,y,(value%10 + 0X30),1);
	for(temp=12; temp<17; temp++)
	{
	    LcdDisplaySeg(y,x+21+temp,temperature[temp]);
	}
}

⌨️ 快捷键说明

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