c语言点阵字模
1. c语言是如何用16点阵方法输出汉字的
我们做手机,经常做这个,显示16点阵的汉字
其实这个跟c语言,没有多大关系,不过我们的手机软件的开发,全部用的都是c
16点阵的数据,通常是16行,16列的,每个点,用1个bit位表示
通常0表示白,即不用描点,1表示黑,需要在此处描个点
因此,用两个for循环,就能把一个16点阵的字符给绘制出来
到底如何绘制,要看显示设备了,我们用的是LCD
不同的设备,会有不同的驱动,也会有不同的描点函数的
2. C语言,我在‘点阵字模工具’上查到“我”的点阵宋体字模如下请问应该怎么弄才能打印出个“我”来
char wo16S[]={
/* 以下是 '我' 的 16点阵宋体 字模,32 byte */
0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,
0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,
0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,
0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02,
};
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 2; j++)
{
char ch = wo16S[i * 2 + j];
for (int k = 0; k < 8; k++)
{
int x = j * 8 + k; //X坐标
int y = i; //Y坐标
if (ch & (1 << (7 - k)))
{
DrawPixel(x, y); //把这里DrawPixel换成C语言中的画点操作函数
}
}
}
}
3. 镐庢牱鐢–璇瑷瀹炵幇led镣归樀鏄剧ず瀛楃︾Щ锷
1銆佸苟涓嶆槸瀛楃湡鍦ㄧЩ锷锛屽彧鏄姣忔℃樉绀虹殑锲惧儚涓崭竴镙风殑锛岃繛缁鏄剧ず16娆″嚭𨱒ュ氨鏄绉诲姩銆
姣斿备笂涓嬬Щ锷锛屾湁涓鍑芥暟鑳芥樉绀轰竴涓瀛楁ā鏁扮粍銆傛妸钬滆タ钬濈殑鏁翠釜瀛楃殑瀛楁ā鏀惧埌杩欎釜鏁扮粍鏄剧ず镄勬槸瑗垮瓧锛屾妸钬滃畨钬濇斁杩涘幓灏辨槸瀹夊瓧銆傛妸瑗垮瓧16琛岀殑钖15琛屽瓧妯′俊鎭鎺ヤ笂瀹夌殑绗1琛岋纸涓鍏卞氨鏄16琛岋级鏀惧埌涓璧蜂綔涓轰竴涓瀛楁ā鏁扮粍鏄剧ず鍑烘潵灏辨槸涓嬬Щ浜嗕竴镙硷纴鎶婅タ钖14琛屾帴瀹夌殑鍓2琛岋纸鍏16琛岋级鏀惧埌涓璧蜂綔涓轰竴涓瀛楁ā鏁扮粍鏄剧ず鍑烘潵灏辨槸涓嬬Щ浜嗕袱镙硷纴渚濇℃帓涓嫔幓鍒16娆$殑镞跺椤氨瀹屾暣涓嬬Щ涓涓瀛椾简銆傚乏鍙充竴镙风殑锛屾妸钬滆タ钬濇疮琛岀殑钖15鍒楁帴涓娾滃畨钬濇疮琛岀殑绗涓鍒椾綔涓轰竴涓鏁扮粍鏄剧ず灏辨槸宸︾Щ涓浣嶏纴钖岀悊渚濇$Щ涓嫔幓16娆′竴涓瀛楃殑宸︾Щ灏卞疄鐜拌繖涓鏁堟灉浜嗐
2銆佷緥绋嬶细
#include<reg51.h>
//sbitA=P2^0;
//sbitB=P2^1;
//sbitC=P2^2;
//sbitselect=P2^3;
sbitclk=P3^0;//595涓茶屾椂阍熺
sbitda=P3^1;//595涓茶屾暟鎹绔
sbitenable=P3^2;
/************************************瀛楀簱**********************************************/
unsignedcharcodestable[]={/*--鏂囧瓧:澶--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
/*--鏂囧瓧:澶--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
/*--鏂囧瓧:蹇--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x70,0x00,0x00,0xFF,0xFF,0x00,0x08,0x80,0xB0,0x40,0x88,0x30,0x88,0x0E,0x88,
0x01,0xFF,0x06,0x88,0x08,0x88,0x30,0x88,0x60,0xF8,0xC0,0x80,0x40,0x80,0x00,0x00,
/*--鏂囧瓧:涔--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x20,0x00,0x18,0x40,0x0C,0xFC,0x07,0x44,0x12,0x44,0x20,0x44,0x40,0x46,
0x3F,0xFA,0x00,0x42,0x00,0x43,0x02,0x43,0x0C,0x42,0x38,0x40,0x10,0x00,0x00,0x00,
/*--鏂囧瓧:锛--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0xDF,0xFC,
0xDF,0xFC,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--鏂囧瓧:娆--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x20,0x14,0x10,0x24,0x4C,0x44,0x43,0x84,0x43,0x64,0x2C,0x1C,0x20,0x20,0x10,0x18,
0x0C,0x0F,0x03,0xE8,0x06,0x08,0x18,0x08,0x30,0x28,0x60,0x18,0x20,0x08,0x00,0x00,
/*--鏂囧瓧:杩--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x40,0x40,0x20,0x41,0x1F,0xCE,0x20,0x04,0x40,0x00,0x47,0xFC,0x42,0x04,0x41,0x02,
0x40,0x02,0x5F,0xFC,0x40,0x04,0x42,0x04,0x44,0x04,0x43,0xFC,0x40,0x00,0x00,0x00,
/*--鏂囧瓧:𨱒--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x20,0x00,0x20,0x80,0x10,0x84,0x10,0x84,0x08,0x94,0x04,0xA4,0x02,0xC4,0xFF,0xFF,
0x01,0x84,0x02,0xC4,0x04,0xB4,0x08,0x94,0x18,0x84,0x30,0x84,0x10,0x80,0x00,0x00,
/*--鏂囧瓧:鎴--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x04,0x20,0x04,0x20,0x42,0x22,0x82,0x22,0x7F,0xFE,0x01,0x21,0x01,0x21,0x10,0x20,
0x10,0x20,0x08,0xFF,0x07,0x20,0x1A,0x22,0x21,0xAC,0x40,0x20,0xF0,0x20,0x00,0x00,
/*--鏂囧瓧:镄--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x7F,0xF8,0x10,0x8C,0x10,0x8B,0x10,0x88,0x3F,0xF8,0x00,0x40,0x00,0x30,
0x00,0x8F,0x03,0x08,0x26,0x08,0x40,0x08,0x20,0x08,0x1F,0xF8,0x00,0x00,0x00,0x00,
/*--鏂囧瓧:绌--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x10,0x40,0x0C,0x40,0x84,0x41,0x44,0x41,0x24,0x41,0x14,0x41,0x05,0x7F,0x06,
0x41,0x04,0x41,0x14,0x41,0x24,0x41,0x44,0x40,0x84,0x40,0x14,0x00,0x0C,0x00,0x00,
/*--鏂囧瓧:闂--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0xFF,0xF8,0x00,0x01,0x00,0x06,0x00,0x00,0x07,0xF0,0x04,0x92,0x04,0x92,
0x04,0x92,0x04,0x92,0x07,0xF2,0x40,0x02,0x80,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,
/*--鏂囧瓧:澶--*/
/*--瀹嬩綋12;姝ゅ瓧浣扑笅瀵瑰簲镄勭偣阒典负锛氩绖楂=16x16--*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
};
/***************************************************************************************
琛屾樉绀哄瓙绋嫔簭
瀹炶川鏄缁椤綋鍓嶈屼腑镄勬墍链夊垪浼犻佷袱瀛楄妭镄勬暟鎹
***************************************************************************************/
voidhang_disp(unsignedchartemp1,unsignedchartemp2)
{
unsignedchari;
for(i=0;i<16;i++)
{
if(i==8)temp2=temp1;/***鍓8浣嶅嵆涓瀛楄妭浼犻佸畬涔嫔悗锛屼紶阃佽ヨ岀殑绗浜屽瓧鑺***/
if(temp2&0x01)da=1;/****鏁版嵁浠庣鍙h緭鍑****/
elseda=0;/****鐢熸垚涓涓婂崌娌匡纴595涓婂崌娌挎帴鍙楁暟鎹****/
clk=0;clk=1;clk=0;
temp2=temp2>>1;
}
enable=0;enable=1;enable=0;/****595骞惰岃緭鍑轰娇鑳****/
}
/***************************************************************************************
娓呰屽瓙绋嫔簭
濡傛灉娌℃湁娓呰岀▼搴忥纴璇ヨ屾樉绀哄畬杞鍒颁笅涓琛屾椂595镄勮緭鍑鸿缮娌℃湁鍙桡纴杩樻槸涓娄竴琛岀殑鏁版嵁锛屽洜涓虹▼搴忎腑鏄鍏堥夊畾琛岋纴
鍐嶅悜595浼犳暟鎹镄勶纴镓浠ヤ笅涓琛屽紑濮嬫椂链変竴娈垫椂闂存槸鏄剧ず钖堜竴琛岀殑鍐呭圭殑锛岃繖娈垫椂闂村氨鏄钖595浼犱袱涓瀛楄妭鏁版嵁镄勬椂闂淬
/***************************************************************************************/
voidhang_clear()
{
unsignedchari;
for(i=0;i<16;i++)
{
da=0;/***595镄勮緭鍑鸿繛鎺ョ殑鏄镣归樀镄勯槾鏋侊纴镓浠ヨ595杈揿嚭楂樼数骞筹纴鍙浠ヤ娇寰楄ヨ岀殑LED镡勭伃****/
clk=0;clk=1;clk=0;
}
enable=0;enable=1;enable=0;
}
/***************************************************************************************/
/***************************************************************************************/
unsignedintcount=0;
unsignedcharmove=0;
voiddisp()
{
unsignedchari;
unsignedintj;
count++;
for(i=0;i<16;i++)
{
P2=i;/*****阃夊畾琛*****/
//hang_disp(stable[2*(i+move)],stable[2*(i+move)+1]);/***浠庡瓧搴扑腑鍙栨暟鎹****/
hang_disp(~stable[2*(i+move)],~stable[2*(i+move)+1]);/***浠庡瓧搴扑腑鍙栨暟鎹鍐嶅彇鍙嶏纴鑳藉疄鐜板弽鏄****/
for(j=0;j<10;j++);/***鏄剧ず鍜屾竻闆堕棿锷犱互寤舵椂锛屼互渚挎樉绀烘槑鏄撅纴鍙浠ヨ嚜琛岃皟鑺傦纴涔熷彲浠ュ幓鎺***/
hang_clear();
}
if(count==10)/***璋冭妭绉诲姩镄勯熷害***/
{
count=0;
move++;
if(move==192)/***璋冭妭绉诲姩镄勫瓧鏁***n=move/16***/
{
move=0;
}
}
}
/***************************************************************************************/
/***************************************************************************************/
main()
{
while(1)
{
disp();
}
}
4. C语言编写16和32点阵字库
CFont ft;
ft.CreatePointFont(90,_T("宋体")); //做点阵字体。 90 所需字体高度(用0.1点表示,例如,传递120表示12点字体)。
DC.SelectObject(&ft);
DC.DrawText((LPCTSTR)str,str.GetLength(),&rt,DT_LEFT);把你要的字写入一个DC
然后用GetPixel得到dc的点阵结构 至于怎么存储就看怎么使用了
5. 急!C语言编写 汉字点阵字库 '罗' '恒'这两个字
#include <stdio.h>
// 每个汉字的水平点数
const int WIDTH = 24;
// 每个汉字的垂直点数
const int HEIGHT = 24;
/*
// 方案1 :每个汉字的笔画
const char FRONT_COLOR[]="■";
// 方案1 :每个汉字的背景
const char BACKGROUND_COLOR[]="□";
*/
// 方案2 :每个汉字的笔画
const char FRONT_COLOR[]="*";
// 方案2 :每个汉字的背景
const char BACKGROUND_COLOR[]=" ";
// 罗恒
int name1[]=
{
/* "罗"字 */
0x00,0x00,0x00,
0x00,0x00,0x00,
0x08,0x00,0x08,
0x0F,0xFF,0xFC,
0x0C,0x61,0x08,
0x0C,0x61,0x08,
0x0C,0x61,0x08,
0x0C,0x61,0x08,
0x0F,0xFF,0xF8,
0x0C,0x10,0x08,
0x00,0x30,0x00,
0x00,0x60,0x20,
0x00,0xDF,0xF0,
0x01,0x80,0x60,
0x03,0x40,0xC0,
0x06,0x60,0x80,
0x08,0x31,0x80,
0x10,0x23,0x00,
0x00,0x04,0x00,
0x00,0x18,0x00,
0x00,0x60,0x00,
0x03,0x80,0x00,
0x1C,0x00,0x00,
0x00,0x00,0x00,
/* "恒"字 */
0x00,0x00,0x00,
0x08,0x00,0x00,
0x0E,0x00,0x00,
0x0C,0x00,0x08,
0x0C,0x7F,0xFC,
0x0C,0x00,0x00,
0x06,0x00,0x00,
0x05,0x20,0x10,
0x05,0xBF,0xF0,
0x24,0x30,0x30,
0x24,0x30,0x30,
0x64,0x30,0x30,
0x44,0x3F,0xF0,
0x04,0x30,0x30,
0x04,0x30,0x30,
0x04,0x30,0x30,
0x04,0x30,0x30,
0x04,0x3F,0xF0,
0x0C,0x30,0x20,
0x0C,0x00,0x00,
0x0C,0x00,0x04,
0x0D,0xFF,0xFE,
0x0C,0x00,0x00,
0x00,0x00,0x00
};
void printChineseCharVertical(int * data ,int dataSize)
{
int i,j,k,n;
int bit;
// 计算汉字个数
int numOfChar = dataSize/( WIDTH * HEIGHT / 8);
for(n=0;n<numOfChar;n++)
{
for(i=0;i<HEIGHT;i++)
{
for(j=0;j<WIDTH;j++)
{
bit = data[n*(WIDTH * HEIGHT / 8) + i * WIDTH / 8 + j/8] & (1<<(7-j%8));
if(bit)
{
printf("%s",FRONT_COLOR);
}
else
{
printf("%s",BACKGROUND_COLOR);
}
}
printf("\n");
}
}
}
void printChineseCharHorizontal(int * data ,int dataSize)
{
int i,j,k,n;
int bit;
// 计算汉字个数
int numOfChar = dataSize/( WIDTH * HEIGHT / 8);
for(i=0;i<HEIGHT;i++)
{
for(j=0;j<numOfChar*WIDTH;j++)
{
bit = data[(j/WIDTH)*(WIDTH*HEIGHT/8) + i*WIDTH/8 + j%WIDTH/8] & (1<<(7-j%WIDTH%8));
if(bit)
{
printf("%s",FRONT_COLOR);
}
else
{
printf("%s",BACKGROUND_COLOR);
}
}
printf("\n");
}
}
int main(int argc, char *argv[])
{
printChineseCharVertical(name1,sizeof(name1)/sizeof(int));
printChineseCharHorizontal(name1,sizeof(name1)/sizeof(int));
return 0;
}
/*
* *
******************
** ** * *
** ** * *
** ** * *
** ** * *
*****************
** * *
**
** *
** *********
** **
** * **
** ** *
* ** **
* * **
*
**
**
***
***
*
***
** *
** *************
**
**
* * * *
* ** **********
* * ** **
* * ** **
** * ** **
* * **********
* ** **
* ** **
* ** **
* ** **
* **********
** ** *
**
** *
** ****************
**
*
* * ***
****************** ** *
** ** * * ** *************
** ** * * **
** ** * * **
** ** * * * * * *
***************** * ** **********
** * * * * ** **
** * * ** **
** * ** * ** **
** ********* * * **********
** ** * ** **
** * ** * ** **
** ** * * ** **
* ** ** * ** **
* * ** * **********
* ** ** *
** **
** ** *
*** ** ****************
*** **
*/
6. c语言字模问题
void drawmat(char *mat,int matsize,int x,int y,int color)
/*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/
{int i,j,k,n;
n=(matsize-1)/8+1;//n是点阵的列数
for(j=0;j<matsize;j++)//j代表点阵中第j行的字符意思
for(i=0;i<n;i++)//i代表点阵中第i列字符的意思
for(k=0;k<8;k++)//k代表在当前字模中,第k位的值
if(mat[j*n+i]&(0x80>>k)) /*测试为1的位则显示*/
putpixel(x+i*8+k,y+j,color);
}
你把字模的每个矩阵元素用二进制展开就知道k的意思了:
char shan16[]={
/* 以下是 '山' 的 16点阵宋体 字模,32 byte */
0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x08,0x21,0x08,
0x21,0x08,0x21,0x08,0x21,0xF8,0x2E,0x08,
0x30,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
};
相当于:
0000 0000 0000 0000 0000 0001 0000 0000
0000 0001 0000 0000 0000 0001 0000 0000
0000 0001 0000 0000 0000 0001 0000 0000
0000 0001 0000 1000 0010 0001 0000 1000
0010 0001 0000 1000 0010 0001 0000 1000
0010 0001 1111 1000 0010 1110 0000 1000
0011 0000 0000 1000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
最后得到:
_______________8________________
___________8___8________________
___________8___8________________
______8____8___8________8___8___
__8___8____8___8________8___8___
__8___8____8888_8888____8___8___
__88____________________8_______
________________________________
7. 急!!C语言编写 汉字点阵字库
/* 以下是 '谢' 的 16点阵宋体 字模,32 byte */
0x01,0x08,0x42,0x08,0x37,0x88,0x24,0x88,
0x07,0xFE,0x04,0x88,0xE7,0xC8,0x24,0xA8,
0x2F,0xA8,0x21,0x88,0x22,0x88,0x2A,0x88,
0x34,0x88,0x28,0x88,0x12,0xA8,0x01,0x10,
};
/* 以下是 '佳' 的 16点阵宋体 字模,32 byte */
0x08,0x40,0x0C,0x40,0x18,0x48,0x17,0xFC,
0x30,0x40,0x60,0x44,0xAF,0xFE,0x20,0x40,
0x20,0x40,0x20,0x48,0x27,0xFC,0x20,0x40,
0x20,0x40,0x20,0x44,0x2F,0xFE,0x20,0x00,
};
/* 以下是 '志' 的 16点阵宋体 字模,32 byte */
0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFE,
0x01,0x00,0x01,0x00,0x3F,0xFC,0x00,0x00,
0x01,0x00,0x08,0x88,0x48,0xC4,0x48,0x86,
0x48,0x14,0x88,0x18,0x07,0xF0,0x00,0x00,
};