Chinese and English display modulo settings

来自LCD wiki
跳转至: 导航搜索

The font modulo software used in the test example is PCtoLCD200. For detailed instructions on its use, see the following document:

PCtoLCD200 Instructions for use

The PCtoLCD200 software is specifically set as follows:

The font selection is Song, and the dot size offset is 0

Word width and word height are selected: 12x8, 16x16, 24x24, 32x32 (English corresponds to 6x8, 8x16, 12x24, 16x32)

MSP130W-001.jpg

点阵格式选择阴码

取模方式选择逐行式

取模走向选择顺向(高位在前)

输出数制选择十六进制数

自定义格式选择C51格式

其他按默认设置

MSP130W-002.jpg

底层支撑函数

*LCD_SetWindows

该函数实现因驱动IC而异(不同的驱动IC设置坐标值命令和原理有差异),但是原理基本一样,都是设置起始坐标和结束坐标,设置一块显示区域

举例如下(ILI9341为例)

void LCD_SetWindows(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
{	
	LCD_WR_REG(lcddev.setxcmd);	
	LCD_WR_DATA(xStar>>8);
	LCD_WR_DATA(0x00FF&xStar);		
	LCD_WR_DATA(xEnd>>8);
	LCD_WR_DATA(0x00FF&xEnd);

	LCD_WR_REG(lcddev.setycmd);	
	LCD_WR_DATA(yStar>>8);
	LCD_WR_DATA(0x00FF&yStar);		
	LCD_WR_DATA(yEnd>>8);
	LCD_WR_DATA(0x00FF&yEnd);

	LCD_WriteRAM_Prepare();	//开始写入GRAM		
}

*Lcd_WriteData_16Bit

该函数就是往GRAM里面设置像素颜色值,然后显示出来

举例如下(ILI9341为例)

void Lcd_WriteData_16Bit(u16 Data)
{	
      LCD_CS_CLR;
      LCD_RS_SET;  
      SPI_WriteByte(SPI2,Data>>8);
      SPI_WriteByte(SPI2,Data);
      LCD_CS_SET;
}

*LCD_DrawPoint

其实就是利用LCD_SetWindows函数和Lcd_WriteData_16Bit函数显示一个像素点

举例如下(ILI9341为例)

void LCD_DrawPoint(u16 x,u16 y)
{
	LCD_SetCursor(x,y);//设置光标位置 
	Lcd_WriteData_16Bit(POINT_COLOR); 
}

英文取模

函数定义如下:

void LCD_ShowChar(u16 x,u16 y,u16 fc, u16 bc, u8 num,u8 size,u8 mode)
{  
   u8 temp;
   u8 pos,t;
   u16 colortemp=POINT_COLOR; 
   num=num-' ';//得到偏移后的值
   LCD_SetWindows(x,y,x+size/2-1,y+size-1);//设置单个文字显示窗口
   if(!mode) //非叠加方式
   {		
       for(pos=0;pos<size;pos++)
       {
	   if(size==12)
           {
              temp=asc2_1206[num][pos];//调用1206字体
	   }
           else
           { 
              temp=asc2_1608[num][pos];		 //调用1608字体
           }
	   for(t=0;t<size/2;t++)
           {                 
              if(temp&(0x80>>t))
              {
                 Lcd_WriteData_16Bit(fc);
              } 
	      else
              { 
                 Lcd_WriteData_16Bit(bc); 
	      }
           }		
       }	
   }
   else//叠加方式
   {
       for(pos=0;pos<size;pos++)
       {
	   if(size==12)
           {
              temp=asc2_1206[num][pos];// 调用1206字体
	   }
           else
           { 
              temp=asc2_1608[num][pos];		 //调用1608字体
	   }
	   for(t=0;t<size/2;t++)
           {   
	      POINT_COLOR=fc;              
	      if(temp&(0x80>>t))
              {
                 LCD_DrawPoint(x+t,y+pos);//画一个点   
	      }
           }
       }
   }
   POINT_COLOR=colortemp;	
   LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口为全屏   	   
}

此函数包含了12x6和16x8两种英文字体设置。

包含了两种显示模式:叠加模式和非叠加模式。

叠加模式:字体不带背景色,直接叠加显示到原来显示的内容上

非叠加模式:字体带有背景色,显示时会将原来显示的内容覆盖掉

中文取模

A、16x16中文字体显示函数定义如下:

void GUI_DrawFont16(u16 x, u16 y, u16 fc, u16 bc, u8 *s,u8 mode)
{
   u8 i,j;
   u16 k;
   u16 HZnum;
   u16 x0=x;
   HZnum=sizeof(tfont16)/sizeof(typFNT_GB16);	//自动统计汉字数目
   for (k=0;k<HZnum;k++) 
   {
       if((tfont16[k].Index[0]==*(s))&&(tfont16[k].Index[1]==*(s+1)))
       { 	
           LCD_SetWindows(x,y,x+16-1,y+16-1);
	   for(i=0;i<16*2;i++)
           {
		for(j=0;j<8;j++)
		{	
		     if(!mode) //非叠加方式
		     {
			  if(tfont16[k].Msk[i]&(0x80>>j))
                          {	
                               Lcd_WriteData_16Bit(fc);
                          }			  
                          else 
                          {
                               Lcd_WriteData_16Bit(bc);
			  }
		     }
		     else
		     {
			  POINT_COLOR=fc;
			  if(tfont16[k].Msk[i]&(0x80>>j))						
                          {
                               LCD_DrawPoint(x,y);//画一个点
			  }
			  x++;
			  if((x-x0)==16)
			  {
			       x=x0;
			       y++;
			       break;
			  }
		     }
	        }
	    }
	 }				  	
	 continue;  //找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
    }
    LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口为全屏 
}

B、24x24中文字体显示函数定义如下:

void GUI_DrawFont24(u16 x, u16 y, u16 fc, u16 bc, u8 *s,u8 mode)
{
    u8 i,j;
    u16 k;
    u16 HZnum;
    u16 x0=x;
    HZnum=sizeof(tfont24)/sizeof(typFNT_GB24);	//自动统计汉字数目
    for (k=0;k<HZnum;k++) 
    {
        if((tfont24[k].Index[0]==*(s))&&(tfont24[k].Index[1]==*(s+1)))
        { 	
             LCD_SetWindows(x,y,x+24-1,y+24-1);
	     for(i=0;i<24*3;i++)
	     {
		  for(j=0;j<8;j++)
		  {
			if(!mode) //非叠加方式
			{
                              if(tfont24[k].Msk[i]&(0x80>>j))
                              {	 
                                   Lcd_WriteData_16Bit(fc);
			      }						
                              else 
                              {
                                   Lcd_WriteData_16Bit(bc);
			      }					
                        }
		        else
		        {
			      POINT_COLOR=fc;
			      if(tfont24[k].Msk[i]&(0x80>>j))
                              { 
                                   LCD_DrawPoint(x,y);// 画一个点
			      }					
                              x++;
			      if((x-x0)==24)
			      {
				   x=x0;
				   y++;
				   break;
			      }
		         }
		   }
	      }
	 }				  	
	 continue;  //找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
    }
    LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);// 恢复窗口为全屏
}

C、32x32中文字体显示函数定义如下:

void GUI_DrawFont32(u16 x, u16 y, u16 fc, u16 bc, u8 *s,u8 mode)
{
    u8 i,j;
    u16 k;
    u16 HZnum;
    u16 x0=x;
    HZnum=sizeof(tfont32)/sizeof(typFNT_GB32);	//自动统计汉字数目
    for (k=0;k<HZnum;k++) 
    {
	 if ((tfont32[k].Index[0]==*(s))&&(tfont32[k].Index[1]==*(s+1)))
	 { 	
               LCD_SetWindows(x,y,x+32-1,y+32-1);
	       for(i=0;i<32*4;i++)
	       {
		     for(j=0;j<8;j++)
	             {
			   if(!mode) //非叠加方式
			   {
				if(tfont32[k].Msk[i]&(0x80>>j))
                                {
				      Lcd_WriteData_16Bit(fc);
                                }				
				else 
                                {
                                      Lcd_WriteData_16Bit(bc);
				}			
                           }
			   else
			   {
				POINT_COLOR=fc;
			        if(tfont32[k].Msk[i]&(0x80>>j))
                                {
                                      LCD_DrawPoint(x,y);// 画一个点
				}		
		                x++;
				if((x-x0)==32)
				{
				      x=x0;
				      y++;
				      break;
				}
			   }
		      }
		}
	  }				  	
	  continue;  //找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
     }
     LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);// 恢复窗口为全屏
}

以上三个函数分别是对16x16、24x24、32x32汉字进行显示设置。

包含了两种显示模式:叠加模式和非叠加模式。

叠加模式:字体不带背景色,直接叠加显示到原来显示的内容上

非叠加模式:字体带有背景色,显示时会将原来显示的内容覆盖掉

BACK TO TOP