本帖最后由 liziride 于 2020-10-29 16:01 编辑
4x4矩阵开关识别控制对应的led等,按下亮,松开灭
#include<reg51.h>
unsigned char row=0,col=0;
//循环调用
void a002_002() {
unsigned char val=16;
unsigned char tmp=0x01;
P1 = 0xF0;
if(P1 != 0xF0) {
P1 = 0x0F;
row=P1;
P1 = 0xF0;
col=P1;
switch(row | col) {
case 0xEE:val = 0;break;//14
case 0xDE:val = 1;break;//13
case 0xBE:val = 2;break;//11
case 0x7E:val = 3;break;//7
case 0xED:val = 4;break;
case 0xDD:val = 5;break;
case 0xBD:val = 6;break;
case 0x7D:val = 7;break;
case 0xEB:val = 8;break;
case 0xDB:val = 9;break;
case 0xBB:val = 10;break;
case 0x7B:val = 11;break;
case 0xE7:val = 12;break;
case 0xD7:val = 13;break;
case 0xB7:val = 14;break;
case 0x77:val = 15;break;
default:val = 16;break;
}
}
if(val < 8) {
tmp = tmp << val;
P2 = ~tmp & P2;
} else if(val < 16) {
val -= 8;
tmp = tmp << val;
P3 = ~tmp & P3;
}else {
P2=0xFF;
P3=0xFF;
}
}
|