按下矩阵键盘第一行时以1200bps发送,1,2,3,4,第二行时以2400bps发送5,6,7,8,第三行以4800bps发

2024-12-23 04:49:43
推荐回答(1个)
回答1:

你为什么不用一样的波特率呢?直接矩阵键盘扫描就好了!以前写的矩阵键盘,希望对你有帮助!
#include
#define uint unsigned int
#define uchar unsigned char
void delay(uint z);
uchar H_scan();
uchar L_scan();
uchar temp=0,L_num=0,H_num=0;
uint table[4][4]={ 0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void main()
{
P2=0x00;
while(1)
{
H_scan();
L_scan();
P0=table[H_num-1][L_num-1];
}
}
uchar H_scan()
{
P1=0x0f;
delay(2);
if(P1!=0x0f)
temp=P1;
temp=temp&0x0f;
switch(temp)
{
case 0x0e:H_num=1;break;
case 0x0d:H_num=2;break;
case 0x0b:H_num=3;break;
case 0x07:H_num=4;break;
}
return H_num;
}
uchar L_scan()
{
P1=0xf0;
delay(2);
if(P1!=0xf0)
temp=P1;
temp=temp&0xf0;
switch(temp)
{
case 0xe0:L_num=1;break;
case 0xd0:L_num=2;break;
case 0xb0:L_num=3;break;
case 0x70:L_num=4;break;
}
return L_num;
}
void delay(uint z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=115;y>0;y--);
}