?? t9_v1.c
字號:
#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];
/**************************************************************************************************
*
*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);
}
/**************************************************************************************************
*
*在LCD的任意位置畫點的函數
*函數聲明:void point(uchar x,uchar y);
*函數參數:x為lcd的列坐標(0-127),y為lcd的縱坐標(0-63)
*利用此函數能在LCD12864的任意位置畫一個點
*
**************************************************************************************************/
void point(uchar x,uchar y)
{
uchar y1,y2,pp;
uchar datain;
pp=1;
y1=y>>3;
y2=y%8;
pp=pp<<y2;
if (x<64)
{
CS2=1;
CS1=0;
write_cmd(PAGE+y1);
write_cmd(COL+x);
datain=read_data();
write_cmd(PAGE+y1);
write_cmd(COL+x);
delay(10);
datain=read_data();
write_cmd(PAGE+y1);
write_cmd(COL+x);
datain=datain|pp;
write_data(datain);
}
else
{
CS2=0;
CS1=1;
write_cmd(PAGE+y1);
write_cmd(COL+x-64);
datain=read_data();
write_cmd(PAGE+y1);
write_cmd(COL+x-64);
delay(10);
datain=read_data();
write_cmd(PAGE+y1);
write_cmd(COL+x-64);
datain=datain|pp;
write_data(datain);
}
}
/**************************************************************************************************
*
*初始化LCD屏函數
*函數聲明:void init();
*函數參數:無
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -