如何实现矩阵键盘自由灵活控制数码管显示数字
#include
unsigned char code table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x10};
unsigned char t=0;
unsigned char i=0;
void Delay(unsigned char i)
{
unsigned char j;
for(; i>0; i--)
for(j=110; j>0; j--);
}
void DisplayLED(unsigned char n)
{
P0=table[n];
}
void Keycan() //判断 矩阵键盘是否被按下
{
unsigned char tmp, key;
P2=0xfe; //第四列
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
Delay(10); //
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
tmp=P2;
switch(tmp)
{
case 0xee: TR0=1; // 启动定时器T0
break;
case 0xde: key=8; //
break;
case 0xbe: key=4; /
break;
}
while(tmp!=0xf0)
{
tmp=P2;
tmp=tmp&0xf0;
}
if(tmp!=0xee)
{
DisplayLED(key);
}
}
}
P2=0xfd; //第三列
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
Delay(10); //
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
tmp=P2;
switch(tmp)
{
case 0xed: TR0=0, key=i; // 停止定时器T0
break;
case 0xdd: key=7; //
break;
case 0xbd: key=3; //
break;
}
while(tmp!=0xf0)
{
tmp=P2;
tmp=tmp&0xf0;
}
DisplayLED(key);
}
}
P2=0xfb; //第二列
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
Delay(10); //
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
tmp=P2;
switch(tmp)
{
case 0xeb: key=0 ; //
break;
case 0xdb: key=6; //
break;
case 0xbb: key=2; //
break;
}
while(tmp!=0xf0)
{
tmp=P2;
tmp=tmp&0xf0;
}
DisplayLED(key);
}
}
P2=0xf7; //第一列
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
Delay(10); //
tmp=P2;
tmp=tmp&0xf0;
if(tmp!=0xf0)
{
tmp=P2;
switch(tmp)
{
case 0xe7: key=9 ; //
break;
case 0xd7: key=5; /
break;
case 0xb7: key=1; //
break;
}
while(tmp!=0xf0)
{
tmp=P2;
tmp=tmp&0xf0;
}
DisplayLED(key);
}
}
}
void main()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
while(1)
{
Keycan();
if(t==20)
{
t=0;
P0=table[i];
Delay(1000);
i++;
if(i==10)
{
i=0;
}
}
}
}
void TimerLED() interrupt 1 using 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
矩阵键盘灵活控制数码管显示数 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)