#include "reg51.h"
#include "code.h"
#define rs P20
#define rw P21
#define e P22
#define cs1 P23
#define cs2 P24
#define lcd P0
#define keydata P1
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P24=P2^4;
bit busy_bit=1;
#define unchar unsigned char
unchar i,j,k;
void delay10ms(void) //延时程序
{
for(j=3;j>0;j--)
for(k=214;k>0;k--);
}
char getkey() //按键判断
{
char i;
keydata=0x0f;
while(keydata==0x0f); //判断有无按键按下,无则等待
delay10ms(); //去抖动
keydata=0xef;
if(keydata==0xee) i=12;
else if(keydata==0xed) i=8;
else if(keydata==0xeb) i=4;
else if(keydata==0xe7) i=0;
keydata=0xdf;
if(keydata==0xde) i=13;
else if(keydata==0xdd) i=9;
else if(keydata==0xdb) i=5;
else if(keydata==0xd7) i=1;
keydata=0xbf;
if(keydata==0xbe) i=14;
else if(keydata==0xbd) i=10;
else if(keydata==0xbb) i=6;
else if(keydata==0xb7) i=2;
keydata=0x7f;
if(keydata==0x7e) i=15;
else if(keydata==0x7d) i=11;
else if(keydata==0x7b) i=7;
else if(keydata==0x77) i=3;
delay10ms(); //去抖动
keydata=0x0f;
return(i);
}
void checkbusy(void)
{
unchar state=0;
while(busy_bit)
{
lcd=0xFF;//空读操作
rw=1;
rs=0;
e=1;
e=1;
e=0;
lcd=0xFF;//再读才有效
rw=1;
rs=0;
e=1;
state=lcd;
e=0;
busy_bit=(bit)(state>>7);
}
}
displayon() //开显示
{
cs1=1;
cs2=0;
checkbusy();
rw=0;
rs=0;
lcd=0x3f;
e=1;
e=0;
cs1=0;
cs2=1;
checkbusy();
rw=0;
rs=0;
lcd=0x3f;
e=1;
e=0;
}
displayoff() //关显示
{
cs1=1;
cs2=0;
checkbusy();
rw=0;
rs=0;
lcd=0x3e;
e=1;
e=0;
cs1=0;
cs2=1;
checkbusy();
rw=0;
rs=0;
lcd=0x3e;
e=1;
e=0;
}
rwcmd(unchar cmd) //写指令
{
checkbusy();
rw=0;
rs=0;
lcd=cmd;
e=1;
e=0;
}
rwdata(unchar displaydata) //写数据
{
checkbusy();
rw=0;
rs=1;
lcd=displaydata;
e=1;
e=0;
}
void addresswrite(unchar x,unchar y) //写地址函数
{
unchar unit;
rwcmd(0x0c); //写z地址,一般z地址默认为0
unit=x+0xb8;
rwcmd(unit); //写x地址;
unit=y+0x40;
rwcmd(unit); //写y地址
}
void display(unchar beginx,unchar endx,unchar beginy,unchar endy,unchar block,unchar p,unchar colour) //反白显示
{ //显示 行开始 行结束 列开始 列结束 块选择 数组 反白与否
if(block==1) {cs1=0;cs2=1;}
if(block==2) {cs1=1;cs2=0;}
for(i=beginx;i<endx;i++)
{
addresswrite(i,beginy);
for(j=beginy;j<endy;j++)
{
if(colour==1)
switch(p)
{
case 1:rwdata(~character1[i][j]);break;
case 2:rwdata(~character2[i][j]);break;
case 3:rwdata(~character3[i][j]);break;
case 4:rwdata(~character4[i][j]);break;
case 5:rwdata(~character5[i][j]);break;
case 6:rwdata(~character6[i][j]);break;
case 7:rwdata(~character7[i][j]);break;
case 8:rwdata(~character8[i][j]);break;
case 9:rwdata(~character9[i][j]);break;
case 10:rwdata(~character10[i][j]);break;
case 11:rwdata(~character11[i][j]);break;
case 12:rwdata(~character12[i][j]);break;
case 13:rwdata(~character13[i][j]);break;
case 14:rwdata(~character14[i][j]);break;
case 15:rwdata(~character15[i][j]);break;
case 16:rwdata(~character16[i][j]);break;
case 17:rwdata(~character17[i][j]);break;
case 18:rwdata(~character18[i][j]);break;
case 19:rwdata(~character19[i][j]);break;
case 20:rwdata(~character20[i][j]);break;
case 21:rwdata(~character21[i][j]);break;
case 22:rwdata(~character22[i][j]);break;
case 23:rwdata(~character23[i][j]);break;
case 24:rwdata(~character24[i][j]);break;
case 25:rwdata(~character25[i][j]);break;
case 26:rwdata(~character26[i][j]);break;
case 27:rwdata(~character27[i][j]);break;
case 28:rwdata(~character28[i][j]);break;
default:break;
}
else if(colour==0)
switch(p)
{
case 1:rwdata(character1[i][j]);break;
case 2:rwdata(character2[i][j]);break;
case 3:rwdata(character3[i][j]);break;
case 4:rwdata(character4[i][j]);break;
case 5:rwdata(character5[i][j]);break;
case 6:rwdata(character6[i][j]);break;
case 7:rwdata(character7[i][j]);break;
case 8:rwdata(character8[i][j]);break;
case 9:rwdata(character9[i][j]);break;
case 10:rwdata(character10[i][j]);break;
case 11:rwdata(character11[i][j]);break;
case 12:rwdata(character12[i][j]);break;
case 13:rwdata(character13[i][j]);break;
case 14:rwdata(character14[i][j]);break;
case 15:rwdata(character15[i][j]);break;
case 16:rwdata(character16[i][j]);break;
case 17:rwdata(character17[i][j]);break;
case 18:rwdata(character18[i][j]);break;
case 19:rwdata(character19[i][j]);break;
case 20:rwdata(character20[i][j]);break;
case 21:rwdata(character21[i][j]);break;
case 22:rwdata(character22[i][j]);break;
case 23:rwdata(character23[i][j]);break;
case 24:rwdata(character24[i][j]);break;
case 25:rwdata(character25[i][j]);break;
case 26:rwdata(character26[i][j]);break;
}
}
}
}
/*********************menufunction*************************/
void menufunction(unchar floor,unchar menu)
{
/***************************显示层菜单**************************/
switch(menu)
{
case 1:
{
display(0,8,0,64,1,3,0);
display(0,8,0,64,2,4,0);
} break;
case 2:
{
display(0,8,0,64,1,5,0);
display(0,8,0,64,2,6,0);
} break;
case 3:
{
display(0,8,0,64,1,7,0);
display(0,8,0,64,2,8,0);
} break;
case 4:
{
display(0,8,0,64,1,9,0);
display(0,8,0,64,2,10,0);
} break;
case 5:
{
display(0,8,0,64,1,11,0);
display(0,8,0,64,2,12,0);
} break;
case 6:
{
display(0,8,0,64,1,13,0);
display(0,8,0,64,2,14,0);
} break;
case 7:
{
display(0,8,0,64,1,15,0);
display(0,8,0,64,2,16,0);
} break;
case 8:
{
display(0,8,0,64,1,17,0);
display(0,8,0,64,2,18,0);
} break;
case 9:
{
display(0,8,0,64,1,19,0);
display(0,8,0,64,2,20,0);
} break;
case 10:
{
display(0,8,0,64,1,21,0);
display(0,8,0,64,2,22,0);
} break;
case 11:
{
display(0,8,0,64,1,23,0);
display(0,8,0,64,2,24,0);
} break;
case 12:
{
display(0,8,0,64,1,25,0);
display(0,8,0,64,2,26,0);
} break;
case 13:
{
display(0,8,0,64,1,27,0);
display(0,8,0,64,2,28,0);
} break;
default: break;
} //层菜单显示
/********************************显示行***********************/
switch(floor)
{
case 1:
{
display(0,2,0,64,1,3,1);
} break; //作者简介反白,仿真QQ群正常显示
case 2:
{
display(2,4,0,64,1,3,1);
} break; //仿真QQ群反白,上下两行正常
case 3:
{
display(6,8,0,32,1,3,1);
} break; //功能反白,上一行正常
case 4:
{
} break; //显示作者简介内容
case 5:
{
} break; //显示QQ群信息
case 6:
{
display(0,4,0,32,1,9,1); //第二项正常显示
} break; //显示图形菜单第一项
case 7:
{
display(0,4,32,64,1,9,1);
} break; //图形第二项
case 8:
{
display(0,4,0,32,2,10,1);
} break; //图形第三项
case 9:
{
display(0,4,32,64,2,10,1);
} break; //图形第四项
case 10:
{
display(4,8,0,32,1,9,1); //图形第五项
} break;
case 11:
{
display(4,8,32,64,1,9,1);
} break; //图形第六项
case 12:
{
display(4,8,0,32,2,10,1);
} break; //图形第七项
case 13:
{
display(4,8,32,64,2,10,1);
} break; //图形第八项
case 14: /