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,
};