#include #define uint unsigned int #define uchar unsigned char uint n,tt; uchar qian,bai,shi,ge; sbit key1=P1^0; sbit key2=P1^1; sbit key3=P1^2; sbit key4=P1^3; void delay(uint x) { uint i,j; for(i=x;i>0;i--) for(j=110;j>0;j--); } uchar code tab[]={0xc0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; void init() { n=1752; qian=n/1000; bai=(n%1000)/100; shi=((n%1000)%100)/10; ge=((n%1000)%100)%10; } void keyscan() { if(key4==0) { delay(10); if(key4==0) { while(!key4); switch(ge) { case 0:ge++;break; case 1:ge++;break; case 2:ge++;break; case 3:ge++;break; case 4:ge++;break; case 5:ge++;break; case 6:ge++;break; case 7:ge++;break; case 8:ge++;break; case 9:ge=0;break; } } } if(key3==0) { delay(10); if(key3==0) { while(!key3); switch(shi) { case 0:shi++;break; case 1:shi++;break; case 2:shi++;break; case 3:shi++;break; case 4:shi++;break; case 5:shi=0;break; } } } if(key2==0) { delay(10); if(key2==0) { while(!key2); if(qian==0) { switch(bai) { case 0:bai++;break; case 1:bai++;break; case 2:bai++;break; case 3:bai++;break; case 4:bai++;break; case 5:bai++;break; case 6:bai++;break; case 7:bai++;break; case 8:bai++;break; case 9:bai=0;break; } } if(qian==1) { switch(bai) { case 0:bai++;break; case 1:bai++;break; case 2:bai++;break; case 3:bai++;break; case 4:bai++;break; case 5:bai++;break; case 6:bai++;break; case 7:bai++;break; case 8:bai++;break; case 9:bai=0;break; } } if(qian==2) { switch(bai) { case 0:bai++;break; case 1:bai++;break; case 2:bai++;break; case 3:bai=0;break; } } } } if(key1==0) { delay(10); if(key1==0) { while(!key1); if(bai==0) { switch(qian) { case 0:qian++;break; case 1:qian++;break; case 2:qian=0;break; } } if(bai==1) { switch(qian) { case 0:qian++;break; case 1:qian++;break; case 2:qian=0;break; } } if(bai==2) { switch(qian) { case 0:qian++;break; case 1:qian++;break; case 2:qian=0;break; } } if(bai==3) { switch(qian) { case 0:qian++;break; case 1:qian++;break; case 2:qian=0;break; } } if(bai==4) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==4) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==5) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==6) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==7) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==8) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } if(bai==9) { switch(qian) { case 0:qian++;break; case 1:qian=0;break; } } } } } void main () { P1=0xff; init(); TMOD=0x01; //È·¶¨¶¨Ê±Æ÷0¹¤×÷·½Ê½Îª01 TH0=(65536-50000)/256;//×°³õÖµ TL0=(65536-50000)%256; EA=1;//´ò¿ª×ÜÖÐ¶Ï ET0=1;//¿ª¶¨Ê±Æ÷0ÖÐ¶Ï TR0=1;//¿ªÊ¼¼Æʱ //EX0=1;EX1=1;IT0=1;IT1=1; while(1) { P2=0xef;P0=tab[ge];delay(1);P2=0xff;P0=0xff; P2=0xdf;P0=tab[shi];delay(1);P2=0xff;P0=0xff; P2=0xbf;P0=tab[bai]-0x80;delay(1);P2=0xff;P0=0xff; P2=0x7f;P0=tab[qian];delay(1);P2=0xff;P0=0xff; keyscan(); } } void zijia() interrupt 1 { TH0=(65536-50000)/256;//ÖØ×°³õÖµ TL0=(65536-50000)%256; tt++; if(tt==1200) { tt=0;ge++; if(ge==10) { ge=0;shi++; if(shi==6) { shi=0;bai++; if(qian==0) { if(bai==10) { bai=0;qian++; } } if(qian==1) { if(bai==10) { bai=0;qian++; } } if(qian==2) { if(bai==4) { bai=0;qian=0; } } } } } } 因篇幅问题不能全部显示,请点此查看更多更全内容