|
#include <reg52.H>
#include <intrins.h>
#include <lcd_drive.h>
#define uchar unsigned char
#define uint unsigned int
void delayms(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i = 0;i < 120;i++);
}
}
//-------??????-------
uint key()
{
uchar h = 0,l = 0;//???h,?l
uchar j_p;
P1 = 0x0f;
if(P1 != 0x0f)
{
delayms( 2 );
if(P1!=0x0f)
{
l = P1 & 0x0f ;
P1 = 0xf0;
h = P1 & 0xf0;
}
}
switch(l | h)
{
case 0x7e:j_p=0;break; //??0
case 0x7d:j_p=1;break; //??1
case 0x7b:j_p=2;break; //??2
case 0x77:j_p=3;break; //??3
case 0xbe:j_p=4;break; //??4
case 0xbd:j_p=5;break; //??5
case 0xbb:j_p=6;break; //??6
case 0xb7:j_p=7;break; //??7
case 0xde:j_p=8;break; //??8
case 0xdd:j_p=9;break; //??9
case 0xdb:j_p='+';break; //??a
case 0xd7:j_p='-';break; //??b
case 0xee:j_p='=';break; //??Enter
case 0xed:j_p='*';break; //??c
case 0xeb:j_p='/';break; //??e
case 0xe7:j_p='c';break; //????
default:return -1;break;
}
P1=0x0f;
while(P1!=0x0f);
return j_p;
}
void deplay(uchar j_p)
{
if(j_p != -1)
{
if(j_p >= 0 && j_p <= 9)
j_p+=48;
lcd_wdat(j_p);
}
}
void deplay_s(long a)
{
int n[10];
uint i=0;
while(a)
{
n[i]=a%10;
a/=10;
i++;
}
while(i)
deplay(n[--i]);
}
void main()
{
uint key();
void deplay(uchar j_p);
void deplay_s(long a);
uchar i=1;
uchar jp=-1;
uchar flat;
uint a,b;
delayms(10);
lcd_init();
lcd_clr();
lcd_wcmd(0x80);
while(1)
{
while(jp==-1)
jp=key();
deplay(jp);
switch (jp)
{
case '=': switch(flat)
{
case '+': a+=b; deplay_s(a); break;
case '-': a=b-a; deplay_s(a); break;
case '*': a*=b; deplay_s(a); break;
case '/': a=b/a; deplay_s(a); break;
default:break;
}
break;
case '+':flat='+';b=a;i=0;break;
case '-':flat='-';b=a;i=0;break;
case '*':flat='*';b=a;i=0;break;
case '/':flat='/';b=a;i=0;break;
case 'c':a=0;b=0;lcd_clr();break;
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:a=a*10*i+jp;i=1;break;
}
jp=-1;
}
}
|
|