村网通总站 姬家寨村 455496.nync.com 欢迎您!
硬件电路设计:姬学瑞;软件程序编写:姬学瑞:版权所有,侵权必究!中国新乡市姬家寨村电子科技研究所研制!
/************************************************************************
/**单片机单词测试程序
/**设计一个以单片机为核心的单词记忆测试器;
/** 实现单词的录入(为使程序具有可演示性,单词不少于10个);
/**单词用按键控制依次在屏幕上显示,按键选择认识还是不认识,
/**也可以直接进入下一个或者上一个;
/**单词背完后给出正确率。
/*************************************************************************/
#define uchar unsigned char
#define uint unsigned int
#include <reg52.h>
#include "asc.h" //ASCII字模表
#include "12864.h" //12864液晶屏底层驱动程序
bit ERROR=1; //输入字符错误标志位
bit result=0; //输入结果对错的标志位,为0是正确
bit verify=1; //已按了确认键后清零
sbit ERR=P2^7;
uchar correctNUM; //统计测试正确的单词数,即得分
/*****************************************
/** 存储要测试的单词,放在ROM中
/****************************************/
uchar code S[10][5]={ "tree ", //树
"rain ", //雨
"water", //水
"fly ", //飞
"go ", //去
"fish ", //鱼
"snow ", //雪
"eat ", //吃
"rice ", //米
"ice ", //冰
} ;
uchar code SL[10]={4,4,5,3,2,4,4,3,4,3};//存储各测试单词的长度
uchar KeyNum[8]; //储存输入的单词
/*****************************************
/** 存储键盘的字母值 ,放在ROM中
/****************************************/
uchar code tab1[6][5]={{'a','b','c','d','e'},
{'f','g','h','i','j'},
{'k','l','m','n','o'},
{'p','q','r','s','t'},
{'u','v','w','x','y'},
{'z',1,2,3,4}};
//最后的 1234 键盘值为功能键, 1表示确定键,2表示不认识,3表示上一个,4表示下一个
/*************************************************
** 键盘扫描程序
*************************************************/
unsigned char kbscan() //键盘扫描
{
uchar hang,lie,key; //P1连行,P3连列
if(P1!=0xFF||P3!=0)
{
switch(P1&0xFF) //P1 扫行
{
case 0xFE:hang=5;break;//P1.0为第6行
case 0xFD:hang=4;break;//P1.1为第5行
case 0xFB:hang=3;break;//P1.2为第4行
case 0xF7:hang=2;break;//P1.3为第3行
case 0xEF:hang=1;break;//P1.4为第2行
case 0xDF:hang=0;break;//P1.5为第1行
}
P1=0; //P1全低电平
P3=0xFF;//P3全高电平
switch(P3&0xFF)
{
case 0xFE:lie=4;break; //P1.0为第5列
case 0xFD:lie=3;break; //P0.5为第4列
case 0xFB:lie=2;break; //P0.6为第3列
case 0xF7:lie=1;break; //P0.7为第2列
case 0xEF:lie=0;break; //P0.7为第1列
}
P1=0xFF; //P1全高电平
P3=0; //P3全低电平
while(P1!=0xFF||P3!=0); //按键松开后才返回值
key=tab1[hang][lie];
}
else
key='_';
return (key);
}
/************************************************************************
/** 主函数
/**
/**
/*************************************************************************/
void main(void)
{
uchar hz_Num; //用于计当前测试的是第几个词,第一个为0
uchar temp[8]; //用于送液晶屏显示的临时变量
uchar iword=0,Nword=0; //输入单词字母下一个计数
LCD12864_init(); //LCD12864初始化
ClearLCD(); //清屏
en_disp(2,1,11,Asc,"INPUT WORD:",1); //在第2行 第1列
en_disp(4,1,1,Asc,">",1); //在第5行,第2列开始显示
en_disp(6,0,8,Asc,"correct:",1); //在第7行,第1列开始显示
en_disp(6,80,5,Asc,"00/10",1); //在第7行 第81列
P1=0xFF; //P1全高电平
P3=0; //P3全低电平
while(1)
{
KeyNum[iword]=kbscan(); //扫描键盘的输入值,没按下时返回下横线
hz_disp(0,48,1,hz1+hz_Num*32,1); //在第1行,第49列开始显示测试的汉字
temp[0]=(hz_Num+1)/10+0x30; //将十进制数转换为ASCII字符
temp[1]=(hz_Num+1)%10+0x30; //算出测试汉字的序号的第一位和第二位
en_disp(0,20,1,Asc,":",1); //在第1行 第21列
en_disp(0,4,2,Asc,temp,1); //在第1行 第5列 显示测试序号
if(KeyNum[iword]!='_') //键盘有按键按下
{
if(KeyNum[iword]==1) //如果按下了确定键
{
if(SL[hz_Num]==iword&&verify) //输入长度等于测试单词的长度,则正确 ,verify表示按下了确认后有效一次
{
correctNUM+=1;
if(correctNUM>10)
{
correctNUM=10; //最多10个正确的
}
verify=0; //标志位清零
hz_Num++; //测试下一个单词
if(hz_Num==10) hz_Num=0; //最多设10个单词
temp[0]=(correctNUM)/10+0x30; //将十进制数转换为ASCII字符
temp[1]=(correctNUM)%10+0x30; //算出测试汉字的序号的第一位和第二位
en_disp(6,80,2,Asc,temp,1); //在第7行 第81列
iword=0;
Nword=0;
en_disp(4,16,8,Asc," ",1); //在第5行,第17列开始显示
}
}
else if(KeyNum[iword]==2||KeyNum[iword]==4)//如果按下了“不认识”或“下一个”键 ,直接跳到下一个单词
{
result=0; //跳下一个时错误灯灭
ERROR=0;
hz_Num++; //测试下一个单词
if(hz_Num==10) hz_Num=0; //最多设10个单词
iword=0;
Nword=0;
en_disp(4,16,8,Asc," ",1); //在第5行,第17列开始显示
}
else if(KeyNum[iword]==3) //如果按下了“上一个”键 ,直接跳到上一个单词
{
result=0; //跳下一个时错误灯灭
ERROR=0;
//测试下一个单词
if(hz_Num==0) hz_Num=10; //最多设10个单词
hz_Num--;
iword=0;
Nword=0;
en_disp(4,16,8,Asc," ",1); //在第4行,第16列开始显示
}
else if(S[hz_Num][iword]==KeyNum[iword]) //输入的字符与测试的标准字符比较
{ temp[0]=KeyNum[iword];
ERROR=0; //正确就标志位置0
en_disp(4,Nword+16,1,Asc,temp,1); //在第5行,第17列开始显示
iword++;
if(iword==8) iword=0;
Nword=iword*8;
verify=1;
}
else
{ temp[0]=KeyNum[iword];
ERROR=1; //错误就置1
en_disp(4,Nword+16,1,Asc,temp,1); //在第5行,第17列开始显示
iword++;
if(iword==8) iword=0;
Nword=iword*8;
}
result=ERROR|result; //0表示结果正确
}
ERR=!result; //错误指示灯
}
}
/***********************************************************
/* ASCII字模的数据表
/* 码表从0x20~0x7e 即ASCII的32-127
/* 纵向取模下高位 8x16
/*********************************************************/
unsigned char code Asc[] = // ASCII 表
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // - -
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0xFC,0xFC,0x38,0x00,0x00, // -!-
0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,
0x00,0x0E,0x1E,0x00,0x00,0x1E,0x0E,0x00, // -"-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0xF8,0xF8,0x20,0xF8,0xF8,0x20,0x00, // -#-
0x02,0x0F,0x0F,0x02,0x0F,0x0F,0x02,0x00,
0x38,0x7C,0x44,0x47,0x47,0xCC,0x98,0x00, // -$-
0x03,0x06,0x04,0x1C,0x1C,0x07,0x03,0x00,
0x30,0x30,0x00,0x80,0xC0,0x60,0x30,0x00, // -%-
0x0C,0x06,0x03,0x01,0x00,0x0C,0x0C,0x00,
0x80,0xD8,0x7C,0xE4,0xBC,0xD8,0x40,0x00, // -&-
0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00,
0x00,0x10,0x1E,0x0E,0x00,0x00,0x00,0x00, // -'-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF0,0xF8,0x0C,0x04,0x00,0x00, // -(-
0x00,0x00,0x03,0x07,0x0C,0x08,0x00,0x00,
0x00,0x00,0x04,0x0C,0xF8,0xF0,0x00,0x00, // -)-
0x00,0x00,0x08,0x0C,0x07,0x03,0x00,0x00,
0x80,0xA0,0xE0,0xC0,0xC0,0xE0,0xA0,0x80, // -*-
0x00,0x02,0x03,0x01,0x01,0x03,0x02,0x00,
0x00,0x80,0x80,0xE0,0xE0,0x80,0x80,0x00, // -+-
0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -,-
0x00,0x00,0x10,0x1E,0x0E,0x00,0x00,0x00,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, // ---
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -.-
0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00, // -/-
0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,
0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00, // -0-
0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00,
0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00, // -1-
0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,
0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00, // -2-
0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,
0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00, // -3-
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00, // -4-
0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,
0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00, // -5-
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00, // -6-
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00, // -7-
0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,
0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00, // -8-
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00, // -9-
0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, // -:-
0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, // -;-
0x00,0x00,0x08,0x0E,0x06,0x00,0x00,0x00,
0x00,0x80,0xC0,0x60,0x30,0x18,0x08,0x00, // -<-
0x00,0x00,0x01,0x03,0x06,0x0C,0x08,0x00,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00, // -=-
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,
0x00,0x08,0x18,0x30,0x60,0xC0,0x80,0x00, // ->-
0x00,0x08,0x0C,0x06,0x03,0x01,0x00,0x00,
0x18,0x1C,0x04,0xC4,0xE4,0x3C,0x18,0x00, // -?-
0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00,
0xF0,0xF8,0x08,0xC8,0xC8,0xF8,0xF0,0x00, // -@-
0x07,0x0F,0x08,0x0B,0x0B,0x0B,0x01,0x00,
0xE0,0xF0,0x98,0x8C,0x98,0xF0,0xE0,0x00, // -A-
0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,
0x04,0xFC,0xFC,0x44,0x44,0xFC,0xB8,0x00, // -B-
0x08,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00,
0xF0,0xF8,0x0C,0x04,0x04,0x0C,0x18,0x00, // -C-
0x03,0x07,0x0C,0x08,0x08,0x0C,0x06,0x00,
0x04,0xFC,0xFC,0x04,0x0C,0xF8,0xF0,0x00, // -D-
0x08,0x0F,0x0F,0x08,0x0C,0x07,0x03,0x00,
0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00, // -E-
0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00,
0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00, // -F-
0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00,
0xF0,0xF8,0x0C,0x84,0x84,0x8C,0x98,0x00, // -G-
0x03,0x07,0x0C,0x08,0x08,0x07,0x0F,0x00,
0xFC,0xFC,0x40,0x40,0x40,0xFC,0xFC,0x00, // -H-
0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,
0x00,0x00,0x04,0xFC,0xFC,0x04,0x00,0x00, // -I-
0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,
0x00,0x00,0x00,0x04,0xFC,0xFC,0x04,0x00, // -J-
0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,0x00,
0x04,0xFC,0xFC,0xC0,0xF0,0x3C,0x0C,0x00, // -K-
0x08,0x0F,0x0F,0x00,0x01,0x0F,0x0E,0x00,
0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x00, // -L-
0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00,
0xFC,0xFC,0x38,0x70,0x38,0xFC,0xFC,0x00, // -M-
0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,
0xFC,0xFC,0x38,0x70,0xE0,0xFC,0xFC,0x00, // -N-
0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00,
0xF0,0xF8,0x0C,0x04,0x0C,0xF8,0xF0,0x00, // -O-
0x03,0x07,0x0C,0x08,0x0C,0x07,0x03,0x00,
0x04,0xFC,0xFC,0x44,0x44,0x7C,0x38,0x00, // -P-
0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00,
0xF8,0xFC,0x04,0x04,0x04,0xFC,0xF8,0x00, // -Q-
0x07,0x0F,0x08,0x0E,0x3C,0x3F,0x27,0x00,
0x04,0xFC,0xFC,0x44,0xC4,0xFC,0x38,0x00, // -R-
0x08,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,
0x18,0x3C,0x64,0x44,0xC4,0x9C,0x18,0x00, // -S-
0x06,0x0E,0x08,0x08,0x08,0x0F,0x07,0x00,
0x00,0x1C,0x0C,0xFC,0xFC,0x0C,0x1C,0x00, // -T-
0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,
0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00, // -U-
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00, // -V-
0x01,0x03,0x06,0x0C,0x06,0x03,0x01,0x00,
0xFC,0xFC,0x00,0x80,0x00,0xFC,0xFC,0x00, // -W-
0x03,0x0F,0x0E,0x03,0x0E,0x0F,0x03,0x00,
0x0C,0x3C,0xF0,0xC0,0xF0,0x3C,0x0C,0x00, // -X-
0x0C,0x0F,0x03,0x00,0x03,0x0F,0x0C,0x00,
0x00,0x3C,0x7C,0xC0,0xC0,0x7C,0x3C,0x00, // -Y-
0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,
0x1C,0x0C,0x84,0xC4,0x64,0x3C,0x1C,0x00, // -Z-
0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0E,0x00,
0x00,0x00,0xFC,0xFC,0x04,0x04,0x00,0x00, // -[-
0x00,0x00,0x0F,0x0F,0x08,0x08,0x00,0x00,
0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00, // --
0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x00,
0x00,0x00,0x04,0x04,0xFC,0xFC,0x00,0x00, // -]-
0x00,0x00,0x08,0x08,0x0F,0x0F,0x00,0x00,
0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00, // -^-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -_-
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00, // -`-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xA0,0xA0,0xA0,0xE0,0xC0,0x00,0x00, // -a-
0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00,
0x04,0xFC,0xFC,0x20,0x60,0xC0,0x80,0x00, // -b-
0x08,0x0F,0x07,0x08,0x08,0x0F,0x07,0x00,
0xC0,0xE0,0x20,0x20,0x20,0x60,0x40,0x00, // -c-
0x07,0x0F,0x08,0x08,0x08,0x0C,0x04,0x00,
0x80,0xC0,0x60,0x24,0xFC,0xFC,0x00,0x00, // -d-
0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00,
0xC0,0xE0,0xA0,0xA0,0xA0,0xE0,0xC0,0x00, // -e-
0x07,0x0F,0x08,0x08,0x08,0x0C,0x04,0x00,
0x40,0xF8,0xFC,0x44,0x0C,0x18,0x00,0x00, // -f-
0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00,
0xC0,0xE0,0x20,0x20,0xC0,0xE0,0x20,0x00, // -g-
0x27,0x6F,0x48,0x48,0x7F,0x3F,0x00,0x00,
0x04,0xFC,0xFC,0x40,0x20,0xE0,0xC0,0x00, // -h-
0x08,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,
0x00,0x00,0x20,0xEC,0xEC,0x00,0x00,0x00, // -i-
0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0xEC,0xEC,0x00, // -j-
0x00,0x30,0x70,0x40,0x40,0x7F,0x3F,0x00,
0x04,0xFC,0xFC,0x80,0xC0,0x60,0x20,0x00, // -k-
0x08,0x0F,0x0F,0x01,0x03,0x0E,0x0C,0x00,
0x00,0x00,0x04,0xFC,0xFC,0x00,0x00,0x00, // -l-
0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,
0xE0,0xE0,0x60,0xC0,0x60,0xE0,0xC0,0x00, // -m-
0x0F,0x0F,0x00,0x0F,0x00,0x0F,0x0F,0x00,
0x20,0xE0,0xC0,0x20,0x20,0xE0,0xC0,0x00, // -n-
0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00,
0xC0,0xE0,0x20,0x20,0x20,0xE0,0xC0,0x00, // -o-
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
0x20,0xE0,0xC0,0x20,0x20,0xE0,0xC0,0x00, // -p-
0x40,0x7F,0x7F,0x48,0x08,0x0F,0x07,0x00,
0xC0,0xE0,0x20,0x20,0xC0,0xE0,0x20,0x00, // -q-
0x07,0x0F,0x08,0x48,0x7F,0x7F,0x40,0x00,
0x20,0xE0,0xC0,0x60,0x20,0x60,0xC0,0x00, // -r-
0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00,
0x40,0xE0,0xA0,0x20,0x20,0x60,0x40,0x00, // -s-
0x04,0x0C,0x09,0x09,0x0B,0x0E,0x04,0x00,
0x20,0x20,0xF8,0xFC,0x20,0x20,0x00,0x00, // -t-
0x00,0x00,0x07,0x0F,0x08,0x0C,0x04,0x00,
0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00, // -u-
0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00,
0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00, // -v-
0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00,
0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00, // -w-
0x07,0x0F,0x0C,0x07,0x0C,0x0F,0x07,0x00,
0x20,0x60,0xC0,0x80,0xC0,0x60,0x20,0x00, // -x-
0x08,0x0C,0x07,0x03,0x07,0x0C,0x08,0x00,
0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00, // -y-
0x47,0x4F,0x48,0x48,0x68,0x3F,0x1F,0x00,
0x60,0x60,0x20,0xA0,0xE0,0x60,0x20,0x00, // -z-
0x0C,0x0E,0x0B,0x09,0x08,0x0C,0x0C,0x00,
0x00,0x40,0x40,0xF8,0xBC,0x04,0x04,0x00, // -{-
0x00,0x00,0x00,0x07,0x0F,0x08,0x08,0x00,
0x00,0x00,0x00,0xBC,0xBC,0x00,0x00,0x00, // -|-
0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,
0x00,0x04,0x04,0xBC,0xF8,0x40,0x40,0x00, // -}-
0x00,0x08,0x08,0x0F,0x07,0x00,0x00,0x00,
0x08,0x0C,0x04,0x0C,0x08,0x0C,0x04,0x00, // -~-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0xC0,0x60,0x30,0x60,0xC0,0x80,0x00, // --
0x07,0x07,0x04,0x04,0x04,0x07,0x07,0x00,
};
/***********************************************************
/* 显示汉字的字模数组 存储要测试的单词中文
/* 纵向取模下高位 16x16
/* 下一个汉字为上一个汉字在数组中位置的 hz1+32
/*********************************************************/
unsigned char code hz1[] =
{
/*-- 文字: 树 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x10,0xD0,0xFF,0x50,0x90,0x68,0x88,0x68,0x18,0x90,0x10,0x10,0xFF,0x10,0x00,
0x04,0x03,0x00,0xFF,0x10,0x09,0x04,0x03,0x01,0x06,0x00,0x41,0x80,0x7F,0x00,0x00,
/*-- 文字: 雨 --*/ //+32
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x02,0xF2,0x32,0x52,0x92,0x12,0xFE,0x32,0x52,0x92,0x12,0xF2,0x02,0x02,0x00,
0x00,0x00,0xFF,0x01,0x02,0x04,0x00,0x7F,0x01,0x02,0x44,0x80,0x7F,0x00,0x00,0x00,
/*-- 文字: 水 --*/// +64
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x10,0x10,0x10,0x90,0x70,0x00,0xFF,0x20,0x60,0x90,0x08,0x04,0x00,0x00,0x00,
0x10,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x00,0x01,0x06,0x0C,0x18,0x08,0x00,
/*-- 文字: 飞 --*/// +96
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x60,0x90,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x10,0x21,0x40,0x78,0x00,
/*-- 文字: 去 --*/ // +128
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x08,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x00,0x01,0x21,0x71,0x29,0x25,0x27,0x21,0x21,0x21,0x29,0x71,0x21,0x01,0x01,0x00,
/*-- 文字: 鱼 --*/ //
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x20,0xF8,0x17,0x12,0x12,0xF2,0x12,0x1A,0x16,0x10,0xF0,0x00,0x00,0x00,
0x40,0x40,0x40,0x4F,0x49,0x49,0x49,0x4F,0x49,0x49,0x49,0x49,0x4F,0x40,0x40,0x00,
/*-- 文字: 雪 --*/ //
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x18,0x0A,0xAA,0xAA,0xAA,0x0A,0xFE,0x0A,0xAA,0xAA,0xAA,0x0A,0x18,0x08,0x00,
0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00,
/*-- 文字: 吃 --*/ //
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0xFC,0x04,0x04,0xFC,0x20,0x58,0x4F,0x4A,0x48,0x48,0xC8,0x08,0x08,0x08,0x00,
0x00,0x0F,0x02,0x02,0x07,0x00,0x30,0x48,0x44,0x42,0x41,0x40,0x40,0x40,0x70,0x00,
/*-- 文字: 米 --*/ //
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x22,0x24,0x38,0xE0,0x20,0xFF,0x60,0xA0,0x30,0x28,0x26,0x20,0x20,0x00,
0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0xFF,0x00,0x01,0x06,0x08,0x18,0x30,0x10,0x00,
/*-- 文字: 冰 --*/ //
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x02,0xCC,0x00,0x10,0x10,0xF0,0x10,0x00,0xFF,0xC0,0x20,0x38,0x10,0x00,0x00,
0x02,0x7E,0x21,0x10,0x0C,0x03,0x00,0x20,0x40,0x3F,0x00,0x03,0x04,0x18,0x08,0x00,
};
/*-----------------------------------------------------------*/
#define LCD_OFF 0x3E
#define LCD_ON 0x3F
#define Add_X 0xB8 //the start address of the page 0 ;(0~7)
#define Add_Y 0x40 //the start address of the Y counter ; (0~64)
#define Add_Z 0xC0 //the start address of the DDRAM ; (0~64)
/*-----------------------------------------------------------*/
#define LCD12864_DATA_PORT P0
sbit LCD12864_EN =P2^4;
sbit LCD12864_RW =P2^3; //0:write ; 1:read
sbit LCD12864_RS =P2^2; //0:the command .1:the data
sbit LCD12864_CS_L =P2^1; //select the left of the lcd when 1
sbit LCD12864_CS_R =P2^0;
sbit LCD12864_RST =P2^5;
/*------------------------------------------------------------*/
void delayus(unsigned int us)
{
while(us--);
}
void delayms(unsigned ms)
{
unsigned int i,j;
for (i=0;i<ms;i++)
{
for (j=0;j<1000;j++)
;
}
}
/*--------------------------select the LCD--------------------*/
void LCDSel(unsigned char sel)
{
switch(sel)
{
case 0: LCD12864_CS_L=0;LCD12864_CS_R=0;break;
case 1: LCD12864_CS_L=1;LCD12864_CS_R=0;break; //left
case 2: LCD12864_CS_L=0;LCD12864_CS_R=1;break; //right
default:;
};
}
/*------------------------------------------------------------*/
void WaitLCD()
{
unsigned char flag;
LCD12864_DATA_PORT=0xFF;
LCD12864_RW=1;
LCD12864_RS=0;
LCD12864_EN=1;
LCD12864_EN=1;
LCD12864_EN=0;
LCD12864_DATA_PORT=0xFF; //读有效数据
LCD12864_RW=1;
LCD12864_RS=0;
;
LCD12864_EN=1;
do
{
flag=LCD12864_DATA_PORT;
LCD12864_DATA_PORT=0xFF;
} while((flag&0x80)==1); //读BUSY信号//仅当第7位为0时才可操作
LCD12864_EN=0;
} //*/
/*-------------------------------------------------------------*/
void WriteDatToLCD12864(unsigned char dat)
{
WaitLCD();
LCD12864_RS=1; //the data
LCD12864_RW=0; //write
LCD12864_DATA_PORT=dat;
LCD12864_EN=1;
;
LCD12864_EN=0;
}
/*-------------------------------------------------------------*/
void WriteCmdToLCD12864(unsigned char cmd)
{
WaitLCD();
LCD12864_RS=0; //the command
LCD12864_RW=0; //write
LCD12864_DATA_PORT=cmd;
LCD12864_EN=1;
;
LCD12864_EN=0;
}
/*-------------------------------------------------------------*/
unsigned char ReadDatFromLCD12864(void)
{
unsigned char dat;
WaitLCD();
LCD12864_DATA_PORT=0xFF; //读空操作
LCD12864_RS=1; //the data
LCD12864_RW=1; //read
LCD12864_EN=1;
LCD12864_EN=1
;
LCD12864_EN=0;
LCD12864_DATA_PORT=0xFF; //来读有效数据
LCD12864_RS=1; //the data
LCD12864_RW=1; //read
LCD12864_EN=1;
dat=LCD12864_DATA_PORT;
LCD12864_EN=0;
return dat;
}
/*--------------------------------------------------------------*/
//from the chip manual
void LCD12864_init(void)
{
LCD12864_RST=0;
delayus(50);
LCD12864_RST=1;
LCDSel(0); //left and right
WriteCmdToLCD12864(LCD_OFF);
WriteCmdToLCD12864(LCD_ON);
}
//x:0~7
void SetX(unsigned char x) //写入X的地址
{
WriteCmdToLCD12864(Add_X+x);
}
//y:0~127
void SetY(unsigned char y)
{
WriteCmdToLCD12864(Add_Y+y);
}
//z:0~63
void SetZ(unsigned char z)
{
WriteCmdToLCD12864(Add_Z+z);
}
void ClearLCD()
{
int i,j;
LCDSel(0);
for(j=0;j<8;j++)
{
WriteCmdToLCD12864(LCD_ON);
SetX(j);
WriteCmdToLCD12864(Add_Y); //diffrent from SetY(0),SetY(64);
SetZ(0);
for (i=0;i<64;i++)
{
WriteDatToLCD12864(0x00);
}
}
}
/*-------------------------显示某点------------------*/
//左上角第一个点为原点,向下Y为轴,向右为X轴
//x:0~63~127 y:0~63
//flag : 0:擦除某个点
// 1:显示某个点
unsigned char code Tab[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void Dot(char x,char y,bit flag)
{
unsigned char dat;
// y=63-y; //坐标轴的移动和反转
if(x<64) //如果小于64则是在左半屏,CS1片选
{
LCDSel(1);
SetX(y/8); //set the page address
SetY(x); //set the Y adress
dat=ReadDatFromLCD12864();
if(flag)
dat=dat|(Tab[y%8]);
else
dat=dat&(~(Tab[y%8])); //擦除某个点就是在原来的数据基础上与上(要擦的位置的取反)
SetY(x); //set the Y adress
WriteDatToLCD12864(dat);
}
else if(x<128)
{
LCDSel(2);
SetX(y/8);
SetY(x-64);
dat=ReadDatFromLCD12864();
if(flag)
dat=dat|(Tab[y%8]);
else
dat=dat&(~(Tab[y%8]));
SetY(x-64);
WriteDatToLCD12864(dat);
}
}
//draw a line between point(x1,y1) and point(x2,y2)
//flag 0:erase the line 1:draw a line
void Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit flag)
{
unsigned char i;
unsigned char temp;
float k;
if(x1==x2)
{
if(y1>y2)
{ temp=x1;x1=x2;x2=temp;
temp=y1;y1=y2;y2=temp;
}
for(i=y1;i<=y2;i++)
{
Dot(x1,i,flag);
}
}else
{
if(x1>x2)
{
temp=x1;x1=x2;x2=temp;
temp=y1;y1=y2;y2=temp;
}
k=(float)(y2-y1)/(float)(x2-x1);
for(i=0;i<x2-x1;i++)
{
Dot(x1+i,(unsigned char)(y1+k*i),flag);
}
}
}
/*-------------------------------------------------------------*/
void Rect(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit flag)
{
Line(x1,y1,x2,y1,flag);
Line(x2,y1,x2,y2,flag);
Line(x2,y2,x1,y2,flag);
Line(x1,y2,x1,y1,flag);
}
/*-------------------------------------------------------------*/
/*void RectArea(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit flag)
{
unsigned char temp;
unsigned char i;
if(x1>x2)
{
temp=x1;x1=x2;x2=temp;
temp=y1;y1=y2;y2=temp;
}
for(i=0;i<=x2-x1;i++)
{
Line(x1+i,y1,x1+i,y2,flag);
}
}
//16*16
//x行 0~7 y列 0~127
//flag 0:汉字反白显示
void hz_disp(unsigned char x,unsigned char y,unsigned char n,unsigned char code * hz,bit flag)
{
unsigned char i,j;
for (j=0;j<n;j++)
{
//显示上半个汉字
for(i=0;i<16;i++)
{
//点的位置是在左还是右
if(y+16*j+i<64)
{
LCDSel(1);
WriteCmdToLCD12864(LCD_ON);
SetX(x);
SetZ(0);
SetY(y+16*j+i);
if(flag)
WriteDatToLCD12864(hz[32*j+i]);
else
WriteDatToLCD12864(~hz[32*j+i]);
}
else if(y+16*j+i<128)
{
LCDSel(2);
WriteCmdToLCD12864(LCD_ON);
SetX(x);
SetZ(0);
SetY(y+16*j+i-64);
if(flag)
WriteDatToLCD12864(hz[32*j+i]);
else
WriteDatToLCD12864(~hz[32*j+i]);
}
}
//显示下半个汉字
for(i=16;i<32;i++)
{
//先判断点是在左还是在右
if(y+16*j+i-16<64)
{ if(x+1<8) //最后一行显示上半个字
{
LCDSel(1);
WriteCmdToLCD12864(LCD_ON);
SetX(x+1);
SetZ(0);
SetY(y+16*j+i-16);
if(flag)
WriteDatToLCD12864(hz[32*j+i]);
else
WriteDatToLCD12864(~hz[32*j+i]);
}
}else if(y+16*j+i-16<127)
{
if(x+1<8) //最后一行
{
LCDSel(2);
WriteCmdToLCD12864(LCD_ON);
SetX(x+1);
SetZ(0);
SetY(y+16*j+i-16-64);
if(flag)
WriteDatToLCD12864(hz[32*j+i]);
else
WriteDatToLCD12864(~hz[32*j+i]);
}
}
}
}
}
//x:行0~7
//y:列0~127
//asc: 指向标准交换码
//string: 指向要显示的字符串
//flag: 0 反白显示
void en_disp(unsigned char x,unsigned char y,unsigned char n,unsigned char code *asc,unsigned char *string,bit flag)
{
unsigned char i,j,loc;
for (j=0;j<n;j++)
{
loc=string[j]-0x20; //确定要显示的字符在asc表中的位置(乘上16),见字模ASC表,H头文件
//显示上半个字母
for(i=0;i<8;i++)
{
//点的位置是在左还是右
if(y+8*j+i<64)
{
LCDSel(1);
WriteCmdToLCD12864(LCD_ON);
SetX(x);
SetZ(0);
SetY(y+8*j+i);
if(flag)
WriteDatToLCD12864(asc[16*loc+i]);
else
WriteDatToLCD12864(~asc[16*loc+i]);
}
else if(y+8*j+i<128)
{
LCDSel(2);
WriteCmdToLCD12864(LCD_ON);
SetX(x);
SetZ(0);
SetY(y+8*j+i-64);
if(flag)
WriteDatToLCD12864(asc[16*loc+i]);
else
WriteDatToLCD12864(~asc[16*loc+i]);
}
}
//显示下半个字母
for(i=8;i<16;i++)
{
//先判断点是在左还是在右
if(y+8*j+i-8<64)
{
if(x+1<8) //最后一行
{
LCDSel(1);
WriteCmdToLCD12864(LCD_ON);
SetX(x+1);
SetZ(0);
SetY(y+8*j+i-8);
if(flag)
WriteDatToLCD12864(asc[16*loc+i]);
else
WriteDatToLCD12864(~asc[16*loc+i]);
}
}else if(y+8*j+i-8<128)
{
if(x+1<8) //最后一行
{
LCDSel(2);
WriteCmdToLCD12864(LCD_ON);
SetX(x+1);
SetZ(0);
SetY(y+8*j+i-8-64);
if(flag)
WriteDatToLCD12864(asc[16*loc+i]);
else
WriteDatToLCD12864(~asc[16*loc+i]);
}
}
}
}
}
/******************************** END ************************************/
硬件电路设计:姬学瑞;软件程序编写:姬学瑞:版权所有,侵权必究!中国新乡市姬家寨村电子科技研究所研制!