#include <REG52.H>
#include <stdio.h>
#include<ziku.h>
#include<string.h>
#define uint unsigned int
#define uchar unsigned char
#define DISP_ON 0x3f
#define DISP_OFF 0x3e
#define COL 0x40 //列地址
#define PAGE 0xb8 //行地址
#define START_LINE 0xc0
#define LCD_BUS P2
#define LCD_CON P3
#define key_bus P1
//==========================================口定义=================================================
sbit CS1=LCD_CON^0; // CS1
sbit CS2=LCD_CON^1; // CS2
sbit E =LCD_CON^2; //液晶使能
sbit RW=LCD_CON^3; //液晶读写
sbit DI=LCD_CON^4; //液晶数据指
sbit sw0=P3^6; //OK
sbit sw1=P3^7; //Cancel
sbit SCL=P0^0;
sbit SDA=P0^1;
//===========================================END===================================================
//=============================================函数声明============================================
void display_h(uchar page,uchar col,uchar code *str,uchar n);
void display_e(uchar page,uchar col,uchar code *str,uchar n);
void display_num(uchar page,uchar col,uchar code *str,uchar n);
void line_v(uchar x,uchar y,uchar l);
void line_h(uchar x,uchar y,uchar l);
void init();
void cls();
void delay(uint); //延时程序
void write_cmd(uchar); //写命令操作字
void write_data(uchar); //写数据
uchar read_data(); //读数据
uchar key_ii();
unsigned char code *py_v1(unsigned char input_py_val[]);
void point(uchar x,uchar y);
unsigned char *T9PY(char *strInput_t9PY_str,uchar length);
//==============================================END================================================
#include<iic.h>
//========================================全局变量声明=============================================
uchar *p_py;
unsigned char PY_num;
struct t9PY_index code * T9PY_mb[4];
uchar state=0;//用state变量来指示程序的执行状态
uchar file_num=0;//用于记录短信的数目,初值为0
uchar length_h=0;//用于记录当前编辑的短信的长度
uchar row=0;
/**************************************************************************************************
*
*T9 输入法查找函数
*函数声明:unsigned char *T9PY(char *strInput_t9PY_str,uchar length);
*参数说明:strInput_t9PY_str为字符串的地址,length为字符串的长度
*函数功能:把找到的汉字点阵表的首地址放在数组T9PY_mb中
*
**************************************************************************************************/
unsigned char *T9PY(char *strInput_t9PY_str,uchar length)
{
struct t9PY_index *cpHZ,*cpHZedge;
unsigned char i;
PY_num=0;
if(*strInput_t9PY_str=='\0')return(0); //如果输入空字符返回0
cpHZ=&(t9PY_index2[0]); //查首字母索引
cpHZedge=t9PY_index2+sizeof(t9PY_index2)/sizeof(t9PY_index2[0]);
while(cpHZ < cpHZedge) //待查询记录条数
{
for(i=0;i<length;i++)
{
if(*(strInput_t9PY_str+i)!=*((*cpHZ).t9PY_T9+i)) //检查字符串匹配
{
break; //发现字母串不配,退出/
}
}
if(i==length&&PY_num<=3)
{
T9PY_mb[PY_num]=cpHZ;
PY_num++;
//break;
}
cpHZ++;
}
if (PY_num>0)
{
p_py=T9PY_mb[0]->PY;
return(T9PY_mb[0]->PY_mb);
}
else
{
return(PY_mb_a);
}
}
/**************************************************************************************************
* P17>---0----1----2----3
* | | | |
* P16>---4----5----6----7
* | | | |
* P15>---8----9----A----B
* | | | |
* P14>---C----D----E----F
* | | | |
* P13 P12 P11 P10
*4*4键盘输入函数
*函数声明:uchar key_ii();
*函数参数:无
*
*
*
**************************************************************************************************/
uchar key_ii()
{
uchar keycode=0xff,temp,i;
key_bus=0x0f;
temp=key_bus&0x0f;
if(temp!=0x0f) //有键按下
{
key_bus=0x7f;
for(i=0;i<4;i++)
{
temp=key_bus&0x0f;
if(temp==0x07)
{
keycode=i*4;
break;
}
else if(temp==0x0b)
{
keycode=i*4+1;
break;
}
else if(temp==0x0d)
{
keycode=i*4+2;
break;
}
else if(temp==0x0e)
{
keycode=i*4+3;
break;
}
key_bus=(key_bus>>1)|0x80;
}
while((key_bus&0x0f)!=0x0f) //等待释放
{
key_bus=0x0f;
}
}
return keycode;
}
/**************************************************************************************************
*
*
*
*
*
*
**************************************************************************************************/
uchar key()
{
uchar keycode=0,temp;
//键盘口,先置1
sw0=1; sw1=1;
temp=P3&0xD0;
if(temp!=0xD0)
{
sw0=1; sw1=1;
temp=P3&0x40;
if(temp==0)keycode=6;
temp=P3&0x80;
if(temp==0)keycode=7;
while(temp!=0xD0)
{
temp=P3&0xD0;
}
}
return keycode;
}
/**************************************************************************************************
*
*延时函数
*函数声明:void delay(uint t);
*函数参数:t
*
*
**************************************************************************************************/
void delay(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
/**************************************************************************************************
*
*向LCD写命令函数
*函数声明:void write_cmd(uchar cmd);
*函数参数:cmd(具体命令查看数据手册)
*
*
**************************************************************************************************/
void write_cmd(uchar cmd)
{
DI=0; RW=0;
LCD_BUS=cmd;
E=1;
E=0;
}
/**************************************************************************************************
*
*向LCD写数据函数
*函数声明:void write_data(uchar dout);
*函数参数:dout为要向LCD写的数据
*
*
**************************************************************************************************/
void write_data(uchar dout)
{
DI=1; RW=0;
LCD_BUS=dout;
E=1;
E=0;
}
/**************************************************************************************************
*
*从LCD的RAM中读数据
*函数声明:uchar read_data();
*返回参数:uchar型为RAM中的数据
*
*
**************************************************************************************************/
uchar read_data()
{
uchar din;
LCD_BUS=0xff;
DI=1; RW=1;
E=0;
E=0;
E=1;
E=1;
E=1;
din=LCD_BUS;
return din;
}
/**************************************************************************************************
*
*画竖线函数
*函数声明:void line_v(uchar x,uchar y,uchar l);
*函数参数:x,y分别为LCD的横向和纵向的坐标值,l为竖线的长度
*
*
**************************************************************************************************/
void line_v(uchar x,uchar y,uchar l)
{
uchar i;
for(i=0;i<l;i++) point(x,y+i);
}
/**************************************************************************************************
*
*画横线函数
*函数声明:void line_h(uchar x,uchar y,uchar l);
*函数参数:x,y分别为LCD的横向和纵向的坐标值,l为横线的长度
*
*
**************************************************************************************************/
void line_h(uchar x,uchar y,uchar l)
{
uchar i;
for(i=0;i<l;i++) point(x+i,y);
}
/*****************************************
T9拼音输入法的proteus仿真51单片机
需积分: 10 125 浏览量
2014-05-25
16:05:08
上传
评论 1
收藏 410KB ZIP 举报
a105865094
- 粉丝: 0
- 资源: 8