![北郵數(shù)電實(shí)驗(yàn)猜拳游戲_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-5/25/c40a836c-d597-4910-ad95-f56ba2c1ae39/c40a836c-d597-4910-ad95-f56ba2c1ae391.gif)
![北郵數(shù)電實(shí)驗(yàn)猜拳游戲_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-5/25/c40a836c-d597-4910-ad95-f56ba2c1ae39/c40a836c-d597-4910-ad95-f56ba2c1ae392.gif)
![北郵數(shù)電實(shí)驗(yàn)猜拳游戲_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-5/25/c40a836c-d597-4910-ad95-f56ba2c1ae39/c40a836c-d597-4910-ad95-f56ba2c1ae393.gif)
![北郵數(shù)電實(shí)驗(yàn)猜拳游戲_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-5/25/c40a836c-d597-4910-ad95-f56ba2c1ae39/c40a836c-d597-4910-ad95-f56ba2c1ae394.gif)
![北郵數(shù)電實(shí)驗(yàn)猜拳游戲_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-5/25/c40a836c-d597-4910-ad95-f56ba2c1ae39/c40a836c-d597-4910-ad95-f56ba2c1ae395.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、 17班05號侯智超數(shù)電實(shí)驗(yàn)設(shè)計(jì)報(bào)告數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告題目:猜拳游戲的設(shè)計(jì)與實(shí)現(xiàn)姓名: 學(xué)院: 專業(yè): 通信工程 學(xué)號: 班內(nèi)序號: 摘要說明:本實(shí)驗(yàn)在Quartus軟件環(huán)境下,利用實(shí)驗(yàn)室集成芯片,使用VHDL語言編寫程序?qū)崿F(xiàn)一個(gè)猜拳小游戲的功能。整個(gè)系統(tǒng)的設(shè)計(jì)過程中,采用了up _to_ down的設(shè)計(jì)思想,完成了編碼和譯碼輸出到8X8點(diǎn)陣和數(shù)碼管顯示分?jǐn)?shù)的功能,對應(yīng)共有三個(gè)模塊。關(guān)鍵詞:編碼譯碼 VHDL 模塊 一 設(shè)計(jì)課題實(shí)驗(yàn)?zāi)康募叭蝿?wù)要求:本電路可供甲乙二人進(jìn)行猜拳游戲。通過不同的按鍵控制,選擇多種出拳方式,顯示猜 拳的結(jié)果,實(shí)現(xiàn)猜拳游戲,防止了作弊的可能。 基本要求: 1、甲
2、乙雙方各用 44 鍵盤中的三個(gè)按鍵模擬“石頭”、“剪刀”、“布”,一個(gè)按鍵為“確 認(rèn)”。44 鍵盤第一行為甲,第二行為乙; 2、裁判用 44 鍵盤第三行的一個(gè)按鍵模擬“開”,一個(gè)按鍵為“準(zhǔn)備”,一個(gè)按鍵為“復(fù) 位”; 3、裁判宣布“準(zhǔn)備”后,甲乙雙方分別選擇出拳方式并確認(rèn); 4、裁判“開”以后,用點(diǎn)陣的左右三列同時(shí)顯示甲乙雙方的猜拳選擇(如下圖所示), 并用兩個(gè)數(shù)碼管顯示甲乙的猜拳比分; 甲“布”,乙“剪刀” 甲“剪刀”,乙“石頭” 5、猜拳游戲?yàn)槲寰秩齽僦?。若甲乙雙方出拳一致,則比分保持不變,雙方重新出拳;6、比賽結(jié)束后,用 88 點(diǎn)陣顯示甲乙獲勝方; 7、復(fù)位后游戲重新開始。 提高要求:
3、1、 點(diǎn)陣顯示增加游戲開機(jī)動(dòng)畫、結(jié)束動(dòng)畫; 2、 為游戲增加音效;3、 在 LCD1602 液晶屏上顯示甲乙雙方的猜拳比分; 4、 自擬其他功能。二 系統(tǒng)設(shè)計(jì):(1)設(shè)計(jì)思路:根據(jù)實(shí)驗(yàn)的要求,首先控制器是鍵盤,構(gòu)思鍵盤的控制方式:1、假設(shè)4X4鍵盤第一個(gè)到最后一個(gè)按鍵編號為1-16,本實(shí)驗(yàn)用到了1-11,共十一個(gè)按鍵,對這十一個(gè)按鍵進(jìn)行鍵值編碼:第一行1234 0001 0101 1001 1101第二行5678 1000 1001 1010 1011第三行91011 1111 0110 1100123代表甲方出“石頭”“剪刀”“布”,4代表“已選好(確認(rèn))”;567代表乙方出“石頭”“剪刀”
4、“布”,8代表“已選好(確認(rèn))”;9代表“準(zhǔn)備”,10代表“開結(jié)果”,11代表“復(fù)位”注:此處復(fù)位的是按鍵的操作,對后面的分?jǐn)?shù)不會有影響。2、鍵盤編好了每個(gè)鍵的碼,進(jìn)行按鍵操作以后,傳入點(diǎn)陣模塊點(diǎn)陣是8X8的,列輸出用紅色,列是共陽極,需要掃描顯示,按照給出的圖案要求,進(jìn)行圖案的掃描顯示,比較簡單,之后詳見代碼。3、根據(jù)賽制,五局三勝,也就是誰先達(dá)到三分誰就是贏家,故計(jì)分模塊只需要分別最大分?jǐn)?shù)技術(shù)為3就符合了計(jì)分目的,計(jì)分獨(dú)立模塊,根據(jù)按鍵模塊輸出的鍵值,進(jìn)行譯碼,根據(jù)“開結(jié)果”以后之前的甲乙出拳組合得出不同分?jǐn)?shù)計(jì)數(shù),通過數(shù)碼管的左側(cè)兩位顯示出來,當(dāng)一方達(dá)到三分后,將甲或者乙的計(jì)分3輸出,輸入
5、到點(diǎn)陣模塊,此時(shí)顯示一方勝利圖案。至此設(shè)計(jì)思路完整清晰。(2)系統(tǒng)總體框圖: 三 分塊設(shè)計(jì)程序及仿真分析1. 按鍵模塊由于我們的4X4按鍵模塊的端口是:四行的每行四個(gè)鍵分別公用一個(gè)行輸入,四列的四個(gè)鍵分別公用一個(gè)列輸出,這就需要我們掃描按鍵來控制輸出。四位計(jì)數(shù)對列進(jìn)行掃描,每次掃描單列時(shí),再對行進(jìn)行掃描,這樣就可以對使用到的所有鍵分別有各自的輸入輸出控制。具體實(shí)現(xiàn)如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity caiqu
6、an isport( kb_row_in:in std_logic_vector(3 downto 0); kb_col_out:out std_logic_vector(3 downto 0); showa,showb,showc,showd:out std_logic_vector(3 downto 0); clk:in std_logic ); END caiquan;architecture cai of caiquan issignal counta,countb:std_logic_vector(1 downto 0);signal col_out:std_logic_vector
7、(3 downto 0);signal a,b,c,d:std_logic_vector(3 downto 0):=0000;-* begin process(counta,clk)- begin if(clkevent and clk=1)then if(counta=11)thencounta=00;else countakb_col_out=0111;countbkb_col_out=1011;countbkb_col_out=1101;countbkb_col_out=1110;countbcase kb_row_in iswhen0111=a=0001;b=0000;c=0000;d
8、b=1000;a=0000;c=0000;dc=1111;b=0000;a=0000;da=0000;b=0000;c=0000;dcase kb_row_in iswhen0111=a=0101;b=0000;c=0000;db=1001;a=0000;c=0000;dc=0110;b=0000;a=0000;da=0000;b=0000;c=0000;dcase kb_row_in iswhen0111=a=1001;b=0000;c=0000;db=1010;a=0000;c=0000;dc=1100;b=0000;a=0000;da=0000;b=0000;c=0000;dcase k
9、b_row_in iswhen0111=d=1101;a=0000;c=0000;bd=1011;b=0000;c=0000;aa=0000;b=0000;c=0000;d=0000; end case; end case; showa=a; showb=b; showc=c; showd=d;end process;end;仿真波形如下: 說明:由仿真可以清晰地看到abcd四組鍵的鍵值輸出a0001 0101 1001 d 1101b 1000 1001 1010 1011c1111 0110 11002點(diǎn)陣模塊 點(diǎn)陣模塊和按鍵模塊一樣需要掃描顯示,由于我們的圖形只涉及到中間四行和兩邊各三列
10、,我們的行掃描只需掃描中間四行其他四行置0可以節(jié)省引腳使用,掃描行,每行對應(yīng)列的輸出,頻率高了人眼看到的就是靜止的圖形。點(diǎn)陣模塊顯示圖形需要對按鍵模塊傳輸過來的鍵碼對應(yīng)譯碼,對應(yīng)不同按鍵情況進(jìn)行不同的圖形顯示。此程序使用鍵值“與”來表達(dá)“已選好(確認(rèn))”,在“與”之前加入“準(zhǔn)備”的限定條件,之后判斷“與”的結(jié)果之前加上“開結(jié)果”的限定,就可以實(shí)現(xiàn)“準(zhǔn)備”出拳“已選好(確認(rèn))”“開結(jié)果”的順序限制,而復(fù)位只需要在每個(gè)進(jìn)程剛開始時(shí)加入復(fù)位信號的初值,就可以實(shí)現(xiàn)復(fù)位來滅掉點(diǎn)陣顯示。具體實(shí)現(xiàn)如下:library ieee;use ieee.std_logic_1164.all;use ieee.std
11、_logic_unsigned.all;use ieee.std_logic_arith.all;entity dianzhen isport(clear:in std_logic;win_a,win_b:in std_logic_vector(2 downto 0);clk:in std_logic;col_a,col_b:out std_logic_vector(3 downto 0);a,b,c,d:in std_logic_vector(3 downto 0);row:out std_logic_vector(7 downto 0);end dianzhen;architecture
12、dian of dianzhen issignal data11,data12,data13,data14,data21,data22,data23,data24:std_logic_vector(3 downto 0);signal a_data,b_data,c1_data,c2_data,c3_data,ad_data,be_data:std_logic_vector(3 downto 0):=0000;signal d_data,e_data:std_logic_vector(3 downto 0):=0000;signal cnt:STD_LOGIC_VECTOR (1 DOWNTO
13、 0);signal wina_data,winb_data:std_logic_vector(2 downto 0):=000;beginprocess(win_a)-note for winabeginif(clkevent and clk=1)thenif(clear=1)thenwina_datawina_datawina_datawina_datawina_datanull;end case;end if;end if;end process;process(win_b)-note for winbbeginif(clkevent and clk=1)thenif(clear=1)t
14、henwinb_datawinb_datawinb_datawinb_datawinb_datanull;end case;end if;end if;end process;process(a)-note for jiabeginif(clkevent and clk=1)thenif(c=1100 or clear=1)thena_dataa_dataa_dataa_datanull;end case;end if;end if;end process;process(b)-note for yibeginif(clkevent and clk=1)thenif(c=1100 or cle
15、ar=1)thenb_datab_datab_datab_datanull;end case;end if;end if;end process;process(c)-note for ready,open and resetbeginif(clkevent and clk=1)thenif(c=1100 or clear=1)thenc1_data=0000;c2_datac1_datac2_datanull;end case;end if;end if;end process;process(clk,c1_data,c2_data,c)-note for ok of jia and yib
16、eginif(clkevent and clk=1)thenif(c=1100 or clear=1)thend_data=0000;e_datad_datae_datanull;end case;end if;if(c=1100 or clear=1)thenad_data=0000;be_data=0000;-a_data=0000;b_data=0000;elsead_data=(a_data and d_data);be_datadata11=0100;data12=1110;data13=1110;data14data11=0010;data12=1100;data13=1100;d
17、ata14data11=1110;data12=1110;data13=1110;data14data11=0000;data12=0000;data13=0000;data14data21=0010;data22=0111;data23=0111;data24data21=0100;data22=0011;data23=0011;data24data21=0111;data22=0111;data23=0111;data24data21=0000;data22=0000;data23=0000;data24=0000; end case;else data11=0000;data12=000
18、0;data13=0000;data14=0000;data21=0000;data22=0000;data23=0000;data24=0000;end if;end if;end process;process(clk)beginif(clkevent and clk=1)thenif(cnt=11)thencnt=00;else cntrow=11111011;col_a=0100;col_brow=11110111;col_a=0100;col_brow=11101111;col_a=0100;col_brow=11011111;col_a=1010;col_brow=11111011
19、;col_b=0010;col_arow=11110111;col_b=0010;col_arow=11101111;col_b=0010;col_arow=11011111;col_b=0101;col_arow=11111011;col_a=data11;col_brow=11110111;col_a=data12;col_brow=11101111;col_a=data13;col_brow=11011111;col_a=data14;col_b=data24;end case;end if;end process;end;仿真波形如下:說明:如波形所示,實(shí)現(xiàn)了順序限定顯示點(diǎn)陣,最下面的
20、三個(gè)win_a,win_b,clear是對應(yīng)計(jì)分模塊甲乙二人計(jì)分結(jié)果的傳入判斷,和對分?jǐn)?shù)的復(fù)位,此復(fù)位也是全局復(fù)位。3.計(jì)分模塊 計(jì)分模塊相對簡單,也由按鍵鍵值判斷來實(shí)現(xiàn)分?jǐn)?shù)的計(jì)數(shù),情況有九種,三種出拳的平局,甲的三種贏的情況和乙的三種贏的情況。對應(yīng)贏的時(shí)候,甲乙的各自分?jǐn)?shù)計(jì)數(shù)的信號加一就可以實(shí)現(xiàn)分?jǐn)?shù)加,顯示到數(shù)碼管需要一個(gè)cat的互相對換,來顯示兩位分?jǐn)?shù)分?jǐn)?shù)滿足三分時(shí)候分?jǐn)?shù)不再增加,并且輸出一個(gè)3給點(diǎn)陣,來顯示勝利結(jié)果,并設(shè)有一個(gè)全局的復(fù)位,來實(shí)現(xiàn)游戲結(jié)束的復(fù)位,或者任意時(shí)刻的“重新開始玩”。具體實(shí)現(xiàn)如下:library ieee;use ieee.std_logic_1164.all;us
21、e ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity jifen isport(clk,clear:in std_logic;a,b,c,d:in std_logic_vector(3 downto 0);smg:out std_logic_vector(6 downto 0);cat:out std_logic_vector(7 downto 0);cnta,cntb:out std_logic_vector(2 downto 0);end jifen;architecture ji of jifen issign
22、al a_data,b_data,c1_data,c3_data,ad_data,be_data:std_logic_vector(3 downto 0):=0000;signal d_data,e_data:std_logic_vector(3 downto 0):=0000;signal cnt_a,cnt_b:STD_LOGIC_VECTOR (2 DOWNTO 0):=000;signal sig_a,sig_b,c2_data:std_logic;signal cat_t:std_logic_vector(7 downto 0):=11111101;beginprocess(a)-n
23、ote for jiabeginif(clkevent and clk=1)thenif(c=1100 or clear=1)thena_dataa_dataa_dataa_datanull;end case;end if;end if;end process;process(b)-note for yibeginif(clkevent and clk=1)thenif(c=1100 or clear=1)thenb_datab_datab_datab_datanull;end case;end if;end if;end process;process(c)-note for ready,o
24、pen and resetbeginif(clkevent and clk=1)thenif(c=1100 or clear=1)thenc1_data=0000;c2_datac1_datac2_datanull;end case;end if;end if;end process;process(c1_data,c2_data,c)-note for ok of jia and yibeginif(c2_dataevent and c2_data=1)thenif(c=1100 or clear=1)thend_data=0000;e_datad_datae_datanull;end ca
25、se;end if;end if;end process;process(clk)beginif(clear=1)thencnt_a=000;elseif(cnt_a=100)thencnt_a=000;elsif(c2_dataevent and c2_data=1)thenif(a_data=0001 and b_data=1001)thencnt_a=cnt_a+1;elsif(a_data=0101 and b_data=1010)thencnt_a=cnt_a+1;elsif(a_data=1001 and b_data=1000)thencnt_a=cnt_a+1;end if;e
26、nd if;end if;end process;process(clk)beginif(clear=1)thencnt_b=000;elseif(cnt_b=100)thencnt_b=000;elsif(c2_dataevent and c2_data=1)thenif(a_data=0001 and b_data=1010)thencnt_b=cnt_b+1;elsif(a_data=0101 and b_data=1000)thencnt_b=cnt_b+1;elsif(a_data=1001 and b_data=1001)thencnt_bcat_t=11111110;cat=ca
27、t_t;if(clear=1)thensmg=0000000;cntasmg=0000000;cntasmg=0110000;cntasmg=1101101;cntasmg=1111001;cntanull; end case; end if;when11111110=cat_t=11111101;cat=cat_t; if(clear=1)thensmg=0000000;cntbsmg=0000000;cntbsmg=0110000;cntbsmg=1101101;cntbsmg=1111001;cntbnull; end case; end if;when others=cat_t clk, kb_row_in = kb_row_in, kb_col_out = kb_col_out, showa = SYNTHESIZED_WI
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度地下空間開發(fā)施工合同規(guī)范文本
- 2025年度印刷材料行業(yè)環(huán)保型采購與生產(chǎn)合同
- 低碳環(huán)保的活動(dòng)方案范文(13篇)
- 2025年債務(wù)解決方案資產(chǎn)協(xié)議書
- 2025年企業(yè)電氣設(shè)施維護(hù)合同
- 2025年家用空氣調(diào)節(jié)器項(xiàng)目提案報(bào)告模稿
- 2025年電子脂肪秤項(xiàng)目立項(xiàng)申請報(bào)告模范
- 2025年芝士片項(xiàng)目立項(xiàng)申請報(bào)告模范
- 2025年空心槳葉干燥機(jī)項(xiàng)目立項(xiàng)申請報(bào)告模板
- 2025年臨時(shí)性雜工勞動(dòng)合同
- 稿件修改說明(模板)
- 醫(yī)學(xué)約束帶的使用課件
- 傳染病防控工作職能部門間協(xié)調(diào)機(jī)制及流程
- 社會團(tuán)體法定代表人登記表
- 中小學(xué)心理健康教育教師技能培訓(xùn)專題方案
- (完整版)50028-城鎮(zhèn)燃?xì)庠O(shè)計(jì)規(guī)范
- 2020年常見腫瘤AJCC分期手冊第八版(中文版)
- 五年級下冊生命、生態(tài)、安全教案
- 原發(fā)性肺癌手術(shù)臨床路徑(最全版)
- 建筑工程施工質(zhì)量驗(yàn)收規(guī)范檢驗(yàn)批填寫全套表格+示范填寫及說明
- 刺五加種植加工項(xiàng)目可行性研究報(bào)告寫作范文
評論
0/150
提交評論