按下16个矩阵键盘依次在数码管上显示1-16的平方。如按下第一个显示1,第二个显示4...Proteus仿真时,用的是元件库自带的矩阵键盘,分别代表1-16,仿真图如下:#includereg52.h#defineuintunsignedint#defineucharunsignedcharvoidinit();//初始化子程序voiddelay(uint);//延时子程序voiddisplay(uint);//显示子程序uintkeyscan();//按键扫描子程序ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchartemp;uintnum;voidmain(){init();while(1)display(keyscan());}voidinit(){num=0;P2=0;P1=0xff;}voiddelay(uintms){uintx,y;for(x=ms;x0;x--)for(y=110;y0;y--);}voiddisplay(uinta){ucharbai,ge,shi;if(a==0){P2=0;P1=0xff;}else{if(a10){P2=table[a];P1=0xfe;}elseif(a100){shi=a/10;ge=a%10;P2=table[shi];P1=0xfe;delay(1);P1=0xff;P2=table[ge];P1=0xfd;delay(1);P1=0xff;}elseif(a1000){bai=a/100;shi=a%100/10;ge=a%10;P2=table[bai];P1=0xfe;delay(1);P1=0xff;P2=table[shi];P1=0xfd;delay(1);P1=0xff;P2=table[ge];P1=0xfb;delay(1);P1=0xff;}}}uintkeyscan(){P3=0xfe;temp=P3;if(temp!=0xfe){delay(5);temp=P3;if(temp!=0xfe){switch(temp){case0xee:num=1;break;case0xde:num=4;break;case0xbe:num=9;break;case0x7e:num=16;break;}}while(temp!=0xfe)temp=P3;}P3=0xfd;temp=P3;if(temp!=0xfd){delay(5);temp=P3;if(temp!=0xfd){switch(temp){case0xed:num=25;break;case0xdd:num=36;break;case0xbd:num=49;break;case0x7d:num=64;break;}}while(temp!=0xfd)temp=P3;}P3=0xfb;temp=P3;if(temp!=0xfb){delay(5);temp=P3;if(temp!=0xfb){switch(temp){case0xeb:num=81;break;case0xdb:num=100;break;case0xbb:num=121;break;case0x7b:num=124;break;}}while(temp!=0xfb)temp=P3;}P3=0xf7;temp=P3;if(temp!=0xf7){delay(5);temp=P3;if(temp!=0xf7){switch(temp){case0xe7:num=169;break;case0xd7:num=196;break;case0xb7:num=225;break;case0x77:num=256;break;}}while(temp!=0xf7)temp=P3;}returnnum;}