#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rw=P2^5;
sbit rs=P2^6;
sbit e=P2^7;
sbit led=P3^7;
sbit beep=P3^2;
uint key,num,k;
uint fuhao;flag,a,b,c,d,biao;
uint dat1[]={1,2,3,0x2b-0x30, 4,5,6,0x2d-0x30, 7,8,9,0x2a-0x30, 0,0x01-0x30,0x3d-0x30,0x2b-0x30 };//±£′???ê?μ?êy?Y
uchar code table[]="WE LOVE EE!";
uchar code table1[]="ZZJ SZX WK!";
void delay(uint i)
{
uint x,y;
for(x=i;x>0;x--)
for(y=1;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
e=0;
rw=0;
P0=com;
delay(500);
e=1;
delay(500);
e=0;
}
void write_date(uchar date)
{
rs=1;
rw=0;
e=0;
P0=date;
delay(500);
e=1;
delay(500);
e=0;
rs=0;
}
void init()
{
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
beep=~beep;
for (num=0;num<11;num++)
{ write_date(table[num]);
delay(10000);
}
write_com(0x80+0x40);
for (num=0;num<11;num++)
{ write_date(table1[num]);
delay(10000);
}
beep=0;
delay(10000);
write_com(0x01);
key=0;
num=0;
key=0;
num=0;
flag=0;
fuhao=0;
a=0;
b=0;
c=0;
d=0;
biao=0;
led=0;
}
void keyscan()
{
P1=0xfe;
if(P1!=0xfe)
{
delay(1000);
if(P1!=0xfe)
{
key=P1&0xf0;
switch(key)
{
case 0xe0: num=0;
break;
case 0xd0: num=1;
break;
case 0xb0: num=2;
break;
case 0x70: num=3;
break;
}
}
while(P1!=0xfe);
if(num==0||num==1||num==2)
{
if(flag==0)
{
a=a*10+dat1[num];
}
else
{
b=b*10+dat1[num];
}
}
if(num==3)
{
flag=1;
fuhao=1;
}
write_date(0x30+dat1[num]);
}
P1=0xfd;
if(P1!=0xfd)
{
delay(1000);
if(P1!=0xfd)
{
key=P1&0xf0;
switch(key)
{
case 0xe0: num=4;
break;
case 0xd0: num=5;
break;
case 0xb0: num=6;
break;
case 0x70: num=7;
break;
}
}
while(P1!=0xfd);
if(num==4||num==5||num==6)
{
if(flag==0) //??óD°′??·?o??ü
{
//led=1;
a=a*10+dat1[num];
}
else
{
//led=1;
b=b*10+dat1[num];
}
}
else
{
flag=1;
fuhao=2;//′?±í??o?
}
write_date(0x30+dat1[num]);
}
P1=0xfb;
if(P1!=0xfb)
{
delay(1000);
if(P1!=0xfb)
{
key=P1&0xf0;
switch(key)
{
case 0xe0: num=8;
break;
case 0xd0: num=9;
break;
case 0xb0: num=10;
break;
case 0x70: num=11;
break;
}
}
while(P1!=0xfb);
if(num==8||num==9||num==10)
{
if(flag==0) //??óD°′??·?o??ü
{
//led=1;
a=a*10+dat1[num];
}
else
{
//led=1;
b=b*10+dat1[num];
}
}
else
{
flag=1;
fuhao=3;//′?±í3?o?*
}
write_date(0x30+dat1[num]);
}
P1=0xf7;
if(P1!=0xf7)
{
delay(1000);
if(P1!=0xf7)
{
key=P1&0xf0;
switch(key)
{
case 0xe0: num=12;
break;
case 0xd0: num=13;
break;
case 0xb0: num=14;
break;
case 0x70: num=15;
break;
}
}
while(P1!=0xf7);
switch(num)
{
case 12:
if(flag==0) //??óD°′??·?o??ü
{
//led=1;
a=a*10+dat1[num];
write_date(0x30);
}
else
{
//led=1;
b=b*10+dat1[num];
write_date(0x30);
}
break;
case 13:
write_com(0x01);
a=0;
b=0;
flag=0;
fuhao=0;
break;
case 15:
flag=1;
fuhao=4;
write_date(0x2f);//3yo?/
break;
case 14:
if(fuhao==1)//?ó
{
write_com(0x4f+0x80);
write_com(0x04);//éè??1a±ê×óò?£??á??2?ò??ˉ
c=a+b;
while(c!=0) //ò???ò?????ê?
{
write_date(0x30+c%10);//??ê??á1?μ?×?oóò????ú0x4fμ?????
c=c/10;//è??°??μ??á1?êy?Y
}
write_date(0x3d); //??ê?μèóúo?=
a=0;
b=0;
flag=0;
fuhao=0;//è?2???3y?a0
}
if(fuhao==2) //??
{
write_com(0x4f+0x80);
write_com(0x04);//éè??1a±ê×óò?£??á??2?ò??ˉ
if(a>b)
c=a-b;
else
c=b-a;
while(c!=0) //ò???ò?????ê?
{
write_date(0x30+c%10);//??ê??á1?μ?×?oóò????ú0x4fμ?????
c=c/10;//è??°??μ??á1?êy?Y
}
if(a<b) write_date(0x2d); //??ê?-o?
write_date(0x3d); //??ê?μèóúo?=
a=0;
b=0;
flag=0;
fuhao=0;//è?2???3y?a0
}
if(fuhao==3)//3?·¨
{
write_com(0x4f+0x80);
write_com(0x04);//éè??1a±ê×óò?£??á??2?ò??ˉ
c=a*b;
while(c!=0) //ò???ò?????ê?
{
write_date(0x30+c%10);//??ê??á1?μ?×?oóò????ú0x4fμ?????
c=c/10;//è??°??μ??á1?êy?Y
}
write_date(0x3d); //??ê?μèóúo?=
a=0;
b=0;
flag=0;
fuhao=0;//è?2???3y?a0
}
if(fuhao==3)//3?·¨
{
write_com(0x4f+0x80);
write_com(0x04);//éè??1a±ê×óò?£??á??2?ò??ˉ
c=a*b;
while(c!=0) //ò???ò?????ê?
{
write_date(0x30+c%10);//??ê??á1?μ?×?oóò????ú0x4fμ?????
c=c/10;//è??°??μ??á1?êy?Y
}
write_date(0x3d); //??ê?μèóúo?=
a=0;
b=0;
flag=0;
fuhao=0;//è?2???3y?a0
}
if(fuhao==4)
{
k=0;
write_com(0x4f+0x80);
write_com(0x04);//éè??1a±ê×óò?£??á??2?ò??ˉ
c=(long)(((float)a/b)*1000);//????×a???along?£
while(c!=0) //ò???ò?????ê?
{
k++;
write_date(0x30+c%10);//??ê??á1?μ?×?oóò????ú0x4fμ?????
c=c/10;//è??°??μ??á1?êy?Y
if(k==3)
{
write_date(0x2e);
k=0;
}
}
if(a/b<0) //è?1?a±èbD?μ??°???′3yμ??á1?×?????ê?0
{
write_date(0x30);
}
write_date(0x3d); //??ê?μèo?
a=0;
b=0;
flag=0;
fuhao=0;//è?2???3y?a0
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
|