1、/*编译环境:Keil 7.50A c51 */*/*包含头文件*/#include/*数码管表格*/unsigned char table=0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E;/*函数功能:延时子程序入口参数:出口参数:*/void delay(void)unsigned char i,j;for(i=0;i20;i+)for(j=0;j250;j+);/*函数功能:LED 显示子程序入口参数:i出口参数:*/void display(unsigned char i)P
2、2=0xfe;P0=tablei;/*函数功能:键盘扫描子程序入口参数:出口参数:*/void keyscan(void)unsigned char n;/扫描第一行P1=0xfe;n=P1;nif(n!=0xf0)delay();P1=0xfe;n=P1;nif(n!=0xf0)switch(n)case(0xe0):display(3);break;case(0xd0):display(2);break;case(0xb0):display(1);break;case(0x70):display(0);break;/扫描第二行P1=0xfd;n=P1;nif(n!=0xf0)delay()
3、;P1=0xfd;n=P1;nif(n!=0xf0)switch(n)case(0xe0):display(7);break;case(0xd0):display(6);break;case(0xb0):display(5);break;case(0x70):display(4);break;/扫描第三行P1=0xfb;n=P1;nif(n!=0xf0)delay();P1=0xfb;n=P1;nif(n!=0xf0)switch(n)case(0xe0):display(11);break;case(0xd0):display(10);break;case(0xb0):display(9);break;case(0x70):display(8);break;/扫描第四行P1=0xf7;n=P1;nif(n!=0xf0)delay();P1=0xf7;n=P1;nif(n!=0xf0)switch(n)case(0xe0):display(15);break;case(0xd0):display(14);break;case(0xb0):display(13);break;case(0x70):display(12);break;/*函数功能:主程序入口参数:出口参数:*/void main(void)while(1)keyscan();