内容发布更新时间 : 2025/1/5 7:34:53星期一 下面是文章的全部内容请认真阅读。
/////4×4矩阵键盘按键为1-16,按键显示0- 9、a-f; ////////////////// #include
#define uchar unsigned char uchar key=0; uchar code
table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xc0};
void show(uchar key){P0=table[key];//显示数值}void Scan_key()//扫描键盘{uchar m;
P1=0xff;//数码管全亮
P2=0x0f;//P2口赋初值低位1高位0 m=P2;
switch (m){case 0x0e: {P2=0xf0; m=P2;
switch (m){case 0xe0:{key=0;show(key);break;} case 0xd0:{key=1;show(key);break;} case 0xb0:{key=2;show(key);break;} case 0x70:{key=3;show(key);break;}
1 / 3
default:
break;}break;}case 0x0d: {P2=0xf0; m=P2;
switch (m){case 0xe0:{key=4;show(key);break;} case 0xd0:{key=5;show(key);break;} case 0xb0:{key=6;show(key);break;} case 0x70:{key=7;show(key);break;} default:
break;}break;}case 0x0b: {P2=0xf0; m=P2;
switch (m){case 0xe0:{key=8;show(key);break;} case 0xd0:{key=9;show(key);break;} case 0xb0:{key=10;show(key);break;} case 0x70:{key=11;show(key);break;} default:
break;}break;}case 0x07:{P2=0xf0; m=P2;
switch (m){case 0xe0:{key=12;show(key);break;} case 0xd0:{key=13;show(key);break;}
2 / 3
case 0xb0:{key=14;show(key);break;} case 0x70:{key=15;show(key);break;} default:
break;}break;}default : break;}} void main(){while (1){Scan_Key();}}
3 / 3