#include <REGX52.H>
#define uchar unsigned char
sbit Key0=P2^0;
uchar Key_scan();
uchar flag=0;
uchar code REG[]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void Delayms(unsigned int x)
{
unsigned int t;
while(x--)
{
for(t=0;t<120;t++);
}
}
uchar Key_scan(void)
{
if(Key0==0)
{
Delayms(10);
if(Key0==0)
{
flag++;
if(flag>=10)
{
flag=0;
}
}
while(Key0==0);
}
return flag;
}
void main()
{
while(1)
{
P0=REG[Key_scan()];
Delayms(10);
}
}
矩阵键盘按键计数
最新推荐文章于 2024-08-31 18:38:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)