#include
***it dula=P2^6;
***it wela=P2^7;
***it beep=P2^3;
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00
};
unsigned char z,num,wei,a,b,c,d,e,f,s1,s2,s3,s4,s5,s6,jia,jian,cheng,deng,chu,qingling,gongneng;
unsigned int flag_num,flag_num1,num1,num2,num3;
void keyscan();
void display(a,b,c,d,e,f);
void buf();
void delay(z);
/*******/
关键在于按键输入到LED中能够实现移位显示,在按键子程序中增加了对位的计算,同时显示子程序display()中
共有6位形参,程序中通过参数的传递实现了对数字的存储。显示子函数中delay()很重要不然会显示出错。
/**************/
void main()
{
num=0;wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
flag_num=0;
flag_num1=0;
num1=num2=num3=0;
while(1)
{
gongneng=jia|jian|cheng|chu;
keyscan();
buf();
if(gongneng == 1)
{
switch(wei)
{
case 1:num1=s1;
break;
case 2:num1=s1*10+s2;
break;
case 3:num1=s1*100+s2*10+s3;
break;
case 4:num1=s1*1000+s2*100+s3*10+s4;
break;
case 5:num1=s1*10000+s2*1000+s3*100+s4*10+s5;
break;
case 6:num1=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6;
break;
}
flag_num=1;
wei=0;
if(jia==1)
{
while(flag_num==1)
{
keyscan();
buf();
if(deng == 1)
{
switch(wei)
{
case 1:num2=s1;
break;
case 2:num2=s1*10+s2;
break;
case 3:num2=s1*100+s2*10+s3;
break;
case 4:num2=s1*1000+s2*100+s3*10+s4;
break;
case 5:num2=s1*10000+s2*1000+s3*100+s4*10+s5;
break;
case 6:num2=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6;
break;
}
wei=0;
num3=num1+num2;
if(num3<10)
{
a=16;
b=16;
c=16;
d=16;
e=16;
f=num3;
}
if(num3<100 && num3>=10)//关系运算符>=
{
a=16;
b=16;
c=16;
d=16;
e=num3/10;
f=num3%10;
}
if(num3<1000 && num3>=100)
{
a=16;
b=16;
c=16;
d=num3/100;
e=num3%100/10;
f=num3%100%10;
}
if(num3<10000 && num3>=1000)
{
a=16;
b=16;
c=num3/1000;
d=num3%1000/100;
e=num3%1000%100/10;
f=num3%100%100%10;
}
if(num3<100000 && num3>=10000)
{
a=16;
b=num3/10000;
c=num3%10000/1000;
d=num3%10000%1000/100;
e=num3%10000%1000%100/10;
f=num3%10000%1000%100%10;
}
if(num3<1000000 && num3>=100000)
{
a=num3/100000;
b=num3%100000/10000;
c=num3%100000%10000/1000;
d=num3%100000%10000%1000/100;
e=num3%100000%10000%1000%100/10;
f=num3%100000%10000%1000%100%10;
}
flag_num1=1;
while(flag_num1 ==1)
{
display(a,b,c,d,e,f);
keyscan();
if(qingling ==1)
{
flag_num=0;
flag_num1=0;
wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
num1=num2=num3=0;
}
}
}
}
}
if(jian==1)
{
while(flag_num==1)
{
keyscan();
buf();
if(deng == 1)
{
switch(wei)
{
case 1:num2=s1;
break;
case 2:num2=s1*10+s2;
break;
case 3:num2=s1*100+s2*10+s3;
break;
case 4:num2=s1*1000+s2*100+s3*10+s4;
break;
case 5:num2=s1*10000+s2*1000+s3*100+s4*10+s5;
break;
case 6:num2=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6;
break;
}
wei=0;
num3=num1-num2;
if(num3<10)
{
a=16;
b=16;
c=16;
d=16;
e=16;
f=num3;
}
if(num3<100 && num3>=10)
{
a=16;
b=16;
c=16;
d=16;
e=num3/10;
f=num3%10;
}
if(num3<1000 && num3>=100)
{
a=16;
b=16;
c=16;
d=num3/100;
e=num3%100/10;
f=num3%100%10;
}
if(num3<10000 && num3>=1000)
{
a=16;
b=16;
c=num3/1000;
d=num3%1000/100;
e=num3%1000%100/10;
f=num3%100%100%10;
}
if(num3<100000 && num3>=10000)
{
a=16;
b=num3/10000;
c=num3%10000/1000;
d=num3%10000%1000/100;
e=num3%10000%1000%100/10;
f=num3%10000%1000%100%10;
}
if(num3<1000000 && num3>=100000)
{
a=num3/100000;
b=num3%100000/10000;
c=num3%100000%10000/1000;
d=num3%100000%10000%1000/100;
e=num3%100000%10000%1000%100/10;
f=num3%100000%10000%1000%100%10;
}
flag_num1=1;
while(flag_num1 ==1)
{
display(a,b,c,d,e,f);
keyscan();
if(qingling ==1)
{
flag_num=0;
flag_num1=0;
wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
num1=num2=num3=0;
}
}
}
}
}
if(cheng==1)
{
// wei=0;
while(flag_num==1)
{
keyscan();
buf();
if(deng == 1)
{
switch(wei)
{
case 1:num2=s1;
break;
case 2:num2=s1*10+s2;
break;
case 3:num2=s1*100+s2*10+s3;
break;
case 4:num2=s1*1000+s2*100+s3*10+s4;
break;
case 5:num2=s1*10000+s2*1000+s3*100+s4*10+s5;
break;
case 6:num2=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6;
break;
}
wei=0;
num3=(num1*num2);
if(num3<10)
{
a=16;
b=16;
c=16;
d=16;
e=16;
f=num3;
}
if(num3<100 && num3>=10)
{
a=16;
b=16;
c=16;
d=16;
e=num3/10;
f=num3%10;
}
if(num3<1000 && num3>=100)
{
a=16;
b=16;
c=16;
d=num3/100;
e=num3%100/10;
f=num3%100%10;
}
if(num3<10000 && num3>=1000)
{
a=16;
b=16;
c=num3/1000;
d=num3%1000/100;
e=num3%1000%100/10;
f=num3%100%100%10;
}
if(num3<100000 && num3>=10000)
{
a=16;
b=num3/10000;
c=num3%10000/1000;
d=num3%10000%1000/100;
e=num3%10000%1000%100/10;
f=num3%10000%1000%100%10;
}
if(num3<1000000 && num3>=100000)
{
a=num3/100000;
b=num3%100000/10000;
c=num3%100000%10000/1000;
d=num3%100000%10000%1000/100;
e=num3%100000%10000%1000%100/10;
f=num3%100000%10000%1000%100%10;
}
flag_num1=1;
while(flag_num1 ==1)
{
display(a,b,c,d,e,f);
keyscan();
if(qingling ==1)
{
flag_num=0;
flag_num1=0;
wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
num1=num2=num3=0;
}
}
}
}
}
if(chu==1)
{
// wei=0;
while(flag_num==1)
{
keyscan();
buf();
if(deng == 1)
{
switch(wei)
{
case 1:num2=s1;
break;
case 2:num2=s1*10+s2;
break;
case 3:num2=s1*100+s2*10+s3;
break;
case 4:num2=s1*1000+s2*100+s3*10+s4;
break;
case 5:num2=s1*10000+s2*1000+s3*100+s4*10+s5;
break;
case 6:num2=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6;
break;
}
wei=0;
num3=(num1/num2);
if(num3<10)
{
a=16;
b=16;
c=16;
d=16;
e=16;
f=num3;
}
if(num3<100 && num3>=10)
{
a=16;
b=16;
c=16;
d=16;
e=num3/10;
f=num3%10;
}
if(num3<1000 && num3>=100)
{
a=16;
b=16;
c=16;
d=num3/100;
e=num3%100/10;
f=num3%100%10;
}
if(num3<10000 && num3>=1000)
{
a=16;
b=16;
c=num3/1000;
d=num3%1000/100;
e=num3%1000%100/10;
f=num3%100%100%10;
}
if(num3<100000 && num3>=10000)
{
a=16;
b=num3/10000;
c=num3%10000/1000;
d=num3%10000%1000/100;
e=num3%10000%1000%100/10;
f=num3%10000%1000%100%10;
}
if(num3<1000000 && num3>=100000)
{
a=num3/100000;
b=num3%100000/10000;
c=num3%100000%10000/1000;
d=num3%100000%10000%1000/100;
e=num3%100000%10000%1000%100/10;
f=num3%100000%10000%1000%100%10;
}
flag_num1=1;
while(flag_num1 ==1)
{
display(a,b,c,d,e,f);
keyscan();
if(qingling ==1)
{
flag_num=0;
flag_num1=0;
wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
num1=num2=num3=0;
}
}
}
}
}
}
if(qingling ==1)
{
flag_num=0;
flag_num1=0;
wei=0;
a=b=c=d=e=f=16;
s1=s2=s3=s4=s5=s6=0;
jia=jian=cheng=chu=deng=qingling=0;
num1=num2=num3=0;
}
}
}
/***********/
void keyscan()
{
unsigned char temp;
if(wei<8)
{
if(wei==7) wei=0;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
wei=wei+1;
break;
case 0xde:num=2;
wei=wei+1;
break;
case 0xbe:num=3;
wei=wei+1;
break;
case 0x7e:num=4;
wei=wei+1;
break;
}
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
beep=0;
}
beep=1;
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=5;
wei=wei+1;
break;
case 0xdd:num=6;
wei=wei+1;
break;
case 0xbd:num=7;
wei=wei+1;
break;
case 0x7d:num=8;
wei=wei+1;
break;
}
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
beep=0;
temp=temp&0xf0;
}
beep=1;
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=9;
wei=wei+1;
break;
case 0xdb:num=0;
wei=wei+1;
break;
case 0xbb:qingling=1;
break;
case 0x7b:deng=1;
break;
}
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
beep=0;
temp=temp&0xf0;
}
beep=1;
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:jia=1;
break;
case 0xd7:jian=1;
break;
case 0xb7:cheng=1;
break;
case 0x77:chu=1;
break;
}
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
beep=0;
temp=temp&0xf0;
}
beep=1;
}
}
}
//return num;
}
/**************/
void buf()
{
switch(wei)
{
case 1:a=b=c=d=e=16;
f=num;
s1=num;
break;
case 2:a=b=c=d=16;
e=s1;
f=num;
s2=num;
break;
case 3:a=b=c=16;
d=s1;
e=s2;
f=num;
s3=num;
break;
case 4:a=b=16;
c=s1;
d=s2;
e=s3;
f=num;
s4=num;
break;
case 5:a=16;
b=s1;
c=s2;
d=s3;
e=s4;
f=num;
s5=num;
break;
case 6:a=s1;
b=s2;
c=s3;
d=s4;
e=s5;
f=num;
s6=num;
break;
}
display(a,b,c,d,e,f);
}
void display(a,b,c,d,e,f)
{
dula=1;
P0=table[a];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
P0=0x00;
delay(1);//这个很重要不然就会有重影多个显示
dula=1;
P0=table[b];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
P0=0x00;
delay(1);
dula=1;
P0=table[c];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
P0=0x00;
delay(1);
dula=1;
P0=table[d];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
P0=0x00;
delay(1);
dula=1;
P0=table[e];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
P0=0x00;
delay(1);
dula=1;
P0=table[f];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
P0=0x00;
delay(1);
}
void delay(z)
{
int x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
/*
unsigned char keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
wei++;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=9;
break;
case 0xdb:num=0;
break;
}
}
}
}
return num;
}
void count()
{
num
} */ |