資源描述:
《鍵盤消抖相關(guān)資料》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、采用調(diào)度器,每隔xxms查詢一次采用先讓列線為高(或低),令行線依次為低(或高),查詢列線狀態(tài)如果有鍵按下,則返回鍵值函數(shù)uCHARKey_Number_Check(void){staticdataCHAROld_Key;CHARKey=KEYPAD_NO_NEW_DATA;uCHARindex;R1=0;if(C1==0)index=0;if(C2==0)index=1;if(C3==0)index=2;if(C4==0)index=3;R1=1;R2=0;if(C1==0)index=4;if(C2==0)index=5;if(C3==0)index=6;if(C
2、4==0)index=7;R2=1;R3=0;if(C1==0)index=8;if(C2==0)index=9;if(C3==0)index=10;if(C4==0)index=11;R3=1;R4=0;if(C1==0)index=12;if(C2==0)index=13;if(C3==0)index=14;if(C4==0)index=15;R4=1;if(Key==Old_Key)//Checktwicetoassurethereisakeypressed{//AvalidKeycheckedif(Key!=Last_valid_key_G)//NewKey!
3、Last_valid_key_G=Key;while(C1==0
4、
5、C2==0
6、
7、C3==0
8、
9、C4==0);returnindex;}else{Old_Key=Key;returnindex;}}888888888888888888888888888888888888888888888888888888888888888888888888888其實都是單片機教材的錯啦。比如動不動就用行例矩陣鍵盤一樣,呵呵……鍵盤掃描和任何中斷處理一樣,要盡量快的處量完,盡量不要做無謂的等待工作,降低系統(tǒng)響應(yīng)效率。不過要達(dá)到好的系統(tǒng)效果,能用RTOS的情況下,最好盡量用OS,可以大大
10、提高CPU的調(diào)度能力和系統(tǒng)實時性。順便發(fā)一個我用的鍵盤程序吧?;赨COSII,在系統(tǒng)時鐘HOOK函數(shù)中調(diào)用。鍵可用時發(fā)送鍵盤值到隊例。有長按鍵處理,并隨著按鍵時間的增加而加快重復(fù)產(chǎn)生鍵值能的頻率,對一些少鍵系統(tǒng)調(diào)節(jié)數(shù)值時很有用。voidKeyScan(void){staticINT32UbPreKeyBuf=0x3f,bCurKeyBuf=0x3f,bKeyOK=FALSE,bLongKey=FALSE,bKeyRepeatDelay;staticINT32UbTickCount=0;INT32UdwTemp;dwTemp=IO0PIN;bCurKeyBuf=0;b
11、CurKeyBuf=bCurKeyBuf
12、((dwTemp>>22)&0x08);//Key1(ESC_KEY)P0.25bCurKeyBuf=bCurKeyBuf
13、((dwTemp>>24)&0x04);//Key2(UP_KEY)P0.26bCurKeyBuf=bCurKeyBuf
14、((dwTemp>>29)&0x02);//Key3(DOWN_KEY)P0.30dwTemp=IO1PIN;bCurKeyBuf=bCurKeyBuf
15、((dwTemp>>16)&0x01);//Key4(ENTER_KEY)P1.16if(bCurKeyBuf!=0x0f){if(
16、bCurKeyBuf!=bPreKeyBuf){bPreKeyBuf=bCurKeyBuf;bTickCount=0;bKeyOK=FALSE;bLongKey=FALSE;if(bKeyRepeat==1){bKeyRepeat=0;OSQPost(KeyQueue,(void*)UPDATE_KEY);}}else{bTickCount++;if(bLongKey==FALSE){if(bTickCount==2){bKeyOK=TRUE;OSQPost(KeyQueue,(void*)bPreKeyBuf);}if(bTickCount==LONG_KEY_DE
17、LAY){bLongKey=TRUE;bKeyRepeatDelay=KEY_REPEAT_DELAY;bKeyOK=FALSE;OSQPost(KeyQueue,(void*)(bPreKeyBuf
18、0x80));bTickCount=0;}}else{if(bKeyRepeat==TRUE){if(bTickCount>=(bKeyRepeatDelay)){OSQPost(KeyQueue,(void*)(bPreKeyBuf
19、0x80));bTickCount=0;if(bKeyRepeatDelay>4)bKeyRepeatDelay--;