<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > AVR單片機矩陣鍵盤(pán)程序(2種方法)

AVR單片機矩陣鍵盤(pán)程序(2種方法)

作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò ) 收藏
AVR矩陣鍵盤(pán)2種方法實(shí)現!

普通方法:

本文引用地址:http://dyxdggzs.com/article/201611/323384.htm

#include//
#include//
#define uchar unsigned char//
#define uint unsigned int//
#define setb(val,bitn) (val|=(1<<(bitn)))//設置某IO口某位為1
#define clr(val,bitn) (val&=~(1<<(bitn)))//設置某IO口某位為0
#define get(val,bitn) (val&(1<<(bitn)))//讀取某位狀態(tài)如if(get(PORTC,7))即判斷PC7口是否為1
#pragma data:code//數組存放位置
const table[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e
};//共陽(yáng)數碼管0--9代碼
ucharnum,yin,temp;//鍵值碼及識別碼
voiddelay(uchar);//延時(shí)函數
void disy();//顯示函數
void skk()
{
for(yin=0;yin<2;yin++)
{
PORTD=0xfe;//將第一行置0,即檢測第一行
temp=PIND;//將值給tem
temp=temp&0xf0;//與0xf0與門(mén)一下,
while(temp!=0xf0)//判斷是否為0xf0
{
delay(10);//延時(shí)
temp=PIND;//將P1值再給tem
temp=temp&0xf0;//將值再與門(mén)
while(temp!=0xf0)//再次判斷是否為0xf0
{
temp=PIND;//確實(shí)按下了,將tem值裝回,以便下次判斷開(kāi)關(guān)語(yǔ)句,否則沒(méi)有它對應的值,如原來(lái)是ee,如果再按下是第二個(gè)鍵就不是de了
switch(temp)//開(kāi)關(guān)語(yǔ)句
{
case 0xee:num=0;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xde:num=1;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xbe:num=2;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0x7e:num=3;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
}
while(temp!=0xf0)//松手判斷,以便退出以上兩個(gè)while
{
temp=PIND;//給temp賦值
temp=temp&0xf0;//與門(mén)一下
}
}
}
}

for(yin=0;yin<2;yin++)
{
PORTD=0xfd;//將第一行置0,即檢測第一行
temp=PIND;//將值給tem
temp=temp&0xf0;//與0xf0與門(mén)一下,
while(temp!=0xf0)//判斷是否為0xf0
{
delay(10);//延時(shí)
temp=PIND;//將P1值再給tem
temp=temp&0xf0;//將值再與門(mén)
while(temp!=0xf0)//再次判斷是否為0xf0
{
temp=PIND;//確實(shí)按下了,將tem值裝回,以便下次判斷開(kāi)關(guān)語(yǔ)句,否則沒(méi)有它對應的值,如原來(lái)是ee,如果再按下是第二個(gè)鍵就不是de了
switch(temp)//開(kāi)關(guān)語(yǔ)句
{
case 0xed:num=4;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xdd:num=5;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xbd:num=6;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0x7d:num=7;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
}
while(temp!=0xf0)//松手判斷,以便退出以上兩個(gè)while
{
temp=PIND;//給temp賦值
temp=temp&0xf0;//與門(mén)一下
}
}
}
}
for(yin=0;yin<2;yin++)
{
PORTD=0xfb;//將第一行置0,即檢測第一行
temp=PIND;//將值給tem
temp=temp&0xf0;//與0xf0與門(mén)一下,
while(temp!=0xf0)//判斷是否為0xf0
{
delay(10);//延時(shí)
temp=PIND;//將P1值再給tem
temp=temp&0xf0;//將值再與門(mén)
while(temp!=0xf0)//再次判斷是否為0xf0
{
temp=PIND;//確實(shí)按下了,將tem值裝回,以便下次判斷開(kāi)關(guān)語(yǔ)句,否則沒(méi)有它對應的值,如原來(lái)是ee,如果再按下是第二個(gè)鍵就不是de了
switch(temp)//開(kāi)關(guān)語(yǔ)句
{
case 0xeb:num=8;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xdb:num=9;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xbb:num=10;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0x7b:num=11;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
}
while(temp!=0xf0)//松手判斷,以便退出以上兩個(gè)while
{
temp=PIND;//給temp賦值
temp=temp&0xf0;//與門(mén)一下
}
}
}
}
for(yin=0;yin<2;yin++)
{
PORTD=0xf7;//將第一行置0,即檢測第一行
temp=PIND;//將值給tem
temp=temp&0xf0;//與0xf0與門(mén)一下,
while(temp!=0xf0)//判斷是否為0xf0
{
delay(10);//延時(shí)
temp=PIND;//將P1值再給tem
temp=temp&0xf0;//將值再與門(mén)
while(temp!=0xf0)//再次判斷是否為0xf0
{
temp=PIND;//確實(shí)按下了,將tem值裝回,以便下次判斷開(kāi)關(guān)語(yǔ)句,否則沒(méi)有它對應的值,如原來(lái)是ee,如果再按下是第二個(gè)鍵就不是de了
switch(temp)//開(kāi)關(guān)語(yǔ)句
{
case 0xe7:num=12;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xd7:num=13;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0xb7:num=14;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
case 0x77:num=15;//與num值比較是否相等,如果相等就退出switch語(yǔ)句
break;//退出switch語(yǔ)句
}
while(temp!=0xf0)//松手判斷,以便退出以上兩個(gè)while
{
temp=PIND;//給temp賦值
temp=temp&0xf0;//與門(mén)一下
}
}
}

}
}


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: AVR單片機矩陣鍵

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>