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

📄 gui.c

📁 STM32驱动nrf24l01
💻 C
📖 第 1 页 / 共 2 页
字号:
入口参数:(x,y) 是显示内容的左上角坐标,*s:英文字符串指针,
          color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示英文字符串。
**********************************************/
void GUI_sprintf_string(uchar x, uint y,char *s, uint color,uint b_color)
{  
	for(;*s!='\0';s++)
	{
		GUI_sprintf_char(x, y,*s, color,b_color);
		x=x+8;
	}
	
	//while (*s) 
	//	{
	//	GUI_sprintf_char(x, y,*s, color,b_color);
	//	s++;
	//	x=x+8;
	//	}
}


/*********************************************
显示预定义汉字字符串
入口参数:(x,y) 是显示内容的左上角坐标,color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示预定义的中文字符串。
      要显示的中文字符串事先定义在chinese.h中的china_char[]数组中,
		如果想修改中文字符串长度、内容,请修改chinese.h中的
		china_char[]数组,建议用字模提取软件zimoV2.2将你要显示的
		中文字符串自动转换为数组数据。
**********************************************/
void GUI_sprintf_HZ(uchar x, uint y, uint color,uint b_color)
{ 
	uchar  s_x=0 ,s_y=0, temp=0 ;  
	uchar n;
	uint j,words;
	words=sizeof(china_char)/32;
	for( n=0 ; n<words ; n++ )
  	{
	 	for( s_x=0 ; s_x<16 ; s_x++ ) 
	  	{
	   	if(s_x+x<240)
	   	{
	   	   j=n;
	   	   j=j*32+s_x;
	   	   temp = china_char[j] ;
	   	   //temp = china_char[n*32+s_x] ;
	   		for( s_y=0 ; s_y<8 ; s_y++ )
	       	{
		     		if(y+s_y<320)
		       	{
			     		if((temp&(0x80>>(s_y))) == (0x80>>(s_y))  )
			       	{
				      	GUI_Point(x+s_x+n*16, y+s_y,color) ;
			       	}
			     		else
			       	{
				      	GUI_Point(x+s_x+n*16, y+s_y,b_color) ;
				   	}
					}
		   	}
		   }
		}
		for( s_x=0 ; s_x<16 ; s_x++ ) 
	  	{
	   	if(s_x+x<240)
	   	{
	   		j=n;
	   		j=j*32+s_x+16;
	   		temp = china_char[j] ;
	   		//temp = china_char[n*32+s_x+16] ;
		    	for( s_y=0 ; s_y<8 ; s_y++ )
	       	{
		     		if(y+s_y<320)
		       	{
			     		if((temp&(0x80>>(s_y))) == (0x80>>(s_y))  )
			       	{
				      	GUI_Point(x+s_x+n*16, y+s_y+8,color) ;
			       	}
			     		else
			       	{
				      	GUI_Point(x+s_x+n*16, y+s_y+8,b_color) ;
				   	}
					}
		   	}
		   }
		}
	}
}


/*********************************************
显示预定义汉字字符串
入口参数:(x,y) 是显示内容的左上角坐标,i:中文字符串中的第几个汉字,
                color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示预定义的中文字符串。
      要显示的中文字符串事先定义在chinese.h中的china[][]数组中,
		如果想修改中文字符串长度、内容,请修改chinese.h中的
		china[][]数组,建议用字模提取软件zimoV2.2将你要显示的
		中文字符串自动转换为数组数据。
**********************************************/
void GUI_sprintf_china(uchar x, uint y,uchar i, uint color,uint b_color)
{ 
  uchar  s_x=0 ,s_y=0, temp=0 ;  
  uint j;
  i=i-1;
  for( s_x=0 ; s_x<16 ; s_x++ ) 
  {
  if(s_x+x<240)
  {
     j=s_x;
     temp = china[i][j] ;
     //temp = china_char[n*32+s_x] ;
          for( s_y=0 ; s_y<8 ; s_y++ )
  {
                  if(y+s_y<320)
          {
                          if((temp&(0x80>>(s_y))) == (0x80>>(s_y))  )
                  {
                          GUI_Point(x+s_x, y+s_y,color) ;
                  }
                          else
                  {
                          GUI_Point(x+s_x, y+s_y,b_color) ;
                          }
                          }
          }
     }
  }
  for( s_x=0 ; s_x<16 ; s_x++ ) 
  {
  if(s_x+x<240)
  {
          j=s_x+16;
          temp = china[i][j] ;
          //temp = china_char[n*32+s_x+16] ;
          for( s_y=0 ; s_y<8 ; s_y++ )
  {
                  if(y+s_y<320)
          {
                          if((temp&(0x80>>(s_y))) == (0x80>>(s_y))  )
                  {
                          GUI_Point(x+s_x, y+s_y+8,color) ;
                  }
                          else
                  {
                          GUI_Point(x+s_x, y+s_y+8,b_color) ;
                          }
                          }
          }
     }
  }
}



/*********************************************
画实心矩形
入口参数: (sx,sy)左上角顶点坐标, (ex,ey)右下角顶点坐标, color颜色
出口参数: 无
说明:在指定位置上画出实心矩形。
**********************************************/
void GUI_box(uchar sx,uint sy,uchar ex,uint ey,uint color)
{ 
	uint temp;   
	ILI9325_SetWindow(sx,sy,ex,ey); 
   sx=ex-sx+1;
	sy=ey-sy+1;

	while(sx--)
	{
	 	temp=sy;
		while(temp--)
	 	{	
			ILI9325_WriteDataU16(color);
		}
	}
}


/*********************************************
画空心矩形
入口参数: (sx,sy)左上角顶点坐标, (ex,ey)右下角顶点坐标, color颜色
出口参数: 无
说明:在指定位置上画出空心矩形。
**********************************************/
void GUI_rectangle( uchar sx,uint sy,uchar ex,uint ey,uint color)
{
	GUI_line(sx,sy,ex,sy,color);
	GUI_line(sx,sy,sx,ey,color);
	GUI_line(ex,sy,ex,ey,color);
	GUI_line(sx,ey,ex,ey,color);
}

/*********************************************
以十进制形式显示无符号长整型数
入口参数:(x,y) 是显示内容的右上角坐标;
			 num是欲显示的无符号长整型数
	       num的数值范围为:0~4,294,967,295(十进制),
			 也就是说利用该函数,我们最多将一个10位十进制数显示在LCD屏上;
			 color:颜色,b_color:背景颜色。
出口参数: 无
说明:将一个无符号长整型数以十进制形式显示在TFT屏上。
注意:在使用该函数时,不论最终显示的数有几位,它都将在LCD屏幕上
      占10个字符的空间(显示的多位十进制数不足10位时,
		本函数会在有效显示数字前面补空格)。
**********************************************/
void GUI_wrul(uchar x, uint y, unsigned long num, uint color,uint b_color)
{
	unsigned long temp; 
	uchar i;
	for(i=0;i<10;i++)
	{
		if(num!=0)
		{
			temp=num/10;
			GUI_sprintf_char(x-7,y,num-temp*10+'0',color,b_color);
			num=temp;
		}
		else/*往前写满10位,也就是前面都写空格*/
		{
			GUI_sprintf_char(x-7,y,' ',color,b_color);
		}
		x=x-8;/*设置光标在文字插入后自动左移*/
	}
}

/*********************************************
以十进制形式显示长变量
入口参数: 
   x,y ----是显示内容的右上角坐标 
    num ----欲显示的长变量
   bits ----允许显示的位数
     dp ----小数点位置
  color ----颜色
b_color ----背景颜色
出口参数: 无
说明: 
将一个长变量的数值以十进制形式显示在TFT屏上,可以根据需要确定
是否显示小数点以及小数点位置,也可以确定在TFT屏幕上显示的位数。
注意:
1、要显示的数据比规定的显示位数多,规定的位全部写-,表示数据溢出。
2、本函数实际上相当于GUI_wrul函数的增强版,如果我们指定bits=10 dp=0,
如下所示:
GUI_wrlval(20,239,tp,10,0,WHITE,BLACK);
那么,其作用和GUI_wrul函数完全一样。
**********************************************/
void GUI_wrlval(uchar x, uint y,unsigned long num,uchar bits,uchar dp,uint color,uint b_color)
{
	char str[10];/*无符号长整型数转换为字符串是10个,所以需要10个单元存储*/	
	unsigned long temp; 
	uchar i;
	//LCD_wrcmd(CUR_AUTO_L);/*设置光标在文字插入后自动左移*/
	for(i=0;i<bits;i++)
	{
		if(num!=0)
		{
			temp=num/10;
			str[i]=num-temp*10+'0';
			num=temp;
		}
		else/*往前写*/
		{
			if(i>=dp)str[i]=0x20;/*小数点前零都变空格*/
			else str[i]='0';/*小数点后零保留*/
		}
	}
	i=0;
	if (num!=0)/*要显示的数据比规定的显示位数多,数据显示溢出*/
	{
		while(i<bits)/*往前写满规定的位数,也就是前面都写空格,直到规定的位数*/
		{
			GUI_sprintf_char(x-7,y,'-',color,b_color);/*规定的位全部写-,表示数据溢出*/
			i++;
			x=x-8;
			if (i==dp) 
			{
				GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
				x=x-8;
			}
		}
	}
	else
	{
		while(i<bits)/*显示前面的有效数字*/
		{
			if ((i==dp)&(str[dp]==0x20))
			{
				GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
				x=x-8;
				GUI_sprintf_char(x-7,y,'0',color,b_color);/*小数点前为0时要补写0*/
				x=x-8;
			}
			else
			{
				if ((i==dp)&(i!=0)) 
				{
					GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
					x=x-8;
				}
				GUI_sprintf_char(x-7,y,str[i],color,b_color);
				x=x-8;
			}
			i++;				
		}
	}
}


/********************************************* 
RGB颜色混合
入口参数:R(红色分量)0-255,G(绿色分量)0-255,B(蓝色分量)0-255
出口参数: 按R5-G6-B5格式混合后的16位颜色码。
说明:将电脑上常见的R8-G8-B8格式转换成8位单片机常用的R5-G6-B5格式。
**********************************************/
uint RGB(uchar R,uchar G,uchar B)
{
	return((uint)(R&0XF8)<<8|(uint)(G&0XFC)<<3|(uint)(B&0XF8)>>3);
}

⌨️ 快捷键说明

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