[C51代码]4*4键盘扫描
#include
#define uint unsigned int
#define uchar unsigned char
sbit key3 =P2^0; //按键的行检测信号
sbit key2 =P2^1;
sbit key1 =P2^2;
sbit key0 =P2^3;
sbit dis0 =P2^4;
sbit dis1 =P2^5;
sbit dis2 =P2^6;
sbit dis3 =P2^7;
sbit dis4 =P3^3;
uchar keyx,key;
uchar co
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint i)
{for(;i>0;i--)
;
}
uchar keyscan() //数码管显示扫描与键盘检测
{
static dis=0;
dis=(dis+1)%5;
dis0=1;dis1=1;dis2=1;dis3=1;dis4=1;
switch(dis) //位选码输出
{
case 0: dis0=0; break;
case 1: dis1=0; break;
case 2: dis2=0; break;
case 3: dis3=0; break;
case 4: dis4=0; break;
}
if(!key0) keyx=dis+1; //键盘的行检测与译码
if(!key1) keyx=dis+5;
if(!key2) keyx=dis+9;
if(!key3) keyx=dis+13;
return keyx;
}
void main(void)
{ while(1)
{
key=keyscan();
P0=disp[key];
delay(3000);
}
}
C51代码4*4键盘扫 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)