#include<reg51.h> unsignedchar code LED_MOD_ANODE[]={0xc0,0xf9,0xa4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff}; unsignedchar code BIT_CONTROL[]={0x01,0x02,0x04,0x08}; unsignedchar LED_COM[]={0xff,0xff,0xff,0xff}; unsignedchar code key_buf[]={0xee,0xde,0xbe,0x7e, 0xed,0xdd,0xbd,0x7d, 0xeb,0xdb,0xbb,0x7b, 0xe7,0xd7,0xb7,0x77}; unsignedint n = 0; voiddelay(unsigned char m){ for(;m>0;m--){ unsigned char i; for(i=125;i>0;i--); } }
voiddisplay(){ unsigned char j; for(j=0;j<4;j++){ P0=LED_MOD_ANODE[LED_COM[j]]; P2=BIT_CONTROL[j]; delay(2); P2=0x00; } }
voidgetkey(void) interrupt 0 using 1{ char key_scan[]={0xef,0xdf,0xbf,0x7f}; unsigned char i=0,j=0; EA=0; for(i=0;i<4;i++){ P1=key_scan; for(j=0;j<16;j++){
if(P1==key_buf[j]){ LED_COM[0]=LED_COM[1]; LED_COM[1]=LED_COM[2]; LED_COM[2]=LED_COM[3]; LED_COM[3]=j; k++; if(n>4) {LED_COM[0]=LED_COM[1]=LED_COM[2]=0X10;n=1;} break; } } }P1=0x0f;EA=1; } voidmain(){ unsigned char i=0; LED_COM[0]=LED_COM[1]=LED_COM[2]=LED_COM[3]=0X10; display(); P1=0x0f; IT0=1; EX0=1; EA=1;
while(1){ display();} }
|