資源描述:
《14單片機(jī) 4×4矩陣式鍵盤識別技術(shù)實驗》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、14.????4×4矩陣式鍵盤識別技術(shù)1.實驗任務(wù)如圖4.14.2所示,用AT89S51的并行口P1接4×4矩陣鍵盤,以P1.0-P1.3作輸入線,以P1.4-P1.7作輸出線;在數(shù)碼管上顯示每個按鍵的“0-F”序號。對應(yīng)的按鍵的序號排列如圖4.14.1所示3.系統(tǒng)板上硬件連線(1.??????把“單片機(jī)系統(tǒng)“區(qū)域中的P3.0-P3.7端口用8芯排線連接到“4X4行列式鍵盤”區(qū)域中的C1-C4 R1-R4端口上;(2.??????把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0-P0.7/AD7端口用8芯排線連接到“四路靜態(tài)數(shù)碼顯示模塊”區(qū)域中的任一個a
2、-h(huán)端口上;要求:P0.0/AD0對應(yīng)著a,P0.1/AD1對應(yīng)著b,……,P0.7/AD7對應(yīng)著h。4.?程序設(shè)計內(nèi)容(1.??????4×4矩陣鍵盤識別處理(2.??????每個按鍵有它的行值和列值 ,行值和列值的組合就是識別這個按鍵的編碼。矩陣的行線和列線分別通過兩并行接口和CPU通信。每個按鍵的狀態(tài)同樣需變成數(shù)字量“0”和“1”,開關(guān)的一端(列線)通過電阻接VCC,而接地是通過程序輸出數(shù)字“0”實現(xiàn)的。鍵盤處理程序的任務(wù)是:確定有無鍵按下,判斷哪一個鍵按下,鍵的功能是什么;還要消除按鍵在閉合或斷開時的抖動。兩個并行口中,一個輸出掃描碼,使
3、按鍵逐行動態(tài)接地,另一個并行口輸入按鍵狀態(tài),由行掃描值和回饋信號共同形成鍵編碼而識別按鍵,通過軟件查表,查出該鍵的功能。5.程序框圖圖4.14.36.匯編源程序KEYBUFEQU30HORG00HSTART:MOVKEYBUF,#2WAIT:MOVP3,#0FFHCLRP3.4MOVA,P3ANLA,#0FHXRLA,#0FHJZNOKEY1LCALLDELY10MSMOVA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