1、wxyz-:前翻页4:ghi5:jkl6:mno+:后翻页1:?2:abc3:def回车键:输入状态和选字状态切换0:.和空格及回车键:*/请把这个帖子的内容保存为51t9py.c/-/源程序大公开(c) Copyright 20012003 xuwenjunAll Rights ReservedV1.00/标题: T9拼音输入法模块/文件名: 51t9py.c/版本: V1.00/修改人: 徐文军E-mail:xuwenjun/日期: 05-4-8/描述:/声明:以下代码仅免费提供给学习用途,但引用或修改后必须在文件中声明出处. /如用于商业用途请与作者联系.有问题请mailto xuwen
2、jun欢迎与我交流!/老版本: 无老版本文件名:/创建人: 02-11-051、很久以前的程序,根据网友张 凯、李 强的51py输入法子程序改编,增加索引、完善主程序、测试程序,使之在Keil下直接仿真2、在Keil环境下可以直接按“CtrlF5”键仿真,切换到在串口依次输入:3、由于Keil的模拟串口是单字节显示,汉字显示为乱码,所以要加挂RICHWIN或RichView这种会重新刷新显示的中文平台,或手工刷新屏幕(RichView可以到 下载)#includestdio.h#includePY_mb.h/#include51t9_MB.h51t9py_indexa.h#define CNT
3、LQ0x11#define CNTLS0x13#define DEL0x7F#define BACKSPACE0x08#define CR0x0D#define LF0x0Aunsigned char cpt9PY_Mblen;struct t9PY_index code* cpt9PY_Mb16;unsigned char t9PY_ime(char *strInput_t9PY_str)struct t9PY_index *cpHZ,*cpHZedge,*cpHZTemp;unsigned char i,j,cInputStrLength;cpt9PY_Mblen=0;/完全匹配组数j=0
4、;/j为匹配最大值cInputStrLength=strlen(strInput_t9PY_str);/输入拼音串长度/if(*strInput_t9PY_str=0)return(0);/如果输入空字符返回0/cpHZ=&(t9PY_index20);/查首字母索引/cpHZedge=t9PY_index2+sizeof(t9PY_index2)/sizeof(t9PY_index20);strInput_t9PY_str+;/指向拼音串第二个字母/while(cpHZ cpHZedge)/待查询记录条数for(i=0;i j) j=i+1;cpHZTemp=cpHZ;break;/发现字母
5、串不配,退出/if(i=cInputStrLength) & (cpt9PY_Mblen 0)return (*(cpt9PY_Mb0).PY_mb);elsereturn (PY_mb_space);void t9PY_Test(void)bit PYEnter=0;bit HZok=0;unsigned char temp;unsigned char temp2;unsigned char t9PYn=0;char idata inline16=0x00;idata char chinese_word3=;char tempchar,Add=0,i=0;struct t9PY_index
6、*cpTemp;cpTemp=t9PY_index2;printf (n按键 /:上一拼音 *:下一拼音 .和空格及回车键:输入状态和选字状态切换n);请按键:2-abc 3-def 4-ghi 5-jkl 6-mno 7-pqrs 8-tuv 9-wxyz nwhile(!HZok)tempchar=getchar();switch (tempchar)case 0:123456789if (PYEnter)inlinei=tempchar;i+;Add=0;t9PY_ime(inline);/if (t9PYn 0) t9PYn -;*t9PYn +;=cpt9PY_Mblen) t9PY
7、n -;-if (Add = 12) Add -= 12;=+if (Add 0) i-;inlinei=0x00;cpTemp=cpt9PY_Mbt9PYn;n./输入状态和选字状态切换 PYEnter =1;defaultHZok=1;rif (PYEnter)选if(cpTemp != PY_mb_space) & (tempchar) & (tempchar)t9PYn=0;%sn,inline);chinese_word0=*(*cpTemp).PY_mb+Add+(tempchar-)*2);chinese_word1=*(*cpTemp).PY_mb+Add+(tempchar-
8、)*2+1);printf (chinese_word);nprintf (*(cpTemp).PY); printf (*cpTemp).PY_mb+Add);n拼音1 2 3 4 5 6 7 8 9relse 拼for (temp=t9PYn;tempcpt9PY_Mblen;temp+)cpTemp=cpt9PY_Mbtemp;temp2=(strlen(*(cpTemp).PY_mb)-Add)/2);%2bd:%02bd:,temp,temp2);printf (*(cpTemp).PY_mb+Add);/-以下为测试程序-/#include #ifdef MONITOR51/* D
9、ebugging with Monitor-51 needschar code reserve 3 _at_ 0x23;/* space for serial interrupt if#endif/* Stop Exection with Serial Intr./* is enabledvoid main (void) char input_string=98/*-Setup the serial port for 1200 baud at 16MHz.-*/#ifndef MONITOR51SCON= 0x50;/* SCON: mode 1, 8-bit UART, enable rcvrTMOD |= 0x20;/* TMOD: timer 1, mode 2, 8-bit reloadTH1= 250;/* TH1:reload value for 9600 baud 11.0592MHz */TR1= 1;/* TR1:timer 1 runTI/* TI:set TI to send first char of UART#endifNote that an embedded program never exits (becausethere is no operating system to return to).Itmust loop and execute f
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1