新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)驅(qū)動(dòng)矩陣按鍵與獨(dú)立按鍵源代碼

單片機(jī)驅(qū)動(dòng)矩陣按鍵與獨(dú)立按鍵源代碼

作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏

void delay(uint xms)
{
uint i, j;
for(i = xms; i > 0; i--)
for(j = 125; j > 0; j--);
}

本文引用地址:http://m.butianyuan.cn/article/201612/324622.htm


void keyscan()
{
if(key1 == 0)
{
delay(5);
if(key1 == 0)
{
fm = 0;
key = 0;
while(!key1);
delay(5);
while(!key1);
fm = 1;
}
}


if(key2 == 0)
{
delay(5);
if(key2 == 0)
{
fm = 0;
key++;
while(!key2);
delay(5);
while(!key2);
fm = 1;
}
}


if(key3 == 0)
{
delay(5);
if(key3 == 0)
{
fm = 0;
key--;
while(!key3);
delay(5);
while(!key3);
fm = 1;
}
}


}
void max_kanscan()
{

P3 = 0xfe;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{//按鍵檢測
temp = P3;
fm = 0;
switch(temp)
{
case 0xee: key = 1 * 1 *1;
break;
case 0xde: key = 2 * 2 *2;
break;
case 0xbe: key = 3 * 3 *3;
break;
case 0x7e: key = 4 * 4 *4;
break;
default:
break;
}
//按鍵釋放
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
fm = 1;
}
}


P3 = 0xfd;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{//按鍵檢測
temp = P3;
fm = 0;
switch(temp)
{
case 0xed: key = 5 * 5 *5;
break;
case 0xdd: key = 6 * 6 *6;
break;
case 0xbd: key = 7 * 7 *7;
break;
case 0x7d: key = 8 * 8 *8;
break;
default:
break;
}
//按鍵釋放
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
fm = 1;
}
}


P3 = 0xfb;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{//按鍵檢測
temp = P3;
fm = 0;
switch(temp)
{
case 0xeb: key = 9 * 9 *9;
break;
case 0xdb: key = 10 * 10 *10;
break;
case 0xbb: key = 11 * 11 *11;
break;
case 0x7b: key = 12 * 12 *12;
break;
default:
break;
}
//按鍵釋放
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
fm = 1;
}
}


P3 = 0xf7;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{//按鍵檢測
temp = P3;
fm = 0;
switch(temp)
{
case 0xe7: key = 13 * 13 *13;
break;
case 0xd7: key = 14 * 14 *14;
break;
case 0xb7: key = 15 * 15 *15;
break;
case 0x77: key = 16 * 16 *16;
break;
default:
break;
}
//按鍵釋放
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
fm = 1;
}
}

}


上一頁 1 2 下一頁

評(píng)論


技術(shù)專區(qū)

關(guān)閉