資源描述:
《實(shí)驗(yàn)五鍵盤實(shí)驗(yàn)實(shí)驗(yàn)報(bào)告.docx》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、鍵盤掃描實(shí)驗(yàn)實(shí)驗(yàn)報(bào)告一、實(shí)驗(yàn)?zāi)康?.掌握線反轉(zhuǎn)法鍵盤掃描原理。2.了解單片機(jī)的輸入和輸出過(guò)程,理解單片機(jī)的數(shù)據(jù)采集過(guò)程。二、實(shí)驗(yàn)內(nèi)容單片機(jī)外接4x4鍵盤,通過(guò)線反轉(zhuǎn)法判斷按下的鍵,并在數(shù)碼管上顯示按鍵對(duì)應(yīng)的數(shù)字。第一行從左到右分別是開關(guān)K0,K1,K2,K3,第二行從左到右分別是K4,K5,K6,K7以此類推。當(dāng)按下Kn時(shí),在數(shù)碼管上顯示數(shù)字n。三、實(shí)驗(yàn)原理線翻轉(zhuǎn)法:先對(duì)行(R0-R3)置0,對(duì)列(R4-R7)置1。當(dāng)有鍵被按下時(shí),會(huì)把按鍵所在的列的電位從1變0,記錄下位置;然后再將行列翻轉(zhuǎn),記錄下按下鍵的所在行,兩數(shù)進(jìn)行或運(yùn)算,就可以得到一個(gè)唯一表示按下
2、鍵的數(shù)字。例如:假定R0-R7分別與單片機(jī)的P2.0-P2.7相連。先把R4-R7置1,R0-R3置0(通過(guò)指令MOVP2,#0F0H實(shí)現(xiàn))。當(dāng)鍵K5被按下時(shí),R5電位被拉低為低電平。此時(shí),P2口表示的數(shù)為:11010000(0xD0);然后再置R4-R7為0,R0-R3為1,此時(shí),R1電位被拉低為低電平,此時(shí),P2口表示的數(shù)為:00001101(0x0D)。將兩數(shù)相與取反,得到:00100010。如此類推,可以把十六個(gè)開關(guān)和得到的數(shù)字的關(guān)系計(jì)算出來(lái),如下表:對(duì)應(yīng)開關(guān)二進(jìn)制十六進(jìn)制對(duì)應(yīng)開關(guān)二進(jìn)制十六進(jìn)制K0000100010x11K8000101000x1
3、4K1001000010x21K9001001000x24K2010000010x41K10010001000x44K3100000010x81K11100001000x84K4000100100x12K12000110000x18K5001000100x22K13001010000x28K6010000100x42K14010010000x48K7100000100x82K15100010000x88四、實(shí)驗(yàn)過(guò)程1.連接好單片機(jī)及其外圍設(shè)備電路2.編寫匯編程序ORGLJMPKeyLJMPK7:CJNER2,#82H,K8ORG0100HMOVP0,#0F
4、8HInit:CLRP1.3LJMPKeyMOVP0,#0C0HK8:CJNER2,#14H,K9Key:MOVP2,#0F0HMOVP0,#080HMOVA,P2LJMPKeyMOVR1,AK9:CJNER2,#24H,K10MOVP2,#0FHMOVP0,#090HMOVA,P2LJMPKeyORLA,R1K10:CJNER2,#44H,K11CPLAMOVP0,#088HMOVR2,ALJMPKeyJNZKeyProK11:CJNER2,#84H,K12LJMPKeyMOVP0,#083HKeyPro:CJNER2,#11H,K1LJMPKeyMOV
5、P0,#0C0HK12:CJNER2,#18H,K13LJMPKeyMOVP0,#0C6HK1:CJNER2,#21H,K2LJMPKeyMOVP0,#0F9HK13:CJNER2,#28H,K14LJMPKeyMOVP0,#0A1HK2:CJNER2,#41H,K3LJMPKeyMOVP0,#0A4HK14:CJNER2,#48H,K15LJMPKeyMOVP0,#086HK3:CJNER2,#81H,K4LJMPKeyMOVP0,#0B0HK15:CJNER2,#88H,K16LJMPKeyMOVP0,#08EHK4:CJNER2,#12H,K5LJM
6、PKeyMOVP0,#099HK16:LJMPKeyLJMPKeyENDK5:CJNER2,#22H,K6MOVP0,#092HLJMPKeyK6:CJNER2,#42H,K7MOVP0,#082H五、實(shí)驗(yàn)結(jié)果1.當(dāng)按下開關(guān)Kn時(shí),數(shù)碼管能夠顯示對(duì)應(yīng)的數(shù)字。并且P2口的實(shí)際輸出值跟理論值完全符合。(也就是按下K0,K1,…,K15,數(shù)碼管上會(huì)顯示0,1,2,…,F)