|
http://#include /* common defines and macros */http://player.youku.com/player.php/sid/XMjk1MjQ2NzIw/v.swf
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
uchar smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};//数码管编码0~ 9
int i=0,j=0,k=0,l=0,m=0,n=0,shuju=0,p=0,num=0,flag=4;
int i1=0,j1=0,l1=0,k1=1,m1=0,m2=0;
int t0=0,t1=0,t2=0,t3=0,a1=0,a2=0,a3=0,a4=0,s1=0,s2=0,s3=0,flag2=0;
void delay(uchar t)
{
while (t--)
{;}
}
void display(uchar z){
PORTA=0XFF;
DDRA=smg[z];
}
void xianshi(int sj) {
PTT=0X00;
PERT=0X00;
m=sj%1000;
n=m%100;
p=n%10;
l=p;
k=n/10;
j=m/100;
i=sj/1000;
DDRT=0X01;
display(i);
delay(500);
display(10); //去残影。
DDRT=0x02;
display(j);
delay(500);
display(10);
DDRT=0x04;
display(k);
delay(500);
display(10);
DDRT=0x08;
display(l);
delay(500);
display(10);
}
void miaozhong(void) {
// int i=0,j=0;
PTT=0X00;
PERT=0X00;
DDRT=0x08;
display(i1);
for(m1=0;m1<10;m1++) {
for(l1=0;l1<10;l1++) {
for(k1=0;k1<6;k1++){
for(i1=0;i1<10;i1++){
for(j1=0;j1<680;j1++){
DDRT=0x00;
display(10);
delay(50);
DDRT=0x01;
display(m1);
delay(500);
display(10);
DDRT=0x00;
display(10);
delay(50);
DDRT=0x02;
display(l1);
delay(500);
DDRT=0x00;
display(10);
delay(50);
DDRT=0x04;
display(k1);
delay(500);
display(10);
DDRT=0x00;
display(10);
delay(50);
DDRT=0x08;
display(i1);
delay(500);
DDRT=0x00;
display(10);
delay(50);
// num=0;
flag=0;
m2=key();
if(flag!=0)
break;
}
if(flag!=0)
break;
}
if(flag!=0)
break;
}
if(flag!=0)
break;
}
if(flag!=0)
break;
}
if(flag!=0) {
// if(flag!=0){
l=0;k=0;j=0;i=0;flag=0;
}
}
void xianshi2(int sj)
{
void xianshi3(int a1,int a2,int a3,int a4);
void miaozhong();
//if(flag!=0){
switch(sj){
case 0:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 1:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 2:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 3:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 4:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 5:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 6:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 7:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 8:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 9:if(flag!=0){t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;}xianshi3(l,k,j,i);break;
case 111:if(flag!=0){
s1=i*1000+j*100+k*10+l;
l=0;k=0;j=0;i=0;flag=0;flag2=1;}xianshi3(l,k,j,i);break;
case 112:
if(flag!=0){
s1=i*1000+j*100+k*10+l;
l=0;k=0;j=0;i=0;flag=0;flag2=2;}xianshi3(l,k,j,i);break;
case 113:
if(flag!=0){
s1=i*1000+j*100+k*10+l;
l=0;k=0;j=0;i=0;flag=0;flag2=3;}xianshi3(l,k,j,i);break;
case 114:miaozhong();break;
case 115:if(flag!=0){l=0;k=0;j=0;i=0;flag=0;}xianshi3(l,k,j,i);break;
case 116:if(flag!=0){
switch(flag2){
case 1:
s2=i*1000+j*100+k*10+l;
s3=s1+s2;
m=s3%1000;
n=m%100;
p=n%10;
l=p;
k=n/10;
j=m/100;
i=sj/1000;break;
case 2:
s2=i*1000+j*100+k*10+l;
s3=s1*s2;
m=s3%1000;
n=m%100;
p=n%10;
l=p;
k=n/10;
j=m/100;
i=sj/1000;break;
case 3:
s2=i*1000+j*100+k*10+l;
s3=s1-s2;
m=s3%1000;
n=m%100;
p=n%10;
l=p;
k=n/10;
j=m/100;
i=sj/1000;break;
}
flag=0;flag2=0;}xianshi3(l,k,j,i);break;
// }
// t0=l;l=sj;t1=k;k=t0;t2=j;j=t1;i=t2;flag=0;
}
}
void xianshi3(int a1,int a2,int a3,int a4)
{
DDRT=0X01;
display(a4);
delay(5000);
display(10); //去残影。
DDRT=0x02;
display(a3);
delay(5000);
display(10);
DDRT=0x04;
display(a2);
delay(5000);
display(10);
DDRT=0x08;
display(a1);
delay(5000);
display(10);}
int key(void) {
int readkey;
int x_temp,y_temp;
DDRB=0X0f;
PUCR_PUPBE=1;
PORTB=0Xf0;
if(PORTB!=0xf0) {
delay(1000);
if(PORTB!=0xf0) {
PORTB&=0xf0;
x_temp=PORTB;
DDRB=0Xf0;
PORTB=0X0f;
// if(PORTB!=0x0f){
PORTB&=0X0f;
y_temp=PORTB;
readkey=(x_temp|y_temp);
PORTB=0X0F;
while(PORTB!=0X0F) {
delay(1000);
while(PORTB!=0X0F){
switch(readkey) {
case 0xee:num=1;break; //1
case 0xde:num=2;break;
case 0xbe:num=3;break;
case 0x7e:num=111;break;
case 0xed:num=4;break;
case 0xdd:num=5;break;
case 0xbd:num=6;break;
case 0x7d:num=112;break;
case 0xeb:num=7;break;
case 0xdb:num=8;break;
case 0xbb:num=9;break;
case 0x7b:num=113;break;
case 0xe7:num=0;break;
case 0xd7:num=115;break;
case 0xb7:num=116;break;
case 0x77:num=114;break;
}
// }
}
}
}flag=5;
}
return num;
}
void main() {
PORTB=0x00;
// void xianshi3(a1,a2,a3,a4);
// void xianshi2( sj);
EnableInterrupts;
for(;;) {
shuju=key();
xianshi2(shuju);
}
} |
|