C语言是如何用16点阵方法输出汉字的三篇

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言是如何用16点阵方法输出汉
字的三篇
篇一:C语言是如何用16点阵方法输出汉字的
到目前为止,我们编写的C程序,其用于人机交互的提示或菜单都是英文的,那么如何在没有汉化的Turbo C集成开发环境下编制显示汉字的程序呢?
解决这一编程问题,我们首先必须了解有关汉字编码及字库的知识。

根据对汉字使
用频率的研究,可把汉字分成高频字(约100个),常用字(约3000个),次常用字(约4000个),罕见字(约8000个)和死字(约45000个),即正常使用的汉字达15000个。

我国1981年公布了《通讯用汉字字符集(基本集)及其交换码标准》GB2312-80方案,把高频字、常用字、和次常用字集合成汉字基本字符集(共6763个),在该集中按汉字使用的频度,又将其分为一级汉字3755个(按拼音排序)、二级汉字3008个(按部首排序),再加上西文字母、数字、图形符号等700个。

国家标准的汉字字符集(GB2312—80)在汉字操作系统中是以汉字库的形式提供的。

汉字库结构作了统一规定,即将字库分成94个区,每个区有94个汉字(以位作区别)每一个汉字在汉字库中有确定的区和位编号(用两个字节),这就是所谓的区位码(区位码的第一个字节表示区号,第二个字节表示位号,因而只要知道了区位码,就可知道该汉字在字库中的地址,每个汉字在字库中是以点阵字模形式存储的,如一般采用16×16点阵形式,每个点用一个二进位表示,存1的点,当显示时,可以在屏上显示一个亮点,存0的点,则在屏上不
显示,这样把存某字的16×16点阵信息直接用来在显示器上按上述原则显示,则将出现对应的汉字。

内码
汉字使用两字节表示,国家制定了统一标准,称为国标码。

国标码规定,每个字节使用
后面7位,第一位为0。

为了区别于英文的ASCII码,国标码在计算机上使用的时候,规定汉字每个字节第一位设置为1,以表示该两字节为汉字,称为内码。

以“大”字为例子:国标码3473H:0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 1内码B4F3H:1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1
国标码与内码有一定的转换公式,即16进制的区位码,两个字节各加80H,就成为了国标码。

汉字字模在字库中存放的位置根据汉字的区位码来确定,内码是汉字在机内的表示。

由于区位码和内码存在固定的转换关系,所以当在支持汉字输入的系统中,键盘输入的汉字内码即在程序中存在,将其转换为区位码,再从字库中找到对应的汉字字模,然后再用有关的位操作和循环语句,对每个字节的每一位进行判断,如同过滤一样,如果某位是1,则按设置的颜色在屏幕的相应位置画点(用graphics.h中的显示象素点的函数putpixel()),若某位为0,则不画点,这样就可按预先设置的颜色在相应位置显示出该汉字来。

内码到区位码的转换
若汉字内码为十六进制数h2h1l2l1,则区号qh相位号wh分别为:qh=h2h1-0xa0;wh=l2l1-0xa0;
若用十进制表示内码为dld2,则qh=dl-l60;
wh=d2-160;即区位码qw为:
qw=100*(d1-160)十(d2-160);
反过来,若已经知道了区位码qw。

则也可求得区号和位号:qh=qw/100;
wh=qw-100*qh;
因而该汉字在汉字库中离起点的偏移位置(以字节为单位),可计算为:
offset=(94*(qh-1)+(wh-1))*32;
注意:字库中每1区有94个字符。

这样,就可以找寻到文件的偏移量,读出一个char bytes[32]数组。

这样bytes数组中则存了要显示汉字的16×16点阵字模,然后将字模按行扫描的办法,通过循环用putpixel()函数在屏幕设定位置显示出象点,因而组合成一个显示的汉字。

在C语言中显示汉字
在许多C程序设计中,要用到汉字进行提示或人机交互,而现行的Turbo C集成开发环境不是汉化的,如何编制能显示汉字的C程序呢?
下面的方法可以帮你在西文环境下显示汉字。

这种方法是调用中文汉字库进行汉字显示。

国家标准规定:汉字库分94个区,每个区有94个汉字(以位作区别),每个汉字在汉字库中有确定的区和位编号,这就是汉字的区位码。

每个汉字在库中是以点阵字模形式存储的,一般采用16×16点阵(32字节)、24×24点阵(72字节),每个点用一个二进制位(0或1)表示,对应在屏幕上显示出来,就是相应的汉字。

由于在中文环境下,输入的是汉字的内码,我们必须将之转换成区位码,算出偏移量,从字库中找到对应的汉字,将其字模显示即可。

内码转换成区位码方法如下:
qh=c1-0xa0 wh=c2-0xa0
其区位码就是:
qw=qh*0xff+wh
该汉字在字库中离起点的位置是:
offset=(94*(qh-1)+(wh-1))*32L
程序例:
#include〈graphics.h〉
#include〈stdio.h〉
#include〈fcntl.h〉
#include〈io.h〉
#include〈stdlib.h〉
#include〈conio.h〉
#define ROW 1//纵坐标放大倍数
#define COL 2//横坐标放大倍数
void main(){
int x,y;
char*s=″汉字显示程序″;
FILE*fp;
char buffer[32];//buffer用来存储一个汉字register m,n,i,j,k;
unsigned char qh,wh;
unsigned long offset;
int gd=DETECT,gm;//图形屏幕初始化
initgraph(&gd,&gm,″″);
if((fp=fopen(″hzk16″,″rb″))==NULL)
//打开汉字库,该字库可以在ucdos中找到
{printf(″Can’t open haz16,Please add it″);
getch();closegraph();exit(0);
}
x=20;y=100;//显示位置设置
while(*s)
{qh=*(s)-0xa0;//汉字区位码
wh=*(s+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;//计算该汉字在字库中偏移量
fseek(fp,offset,SEEK_SET);
fread(buffer,32,1,fp);//取出汉字32字节的点阵字模存入buffer中(一个汉字)
for(i=0;i〈16;i++)//将32位字节的点阵按位在屏幕上打印出来(1:打印,0:不打印),显示汉字
for(n=0;n〈ROW;n++)
for(j=0;j〈2;j++)
for(k=0;k〈8;k++)
for(m=0;m〈COL;m++)
if(((buffer[i*2+j]〉〉(7-k))&0x1)!=NULL)
putpixel(x+8*j*COL+k*COL+m,y+i*ROW+n,GREEN);
s+=2;//因为一个汉字内码占用两个字节,所以s必须加2
x+=30;
}
getch();
closegraph();
}
上述程序在Turbo C 2.0编译系统下运行成功,它可以将汉字放大显示,读者可以将它改成函数用在您的程序中显示汉字。

篇二:C语言是如何用16点阵方法输出汉字的
//电路连接为:P1.0-P1.3连接4线-16线译码器控制每一列的扫描,
//P2、P0口分别控制从上至下的16行
//汉字取码方式为从上之下从左到右
#include<reg52.h>
void delayms(unsigned int xms);
void main()
{
int a,ab; //用于半屏扫描
unsigned int c=0;//c作为ziku数组的计数器
int d=0,e=0;//d作为0~15竖屏扫描变量,一个字扫描e遍
int f=0;//汉字计数器
//////////////////////////////////////////////////////////////////// ////汉字字模库
unsigned char code hzdot[1632]={
/*C2020*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*we C7765*/
0x80,0x0F,0x80,0x30,0x00,0x0C,0x80,0x03,0x00,0x0C,0x80,0x30,0x80,0x0
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
/*d C2064*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x88,0x10,0xF8,0x3 F,0x00,0x20,
/*id C6964*/
0x00,0x00,0x80,0x20,0x98,0x20,0x98,0x3F,0x00,0x20,0x00,0x20,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x88,0x10,0xF8,0x3 F,0x00,0x20,
/*n'C6E27*/
0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
0x10,0x00,0x16,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*t C7420*/
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
/*kn C6B6E*/
0x08,0x20,0xF8,0x3F,0x00,0x24,0x00,0x02,0x80,0x2D,0x80,0x30,0x80,0x2 0,0x00,0x00,
0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
/*ow C6F77*/
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
0x80,0x0F,0x80,0x30,0x00,0x0C,0x80,0x03,0x00,0x0C,0x80,0x30,0x80,0x0 F,0x80,0x00,
/*m C206D*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0x00,0x80,0x3F,0x80,0x20,0x80,0x0 0,0x00,0x3F,
/*uc C7563*/
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 1,0x00,0x00,
/*h C6820*/
0x08,0x20,0xF8,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*ab C6162*/
0x00,0x00,0x00,0x19,0x80,0x24,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x3 F,0x00,0x20,
0x08,0x00,0xF8,0x3F,0x00,0x11,0x80,0x20,0x80,0x20,0x00,0x11,0x00,0x0 E,0x00,0x00,
/*ou C6F75*/
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
/*t C7420*/
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*ea C6561*/
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
0x00,0x00,0x00,0x19,0x80,0x24,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x3 F,0x00,0x20,
/*ch C6368*/
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 1,0x00,0x00,
0x08,0x20,0xF8,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
/*o C206F*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
/*th C7468*/
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
0x08,0x20,0xF8,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
/*er C6572*/
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
0x80,0x20,0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x20,0x80,0x00,0x80,0x0 1,0x00,0x00,
/*2 C2032*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x70,0x30,0x08,0x28,0x08,0x24,0x08,0x22,0x88,0x21,0x70,0x3 0,0x00,0x00,
/*0y C3079*/
0x00,0x00,0xE0,0x0F,0x10,0x10,0x08,0x20,0x08,0x20,0x10,0x10,0xE0,0x0 F,0x00,0x00,
0x80,0x80,0x80,0x81,0x80,0x8E,0x00,0x70,0x00,0x18,0x80,0x06,0x80,0x0 1,0x80,0x00,
/*ea C6561*/
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
0x00,0x00,0x00,0x19,0x80,0x24,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x3 F,0x00,0x20,
/*rs C7273*/
0x80,0x20,0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x20,0x80,0x00,0x80,0x0 1,0x00,0x00,
0x00,0x00,0x00,0x33,0x80,0x24,0x80,0x24,0x80,0x24,0x80,0x24,0x80,0x1 9,0x00,0x00,
/*a C2061*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0x00,0x00,0x00,0x19,0x80,0x24,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x3 F,0x00,0x20,
/*go C676F*/
0x00,0x00,0x00,0x6B,0x80,0x94,0x80,0x94,0x80,0x94,0x80,0x93,0x80,0x6 0,0x00,0x00,
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
/*.w C2E77*/
0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x80,0x0F,0x80,0x30,0x00,0x0C,0x80,0x03,0x00,0x0C,0x80,0x30,0x80,0x0 F,0x80,0x00,
/*e C6520*/
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*we C7765*/
0x80,0x0F,0x80,0x30,0x00,0x0C,0x80,0x03,0x00,0x0C,0x80,0x30,0x80,0x0 F,0x80,0x00,
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1
/*re C7265*/
0x80,0x20,0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x20,0x80,0x00,0x80,0x0 1,0x00,0x00,
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
/*g C2067*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x6B,0x80,0x94,0x80,0x94,0x80,0x94,0x80,0x93,0x80,0x6 0,0x00,0x00,
/*ui C7569*/
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
0x00,0x00,0x80,0x20,0x98,0x20,0x98,0x3F,0x00,0x20,0x00,0x20,0x00,0x0 0,0x00,0x00,
/*de C6465*/
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x88,0x10,0xF8,0x3 F,0x00,0x20,
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
/*d C6420*/
0x00,0x00,0x00,0x0E,0x00,0x11,0x80,0x20,0x80,0x20,0x88,0x10,0xF8,0x3 F,0x00,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*by C6279*/
0x08,0x00,0xF8,0x3F,0x00,0x11,0x80,0x20,0x80,0x20,0x00,0x11,0x00,0x0 E,0x00,0x00,
0x80,0x80,0x80,0x81,0x80,0x8E,0x00,0x70,0x00,0x18,0x80,0x06,0x80,0x0 1,0x80,0x00,
/*o C206F*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
/*ur C7572*/
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
0x80,0x20,0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x20,0x80,0x00,0x80,0x0 1,0x00,0x00,
/*i C2069*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x80,0x20,0x98,0x20,0x98,0x3F,0x00,0x20,0x00,0x20,0x00,0x0 0,0x00,0x00,
/*nt C6E74*/
0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
/*ui C7569*/
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
0x00,0x00,0x80,0x20,0x98,0x20,0x98,0x3F,0x00,0x20,0x00,0x20,0x00,0x0 0,0x00,0x00,
/*ti C7469*/
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x80,0x20,0x98,0x20,0x98,0x3F,0x00,0x20,0x00,0x20,0x00,0x0 0,0x00,0x00,
/*on C6F6E*/
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
0x80,0x20,0x80,0x3F,0x00,0x21,0x80,0x00,0x80,0x00,0x80,0x20,0x00,0x3 F,0x00,0x20,
/*,y C2C79*/
0x00,0x80,0x00,0xB0,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x80,0x80,0x80,0x81,0x80,0x8E,0x00,0x70,0x00,0x18,0x80,0x06,0x80,0x0 1,0x80,0x00,
/*ou C6F75*/
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
0x80,0x00,0x80,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x80,0x3 F,0x00,0x20,
/*s C2073*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x00,0x00,0x00,0x33,0x80,0x24,0x80,0x24,0x80,0x24,0x80,0x24,0x80,0x1 9,0x00,0x00,
/*we C7765*/
0x80,0x0F,0x80,0x30,0x00,0x0C,0x80,0x03,0x00,0x0C,0x80,0x30,0x80,0x0 F,0x80,0x00,
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
/*pt C7074*/
0x80,0x80,0x80,0xFF,0x00,0xA1,0x80,0x20,0x80,0x20,0x00,0x11,0x00,0x0
0x00,0x00,0x80,0x00,0x80,0x00,0xE0,0x1F,0x80,0x20,0x80,0x20,0x00,0x0 0,0x00,0x00,
/*m C206D*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0x00,0x80,0x3F,0x80,0x20,0x80,0x0 0,0x00,0x3F,
/*e C6520*/
0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x1 3,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,
/*of C6F66*/
0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1 F,0x00,0x00,
0x00,0x00,0x80,0x20,0x80,0x20,0xF0,0x3F,0x88,0x20,0x88,0x20,0x88,0x0 0,0x18,0x00,
/*f C6620*/
0x00,0x00,0x80,0x20,0x80,0x20,0xF0,0x3F,0x88,0x20,0x88,0x20,0x88,0x0 0,0x18,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
/*my C6D79*/
0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0x00,0x80,0x3F,0x80,0x20,0x80,0x0 0,0x00,0x3F,
0x80,0x80,0x80,0x81,0x80,0x8E,0x00,0x70,0x00,0x18,0x80,0x06,0x80,0x0 1,0x80,0x00
};
P2=0x00;
P0=0x00;
delayms(1000);
while(1) //while(1)使内容重复显示
{
///////////////////////////////////////////////////////////////扫描显示文字
//////////////////////////////////////////////////////////////// ///////半屏扫描x遍
for(ab=0;ab<=2;ab++){
P2=0x00;
P0=0xf0;
for(a=15;a>=0;a--)
{
P1=a;
delayms(10);
}
P2=0x00;
P0=0x0f;
for(a=15;a>=0;a--) {
P1=a;
delayms(10);
}
P2=0xf0;
P0=0x00;
for(a=15;a>=0;a--) {
P1=a;
delayms(10);
}
P2=0x0f;
P0=0x00;
for(a=15;a>=0;a--) {
P1=a;
delayms(10);
}
P2=0x00;
P0=0x00;
}
delayms(500);
///////////////////////////////////////////////////////////// for(f=0;f<=1632/2-16;f++){ //显示f+1个帧for(e=0;e<=4;e++){
c=f*2;
for(d=0;d<=15;d++) //一个帧显示4*15=60毫秒
{
P2=hzdot[c];c++;
P0=hzdot[c];c++;
P1=d;
delayms(1);
}
}
}
}//这个大括号属于while(1)
}
void delayms(unsigned int xms)
{
unsigned int i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
//若for语句中的两个变量都为unsigned int,且j=110时,i等于几,这个嵌套语句就延时约多少毫秒。

篇三:C语言是如何用16点阵方法输出汉字的
因此,汉字在汉字库中的具体位置计算公式为:94*(区号-1)+位号-1.
减1是因为数组是以0为开始而区号位号是以1为开始的.
这仅为以汉字为单位该汉字在汉字库中的位置,那么,如何得到以字节为单位得到该汉字在汉字库中的位置呢?
只需乘上一个汉字字模占用的字节数即可,
即:(94*(区号-1)+位号-1)*一个汉字字模占用字节数,而按每种汉字库的汉字大小不同又会得到不同的结果.
以16*16点阵字库为例,计算公式则为:(94*(区号-1)+(位号-1))*32.
汉字库文该从该位置起的32字节信息即记录了该字的字模信息.
了解点阵汉字及汉字库的构成原理后,显示汉字就变得简单.以16*16点阵字库为例,
通常的方法是:将文件工作指针移到需要的汉字字模处、将汉字库文件读入一2*16数组再用for循环一位位地显示.
#include"graphics.h"
#include"stdio.h"
main()
{int i=VGA,j=VGAHI,k;
unsigned char mat[16][2],chinease[3]="我";
FILE*HZK;
if((HZK=fopen("hzk16","rb"))==NULL)exit(0);
initgraph(&i,&j,"");
i=chinease[0]-0xa0;j=chinease[1]-0xa0;/*获得区码与位码*/ fseek(HZK,(94*(i-1)+(j-1))*32l,SEEK_SET);
fread(mat,32,1,HZK);
for(j=0;j<16;j++)
for(i=0;i<2;i++)
for(k=0;k<8;k++)
if(mat[j][i]&(0x80>>k))/*测试为1的位则显示*/
putpixel(i*8+k,j,WHITE);
getch();
closegraph();
fclose(HZK);。

相关文档
最新文档