#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit R=P2^0;
sbit W=P2^1;
sbit E=P2^2;
void show(unsigned long x );
void delay(unsigned int k);//延时
int keyc();//键盘扫描
void init();//LCD初始化
void write_com_1602(unsigned char command);//写命令
void write_data_1602(unsigned char datum);//写数据
void desplay(unsigned int a);//显示程序
unsigned int key;
unsigned char anjian(void) ;
void DelayMS(uint x)
{
uchar i;
while(x--)
for(i=0;i<250;i++);
}
uchar x;
void main()
{
unsigned long first,second,c;
unsigned long third ;
/// unsigned char flag ;//flag1;
//first=0;flag=1;
_nop_();
init();
P1=0x0f;
while(1)
{
while(P1==0x0f);
key=anjian();
if(key<11&&key>=0)
{
first=first*10+key;//key=0;
desplay(key);//显示第一位
// P1=0x0f;
while(P1!=0x0f);
delay(130);
}
if(key<17&&key>=13)
{
switch (key)
{
case 16: write_data_1602('+'); second=first; first=0; c=1;
break;
case 15: write_data_1602('-'); second=first; first=0; c=2;
break;
case 14: write_data_1602('*'); second=first; first=0; c=3;
break;
case 13: write_data_1602('/'); second=first; first=0; c=4;
break;
default: break;
delay(130);
}
delay(130);
}
if(key==12)
{
write_com_1602(0x80+0x40);//给AC送值
write_data_1602('=');
// third= first ;
switch (c)
{
case 1: third=second+first;
break;
case 2: third=second-first;
break;
case 3: third =second*first;
break;
|