用了几个小时弄了个小程序,主要用于字数不多但型号字体变化较多的场合
效果如下
typedef struct typFNT_GB16 // 汉字字模数据结构
{
unsigned char Index[2]; // 汉字内码索引
char Msk[32]; // 点阵码数据
};
/////////////////////////////////////////////////////////////////////////
// 汉字字模表 //
// 汉字库: 宋体16.dot,逐列取模高位在前,数据排列:从左到右从上到下 //
/////////////////////////////////////////////////////////////////////////
const struct typFNT_GB16 codeGB_16[] = // 数据表
{
"爱", 0x00,0x02,0x02,0x04,0x4D,0x05,0x69,0x09,0x59,0x32,0x49,0xE2,0x6F,0x54,0x59,0x54,
0xC9,0x48,0x89,0x58,0x99,0x64,0xE9,0x44,0x89,0x02,0x09,0x03,0x0C,0x02,0x00,0x00,
"你", 0x01,0x00,0x02,0x00,0x0F,0xFE,0x34,0x00,0xC2,0x08,0x04,0x30,0x19,0xC0,0xF0,0x84,
0x50,0x02,0x17,0xFC,0x10,0x00,0x11,0x00,0x14,0xC0,0x38,0x38,0x10,0x10,0x00,0x00,
"无", 0xFF,0xFD,0xFD,0xFD,0xBD,0xFB,0xBD,0xF7,0xBD,0xEF,0xBD,0xDF,0xBD,0x3F,0x80,0xFF,
0xBC,0x03,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xFD,0xF1,0xFF,0xFF,
"线", 0xFD,0xFB,0xF9,0xBB,0xE5,0x3B,0x1C,0xB7,0xB9,0xB7,0xFF,0xB7,0xF6,0xFB,0xF6,0xFB,
0xF6,0xF7,0x00,0x37,0xF6,0xCF,0xB6,0xD7,0xC6,0xBB,0xD6,0xFD,0xFE,0xE0,0xFF,0xFF,
"站", 0xF7,0xF7,0xF5,0xF7,0xB6,0x2F,0xC7,0xCF,0xF7,0x2F,0xF0,0xEF,0xF7,0xFF,0xFF,0x01,
0xFF,0x7B,0xFF,0x7B,0x00,0x7B,0xF7,0x7B,0xF7,0x7B,0xF7,0x01,0xF7,0xFF,0xFF,0xFF,
"标", 0xF7,0xDF,0xF7,0x3F,0xF4,0xFF,0x00,0x00,0xF5,0xFF,0xF6,0x6F,0xFB,0xDF,0xBB,0x3F,
0xBB,0xFD,0xBB,0xFE,0xB8,0x01,0xBB,0xFF,0xBB,0x7F,0xBB,0x9F,0xFB,0xC7,0xFF,0xFF,
};
//显示一个汉字
void LCD_GB1616(u16 x,u16 y,u8 font[2],u8 size)
{
u8 y0=y;
u16 tempcolor;
u8 temp;
unsigned int i,j,k;
for (k=0;k<70;k++)
{
if ((codeGB_16[k].Index[0]==font[0])&&(codeGB_16[k].Index[1]==font[1]))
{
for(i=0;i<size*2;i++)
{
temp=codeGB_16[k].Msk
;
for(j=0;j<8;j++)
{
if(temp&0x80)LCD_DrawPoint(x,y);
else
{
tempcolor=POINT_COLOR;
POINT_COLOR=BACK_COLOR;
LCD_DrawPoint(x,y);
POINT_COLOR=tempcolor;//还原
}
temp<<=1;
y++;
if((y-y0)==size)
{
y=y0;
x++;
break;
}
}
}
}
}
}
void Show_Str(u16 x,u16 y,u16 width,u16 height,u8*str,u8 size)
{
u16 x0=x;
u16 y0=y;
u8 bHz=0; //字符或者中文
while(*str!=0)//数据未结束
{
if(!bHz)
{
if(*str>0x80)bHz=1;//中文
else //字符
{
if(x>(x0+width-size/2))//换行
{
y+=size;
x=x0;
}
if(y>(y0+height-size))break;//越界返回
if(*str==13)//换行符号
{
y+=size;
x=x0;
str++;
}
else LCD_ShowChar(x,y,*str,size,0);//有效部分写入
str++;
x+=size/2; //字符,为全字的一半
}
}else//中文
{
bHz=0;//有汉字库
if(x>(x0+width-size))//换行
{
y+=size;
x=x0;
}
if(y>(y0+height-size))break;//越界返回
LCD_GB1616(x,y,str,size); //显示这个汉字,空心显示
str+=2;
x+=size;//下一个汉字偏移
}
}
}
{
unsigned char Index[2];
u8 Msk[32];
};
const struct typFNT_GB16 codeGB_16[] =// ???
{
"°®", 0x00,0x02,0x02,0x04,0x4D,0x05,0x69,0x09,0x59,0x32,0x49,0xE2,0x6F,0x54,0x59,0x54,
0xC9,0x48,0x89,0x58,0x99,0x64,0xE9,0x44,0x89,0x02,0x09,0x03,0x0C,0x02,0x00,0x00,
"Äã", 0x01,0x00,0x02,0x00,0x0F,0xFE,0x34,0x00,0xC2,0x08,0x04,0x30,0x19,0xC0,0xF0,0x84,
0x50,0x02,0x17,0xFC,0x10,0x00,0x11,0x00,0x14,0xC0,0x38,0x38,0x10,0x10,0x00,0x00,
"ÎÞ", 0xFF,0xFD,0xFD,0xFD,0xBD,0xFB,0xBD,0xF7,0xBD,0xEF,0xBD,0xDF,0xBD,0x3F,0x80,0xFF,
0xBC,0x03,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xBD,0xFD,0xFD,0xF1,0xFF,0xFF,
"Ïß", 0xFD,0xFB,0xF9,0xBB,0xE5,0x3B,0x1C,0xB7,0xB9,0xB7,0xFF,0xB7,0xF6,0xFB,0xF6,0xFB,
0xF6,0xF7,0x00,0x37,0xF6,0xCF,0xB6,0xD7,0xC6,0xBB,0xD6,0xFD,0xFE,0xE0,0xFF,0xFF,
"Õ¾", 0xF7,0xF7,0xF5,0xF7,0xB6,0x2F,0xC7,0xCF,0xF7,0x2F,0xF0,0xEF,0xF7,0xFF,0xFF,0x01,
0xFF,0x7B,0xFF,0x7B,0x00,0x7B,0xF7,0x7B,0xF7,0x7B,0xF7,0x01,0xF7,0xFF,0xFF,0xFF,
"±ê", 0xF7,0xDF,0xF7,0x3F,0xF4,0xFF,0x00,0x00,0xF5,0xFF,0xF6,0x6F,0xFB,0xDF,0xBB,0x3F,
0xBB,0xFD,0xBB,0xFE,0xB8,0x01,0xBB,0xFF,0xBB,0x7F,0xBB,0x9F,0xFB,0xC7,0xFF,0xFF,
};
void LCD_GB1616(u16 x,u16 y,u8 font[2],u8 size,u8 mode)
{
u16 y0=y;
u16 tempcolor=POINT_COLOR;
u8 temp;
unsigned int i,j,k;
if(mode==0)
{
for (k=0;k<70;k++)
{
if ((codeGB_16[k].Index[0]==font[0])&&(codeGB_16[k].Index[1]==font[1]))
{
for(i=0;i<size*2;i++)
{
temp=codeGB_16[k].Msk[i];
for(j=0;j<8;j++)
{
if((temp&0x80)&&(mode==0)) POINT_COLOR=BACK_COLOR;
else POINT_COLOR=tempcolor;
LCD_DrawPoint(x,y);
POINT_COLOR=tempcolor;
temp<<=1;
y++;
if((y-y0)==size)
{
y=y0;
x++;
break;
}
}
}
}
}
}
else
{
for (k=0;k<70;k++)
{
if ((codeGB_16[k].Index[0]==font[0])&&(codeGB_16[k].Index[1]==font[1]))
{
for(i=0;i<size*2;i++)
{
temp=codeGB_16[k].Msk[i];
for(j=0;j<8;j++)
{
if((temp&0x80)&&(mode==1)) POINT_COLOR=tempcolor;
else POINT_COLOR=BACK_COLOR;
LCD_DrawPoint(x,y);
temp<<=1;
y++;
if((y-y0)==size)
{
y=y0;
x++;
break;
}
}
}
}
}
}
POINT_COLOR=tempcolor;
}
void Show_Str(u16 x,u16 y,u16 width,u16 height,u8*str,u8 size)
{
u16 x0=x;
u16 y0=y;
u8 bHz=0; //??????
while(*str!=0)//?????
{
if(!bHz)
{
if(*str>0x80)bHz=1;//??
else //??
{
if(x>(x0+width-size/2))//??
{
y+=size;
x=x0;
}
if(y>(y0+height-size))break;//????
if(*str==13)//????
{
y+=size;
x=x0;
str++;
}
else LCD_ShowChar(x,y,*str,size,0);//??????
str++;
x+=size/2; //??,??????
}
}else//??
{
bHz=0;//????
if(x>(x0+width-size))//??
{
y+=size;
x=x0;
}
if(y>(y0+height-size))break;//????
LCD_GB1616(x,y,str,size,0);//??????,????
str+=2;
x+=size;//???????
}
}
}
改了下楼主的,不会报错了
一周热门 更多>