📄 t9.c
字号:
/*-----------------------------------------------------------------------------------*/
/* --- 名称: T9拼音输入法 --- */
/* --- 设计: 马伟宇(puma)--- */
/* --- 版本: V1.0 --- */
/* --- Email: puma810719@yahoo.com.cn --- */
/* --- 完成时间: 2005.4.2 --- */
/* --- 改动时间:2005.4.4 增加小键盘输入,增加操作提示 --- */
/* --- 版权: 可以随意使用和改动,但必需注明原作者 --- */
/*-----------------------------------------------------------------------------------*/
#include<graphics.h>
#include<io.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<e:\tt9\index.c>
/*由于个人编译器问题,使用前,请将index.c的路径改成你所在目录的路径或者改成默认路径 */
/*>>>>>>>移植单片机中:<graphics.h><io.h><stdlib.h><conio.h>头文件去掉<<<<<<<<<*/
/*------------------------------------------------------------------------------------*/
/* ---程序中调用到的所有子函数--- */
/*------------------------------------------------------------------------------------*/
void initial();
void st_display();
void logo_display();
void error_display();
void output_hz();
void output_other();
int check_return();
void cancel_data();
void cancel_data1();
void cancel_data2();
void blueline();
unsigned char *show_hz_clue();
void get_hz_data();
void get_hz_index();
void show_other_clue();
void get_other_data();
void enter_r();
void input_work();
/*-------------------------------------------------------------------------------------*/
/* void initial() */
/* ---初始化子函数--- */
/* ---入口:无;返回:无--- */
/* ---功能:初始化图形和边框--- */
/*-------------------------------------------------------------------------------------*/
void initial()
{
int i;
int driver=DETECT,mode;
/*屏幕初始化*/
initgraph(&driver,&mode,"");
setcolor(9);
/*画显示的框和线*/
bar(100,100,536,255);
for(i=0;i<5;i++)
{
line(100,150+i,536,150+i);
}
line(100,101,175,101);
line(100,101,100,120);
line(100,120,175,120);
line(175,101,175,120);
printf("Hello Puma! \n");
printf("please input: 5 3 5 0 2 1 3 1 5 0 4 6 r r r r w w 1\n");
for(i=0;i<20;i++)printf("\n");
printf(">>> / or Q-up; * or W-down; - or R-input change; <<<\n");
printf(">>> 7-tuv; 8-wxyz; 9-cancel or back; <<<\n");
printf(">>> 4-jkl; 5-mno; 6-pqrs; <<<\n");
printf(">>> 1-abc; 2-def; 3-ghi; <<<\n");
printf(">>> 0-enter; <<<\n");
}
/*--------------------------------------------------------------------------------------*/
/* void st_display(unsigned char (*p1)[2]) */
/* ---输入切换显示子函数--- */
/* ---入口:无 ;返回:无--- */
/* ---功能:显示“拼音输入:”--- */
/*--------------------------------------------------------------------------------------*/
void st_display(unsigned char (*p1)[2])
{
int temp_1;
for(temp_1=0;temp_1<5;temp_1++)
{
output_hz(temp_1*16+103,103,*(*(p1+temp_1)+0),*(*(p1+temp_1)+1),9); /* ==调用 汉字输出子函数== */
}
}
/*--------------------------------------------------------------------------------------*/
/* void logo_display() */
/* ---logo显示子函数--- */
/* ---入口:无 ;返回:无--- */
/* ---功能:显示“拼音输入:”--- */
/*--------------------------------------------------------------------------------------*/
void logo_display()
{
int temp_1;
char logo[4]={15,20,12,0};
for(temp_1=0;temp_1<4;temp_1++)
{
output_other(temp_1*8+280,80,logo[temp_1],9,2); /* ==调用 其它输出子函数== */
} /* PUMA */
}
/*--------------------------------------------------------------------------------------*/
/* void error_display() */
/* ---出错显示子函数--- */
/* ---入口:无 ;返回:无--- */
/* ---功能:显示“error!please enter 9!”--- */
/*--------------------------------------------------------------------------------------*/
void error_display()
{
int temp_3;
char error[5]={4,17,17,14,17};
char warn1[6]={15,11,4,0,18,4};
char warn2[5]={4,13,19,4,17};
for(temp_3=0;temp_3<5;temp_3++)
{
output_other(temp_3*8+200,50,error[temp_3],44,1); /* error */
}
output_other(240,50,16,44,4); /* ! */
for(temp_3=0;temp_3<6;temp_3++)
{
output_other(temp_3*8+250,50,warn1[temp_3],44,1); /* please */
}
output_other(298,50,0,44,4);
for(temp_3=0;temp_3<5;temp_3++)
{
output_other(temp_3*8+306,50,warn2[temp_3],44,1); /* enter */
}
output_other(352,50,9,44,3); /* 9 */
output_other(360,50,16,44,4); /* ! */
}
/*---------------------------------------------------------------------------------------*/
/* void output_hz(int x_point,int y_point,int H,int L,int color) */
/* */
/* ---汉字输出子函数--- */
/* ---入口:x_point=屏幕X轴显示点,y_point=屏幕Y轴显示点,--- */
/* --- num_h=字库X轴数字,num_l=字库Y轴数字,color=字体颜色;返回:无--- */
/* ---功能:在屏幕上显示出汉字,根据num_h,num_l确定字模位置,在屏幕x,y上显示出来--- */
/*---------------------------------------------------------------------------------------*/
void output_hz(int x_point,int y_point,int H,int L,int color)
{
char buffer[32];
long int offset;
int t1,t2,t3;
FILE *fp;
if((fp=fopen("hzk16","rb"))==NULL) /*打开文件出错提示。"hzk16" "rb"--"打开的文件" "只读二进制数据"*/
{
printf("Can't open hzk16,please addit!");
getch();
closegraph();
exit(0);
}
offset=(94*(H-1)+(L-1))*32L; /*算偏移量,具体公式可查HZK16的定位算法*/
fseek(fp,offset,0); /*文件定位 fseek(文件类型指针,偏移量,起始点)起始点:0 文件开始;1 当前位置;2 文件末尾*/
fread(buffer,32,1,fp); /*读文件 fread(buffer,size,count,fp) count:要读多少个size字节数据 */
/* >>>>>>>移植单片机中:需修改fseek(),fread()并添加到HZK16去取字模数据的程序,然后存到buffer[32]中<<<<<<<<*/
for(t1=0;t1<16;t1++) /*一个汉字16*16=256点,需要32个字节保存(32*8=256)*/
{
for(t2=0;t2<2;t2++) /* 1 2 */
{ /* 3 4 */
for(t3=0;t3<8;t3++) /* ... ... */
{ /* 字模内二进制对应的排列顺序*/
if(((buffer[t1*2+t2]>>(7-t3))&0x1)!=NULL) /*判断当前字模的二进制是否为 “1”,是,则打印出点阵*/
{
putpixel(x_point+8*t2+t3,y_point+t1,color); /* 送往打印点阵函数putpixel(x点,y点,颜色),打印顺序和字模顺序一样 */
} /*==调用 在图形上显示点的子函数(头文件中)==*/
}
} /* >>>>>>>移植单片机中:修改所有putpixel()子程序为LCD上显示点的程序<<<<<<<<*/
}
fclose(fp);
}
/*-------------------------------------------------------------------------------------------*/
/* void output_other(int x_point,int y_point,int number,int color,int change) */
/* */
/* ---其它输出子函数--- */
/* ---入口:x_point,y_point=图形X,Y轴坐标,number=字母x轴坐标,--- */
/* --- color=字体颜色,change=选择当前输出类型;返回:无--- */
/* ---功能: 通过number找到字模(大写字母,小写字母,数字,标点符号),在图形的XY轴上显示--- */
/*-------------------------------------------------------------------------------------------*/
void output_other(int x_point,int y_point,int number,int color,int change)
{
int t1,t2;
for(t1=0;t1<16;t1++)
{
for(t2=0;t2<8;t2++)
{
if(change==1) /*change=1;输出小写字母*/
{
if(((small_en[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==调用 在图形上显示点的子函数(头文件中)==*/
}
}
if(change==2) /*change=2;输出大写字母*/
{
if(((large_en[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==调用 在图形上显示点的子函数(头文件中)==*/
}
}
if(change==3) /*change=3;输出数字*/
{
if(((num[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==调用 在图形上显示点的子函数(头文件中)==*/
}
}
if(change==4) /*change=4;输出标点符号*/
{
if(((sign[number][t1]>>(7-t2))&0x01)!=NULL)
{
putpixel(x_point+t2,y_point+t1,color); /*==调用 在图形上显示点的子函数(头文件中)==*/
}
}
}
}
}
/*-------------------------------------------------------------------------------------*/
/* int check_return(char v2) */
/* */
/* ---键盘输入数据判断并返回命令字子函数--- */
/* ---入口:当前键盘按下的字符;返回:根据字符得到的命令字--- */
/* ---功能:判断键盘按下的字符,返回一个该字符对应的命令字--- */
/*-------------------------------------------------------------------------------------*/
int check_return(char v2)
{
int re_num;
switch(v2)
{ /*按键功能*/
case '1':re_num=1;break; /*abc*/
case '2':re_num=2;break; /*def*/
case '3':re_num=3;break; /*ghi*/
case '4':re_num=4;break; /*jkl*/
case '5':re_num=5;break; /*mno*/
case '6':re_num=6;break; /*pqrs*/
case '7':re_num=7;break; /*tuv*/
case '8':re_num=8;break; /*wxyz*/
case '9':re_num=9;break; /*取消退格*/
case '0':re_num=0;break; /*确认*/
case 'q':re_num=10;break; /*上翻页*/
case '/':re_num=10;break; /*上翻页*/
case 'w':re_num=11;break; /*下翻页*/
case '*':re_num=11;break; /*下翻页*/
case 'r':re_num=12;break; /*输入状态切换*/
case '-':re_num=12;break; /*输入状态切换*/
case 'x':closegraph();exit(0);
default:re_num=20;break; /*其它输入无效*/
}
return(re_num);
}
/*------------------------------------------------------------------------------------*/
/* void cancel_data() */
/* ---退格子函数--- */
/* ---入口:无;返回:无--- */
/* ---功能:将输入框内的文字退格取消,一次退一个字母宽度(8*16)--- */
/*------------------------------------------------------------------------------------*/
void cancel_data()
{
m=m-8;
if(m<0)
{
m=416;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -