单片机矩阵键盘的控制
下面是我的程序:#include
unsigned char temp;
char x;
unsigned char number[]={
0x3f,
0x06,
0x5b,
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f,
0x77,
0x7c,
0x39,
0x5e,
0x79,
0x71
};//¶¨ÒåÊý×é0ÖÁ15
void delay()
{
int i,j;
for(i=5;i<0;i--)
for(j=120;j<0;j--);
}//ÑÓʱ³ÌÐò
void main()
{
P1 = 0x00;//³ÌÐò¿ªÊ¼Ê±ÊýÂë¹Ü²»ÏÔʾ
while(1)
{
P3 = 0x7f;//ʹ°´¼üS1ÖÁS4ÏÔʾ0ÖÁ3
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
delay();
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
temp = P3;
switch(temp)
{
case 0x7e:x=0;
break;
case 0x7d:x=1;
break;
case 0x7b:x=2;
break;
case 0x77:x=3;
break;
}
while(temp!=0x0f)//Ìø³ö
{
temp=P3;
temp=temp&0x0f;
}
P1 = number[x];
}
}
//cond
P3 = 0xbf;//ʹ°´¼üS5ÖÁS8ÏÔʾ4ÖÁ7
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
delay();
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
temp = P3;
switch(temp)
{
case 0xbe:x=4;
break;
case 0xbd:x=5;
break;
case 0xbb:x=6;
break;
case 0xb7:x=7;
break;
}
while(temp!=0x0f)//Ìø³ö
{
temp=P3;
temp=temp&0x0f;
}
P1 = number[x];
}
}
//thirth
P3 = 0xdf;//ʹS9ÖÁS12ÏÔʾ8ÖÁb
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
delay();
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
temp = P3;
adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=a65eeeafe947a97a&k=switch&k0=switch&kdi0=0&luki=3&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=7aa947e9afee5ea6&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2001%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">switch(temp)
{
case 0xde:x=8;
break;
case 0xdd:x=9;
break;
case 0xdb:x=10;
break;
case 0xd7:x=11;
break;
}
while(temp!=0x0f)//Ìø³ö
{
temp=P3;
temp=temp&0x0f;
}
P1 = number[x];
}
}
//four
P3 = 0xef;//ʹS13ÖÁS16ÏÔʾCÖÁF
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
delay();
temp = P3;
temp = temp & 0x0f;
while(temp != 0x0f)
{
temp = P3;
switch(temp)
{
case 0xee:x=12;
break;
case 0xed:x=13;
break;
case 0xeb:x=14;
break;
case 0xe7:x=15;
break;
}
while(temp!= 0x0f)
{
temp = P3;
temp = temp&0x0f;
}
while(temp!=0x0f)//Ìø³ö
{
temp=P3;
temp=temp&0x0f;
}
P1 = number[x];
}
}
}
}
感觉好长,如果厉害点的话,应该可以做编得更短的,有时间只有再把它完善了。
单片机矩阵键 相关文章:
- 51单片机矩阵键盘与左右流水灯控制C程序(12-02)
- 51单片机矩阵键盘检测源代码(按键数码管显示0-F)(12-02)
- 单片机矩阵键盘改良后的程序(11-30)
- 单片机检测矩阵键盘.c文件(11-30)
- C51单片机的3*3矩阵键盘程序(11-30)
- MSP430单片机的4X4矩阵键盘C语言程序(11-30)