资源描述:
《4×4键盘矩阵控制条形LED显示》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、4×4键盘矩阵控制条形LED显示#include#include#defineucharunsignedchar#defineuintunsignedintucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00};ucharcodeKeyCodeTable[]={0x11,0x12,0x14,0x18,0x21
2、,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88};voidDelay(){uchari;for(i=0;i<200;i++);}ucharKeys_Scan(){ucharsCode,kCode,i,k;P1=0xf0;if((P1&0xf0)!=0xf0){Delay();if((P1&0xf0)!=0xf0){sCode=0xfe;for(k=0;k<4;k++){P1=sCode;if((P1&0xf0)!=0xf0){kCode=~
3、P1;for(i=0;i<16;i++){if(kCode==KeyCodeTable[i])returni;}}elsesCode=_crol_(sCode,1);}}}return-1;}voidmain(){ucharKeyNO=-1;uchari,P2_LED,P3_LED;while(1){KeyNO=Keys_Scan();if(KeyNO!=-1){P2_LED=0xff;P3_LED=0xff;for(i=0;i<=KeyNO;i++){if(i<8)P3_LED>>=1;elseP2_
4、LED>>=1;}P3=P3_LED;P2=P2_LED;}}}