单片机源程序如下:
- #include <reg52.h>
- #defineuchar unsigned char
- #defineuint unsigned int
- uchartemp;
- intyanp=20;
- uchari,key,yand;
- uchardispay_[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
- ucharyanp_[]={64104,64260,64400,64524,
- 64580,64685,64778,64820,64898,64968,65030,
- 65058,65110,65157,65178,65217};
- ucharyand_[3]={0xfe,0xef,0xee};
- sbitP3_7=P3^7;
- voiddelay(uint i)
- {
- uint m,n;
- for(m=i;m>0;m--)
- for(n=125;n>0;n--);
- }
- voidkeyscan()
- {
- P1=0xf0;
- if(P1!=0xf0)
- {
- delay(10);
- if(P1!=0xf0)
- {
- temp=P1;
- temp|=0x0f;
- P1=temp;
- switch(P1)
- {
- case0xee:key=4;yand=0;yanp=0;break;
- case0xde:key=5;yand=0;yanp=1;break;
- case 0xbe:key=6;yand=0;yanp=2;break;
- case0x7e:key=7;yand=0;yanp=3;break;
- case0xed:key=1;yand=1;yanp=4;break;
- case0xdd:key=2;yand=1;yanp=5;break;
- case0xbd:key=3;yand=1;yanp=6;break;
- case0x7d:key=4;yand=1;yanp=7;break;
- case0xeb:key=5;yand=1;yanp=8;break;
- case0xdb:key=6;yand=1;yanp=9;break;
- case0xbb:key=7;yand=1;yanp=10;break;
- case0x7b:key=1;yand=2;yanp=11;break;
- case0xe7:key=2;yand=2;yanp=12;break;
- case 0xd7:key=3;yand=2;yanp=13;break;
- case0xb7:key=4;yand=2;yanp=14;break;
- case0x77:key=5;yand=2;yanp=15;break;
- }
- }
- }
- }
- voiddiapay()
- {
- P2=yand_[yand];
- P0=dispay_[key];
- }
- voidmain()
- { TMOD=0x10;
- EA=1;
- ET1=1;
- while(1)
- {
- keyscan();
- diapay();
- delay(200);
- if(yanp!=20)
- {
- TR1=1;
- TH1=yanp_[yanp]/256;
- TL1=yanp_[yanp]%256;
- TR1=1;
- }
- } }
- voidt0(void) interrupt 3
- { TH1=yanp_[yanp]/256;
- TL1=yanp_[yanp]%256;
- P3_7=~P3_7;
- }
复制代码
|