#includereg52.htypedefunsignedcharuint8;typedefunsignedintuint16;typedefunsignedlongintuint32;sbitSp1=P3^1;//选择功能sbitSp2=P3^2;//减sbitSp3=P3^3;//加uint8i,j,k=0;uint16Number[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//延时程序voiddelay(uint16m){while(m--);}voiddelay_1s(uint16n){for(n=100;n0;n--)for(n=20;n0;n--)for(n=248;n0;n--);}//功能1抬起自加减Jj(){zz:j=0;delay(15000);if(!Sp3){delay(250);if(!Sp3){while(1){yy:j++;if(j==100)j=0;P0=Number[j/10];P2=Number[j%10];delay(20000);//扫描按键if(!Sp1)break;if(!Sp2){while(!Sp2);gotoxx;}if(!Sp3){P0=Number[0];P2=Number[0];while(!Sp3);gotozz;}}}}elseif(!Sp2){delay(250);if(!Sp2){j=100;while(1){xx:j--;if(j==0)j=100;P0=Number[j/10];P2=Number[j%10];delay(20000);//扫描按键if(!Sp1)break;if(!Sp2){P0=Number[0];P2=Number[0];while(!Sp2);gotozz;}if(!Sp3)gotoyy;}}}}//功能2自加减voidZj(uint32u,v){staticuint8flag=0;k=0;P0=Number[0];P2=Number[0];while(1){aa:if(!Sp1){delay(250);if(!Sp1)break;}if(!Sp3){delay(250);if(!Sp3){k++;if(k==100){k=0;}P0=Number[k/10];P2=Number[k%10];//长按自加==============for(u=20000;u0;u--){if(!Sp3)flag=1;elsebreak;}while(flag==1){if(!Sp3){k++;if(k==100){k=0;}P0=Number[k/10];P2=Number[k%10];delay(25000);}else{flag=0;break;}}}}//======================elseif(!Sp2){delay(250);if(!Sp2){k--;if(k==0|k==0-1){P0=Number[0];P2=Number[0];k=100;gotoaa;}P0=Number[k/10];P2=Number[k%10];//长按自减===============for(u=20000;u0;u--){if(!Sp2)flag=1;elsebreak;}while(flag==1){if(!Sp2){k--;if(k==0|k==0-1){P0=Number[0];P2=Number[0];k=100;gotodd;}P0=Number[k/10];P2=Number[k%10];dd:delay(25000);}else{flag=0;break;}}//=======================}}}}//P3^1即SP1判断功能Pd(){staticuint8i=0;while(1){if(!Sp1){delay(250);if(!Sp1){P0=Number[0];P2=Number[0];while(!Sp1);switch(i){case0:i=1;break;case1:i=0;break;default:break;}}}if(i==0)Jj();elseZj();}}//主程序main(){P0=Number[0];P2=Number[0];while(1){Pd();}}