反转法扫描键盘,串行口数据输出,74ls164驱动数码管显示P1口为扫按键特征码输入端P3.0,P3.1为串行口数据输出端74ls164为8位串行移位输入,并行8位串行输出的移位寄存器数码管为segmax2-ca共阳数码管程序代码如下:#includereg51.h#defineucharunsignedchar#defineuintunsignedintUnsignedintcodekey_tab[]={0xff,0xEE,0xDE,0xBE,0x7E,0xED,0xDD,0xBD,0x7D,0xEB,0xDB,0xBB,0x7B,0xE7,0xD7,0xB7,0x77};//扫按键的特征码unsignedintcodeLED_tab[]={0xff,0x03,0x9f,0x25,0x0d,0x99,0xb49,0x41,0x1f,0x01,0x09,0x11,0xc1,0xe5,0x85,0x21,0x71};//数码管显示的笔形码voidsbuf(ucharnum)//串行口数据输出函数{TI=0;SBUF=LED_tab[num];while(!TI);TI=0;}ucharkey_num()//扫描按键{uchari;uintl,s,key;l=0x0f;s=0xf0;while(l==0x0f){P1=0x0F;l=P1&0x0f;}//一直扫行码,等到扫到行码while(s==0xf0){P1=0xF0;s=P1&0xf0;}//一直扫列码,等到扫到列码key=l|s;for(i=0;i17;i++){if(key_tab[i]==key)break;}returni;}voidmain(){uchara;SCON=0x00;//串行口方式0sbuf(0);while(1){a=key_num();sbuf(a);}}