用msp430g2553怎样扫描4*4键盘,并读取键盘值
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
这是网上一个程序例子,楼上的分析很到位,可以结合这个例子修改到G系列,关键要自己理解学会修改~
void Delay()
{
uint i,j;
for(i=3;i>0;i--)
for(j=112;j>0;j--);
}
uchar key_check()
{
uchar xh=0x01;
uchar i,val;
uchar temp,tp;
for(i=0;i<4;i++)
{
P1=~xh;
Delay();
temp=P1;
if((temp&0xf0)!=0xf0) //如果有键按下
{
tp=temp&0xf0; //查看高四位哪个为低电平
switch(tp)
{
case 0x70:val=i*4;break; //判断位置,计算键值
case 0xb0:val=i*4+1;break;
case 0xd0:val=i*4+2;break;
case 0xe0:val=i*4+3;break;
default: break;
}
}
xh<<=1;
}
return val; //返回键值
}