數(shù)字邏輯實驗報告_第1頁
數(shù)字邏輯實驗報告_第2頁
數(shù)字邏輯實驗報告_第3頁
數(shù)字邏輯實驗報告_第4頁
數(shù)字邏輯實驗報告_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、北京郵電大學數(shù)字電路與邏輯設計實驗報告實驗題目:擲骰子游戲電路的設計與實現(xiàn)學生姓名: 班級:學號: 序號:目錄一、 設計課題的任務要求二、 系統(tǒng)設計三、 仿真波形及波形分析四、 源程序五、 功能說明及資源利用情況六、 故障及問題分析七、 總結和結論一、 設計課題的任務要求設計并實現(xiàn)一個擲骰子游戲電路。 基本要求: 1、 電路可供甲乙二人游戲,游戲者甲使用的按鍵為 BTN0,游戲者乙使用的按鍵為 BTN1。2、 每按一次按鍵,代表擲一次骰子,可隨機得到 16 范圍內(nèi)的兩個數(shù)字。 3、 甲乙按鍵產(chǎn)生的隨機數(shù)字分別用數(shù)碼管 DISP0-DISP1、DISP2-DISP3 顯示,并用 DISP7 顯示

2、比賽局數(shù),比賽結束用 8×8 點陣顯示獲勝方,并伴有聲音效果。4、 具體游戲規(guī)則如下: (1) 第一局比賽,甲乙依次各按一次按鍵,按鍵所得兩數(shù)之和為7或11者勝;若無 人取勝,則進行第二局比賽; (2) 第二局比賽,甲乙每人各按一次按鍵,按鍵所得二數(shù)之和與第一局比賽相同者獲 勝,若無人獲勝,則進行第三局比賽,重復進行步驟(2),直到出現(xiàn)勝者為止。 (3) 游戲局數(shù)最多進行六局。在第六局比賽時,若重復進行步驟(2)仍未出現(xiàn)勝者, 以按鍵所得兩數(shù)之和最大者為獲勝方。 提高要求: 1、 增加多人游戲的功能,數(shù)碼管可分時記錄顯示每個游戲者的骰子點數(shù)。 2、 點陣顯示增加游戲開機動畫、結束動畫

3、,并伴有樂曲播放。 3、 自擬其它功能。二、系統(tǒng)設計1、設計思路:按照實驗要求,使用狀態(tài)機分別表示游戲的不同狀態(tài);使用分頻器來控制時鐘;控制器實現(xiàn)具體的游戲規(guī)則;8*8LED點陣來顯示勝負;數(shù)碼管顯示局數(shù)和甲乙擲出的隨機數(shù);隨機數(shù)用一到六的循環(huán)產(chǎn)生。在編譯時采用元件例化來生成各自的模塊。流程圖如下 顯示2、總體框圖:控制器分頻器防抖器輸入3、分塊設計:分別包括分頻器、防抖器、隨機數(shù)的產(chǎn)生、判斷器、譯碼器和顯示器等模塊,綜合起來實現(xiàn)所要求的功能。分頻器:防抖器:隨機數(shù)的產(chǎn)生: 判斷器: 譯碼器: 顯示器:三、 仿真波形及波形分析根據(jù)甲先乙后的順序進行仿真如下:從仿真中可以看出隨機數(shù)的產(chǎn)生,若時間

4、軸向后移可以將游戲看得更加清楚。四、 源程序分頻器:library ieee;use ieee.std_logic_1164.all;entity fenpingqi is port (clk:in std_logic;clktmp:out std_logic); end fenpingqi;architecture a of fenpingqi is signal tmp: integer range 0 to 499:=0;signal clktmp1: std_logic;beginp3:process(clk) -frequent timebeginif clk'event a

5、nd clk='1'thenif tmp=499 then tmp<=0;clktmp1<= not clktmp1;elsetmp<=tmp+1;end if;end if;end process p3;clktmp<=clktmp1;end a ;防抖器:library ieee;use ieee.std_logic_1164.all;entity fangdouqi is port (clk,btn1, btn2 :in std_logic; btn1_en,btn2_en :out std_logic); end fangdouqi;archit

6、ecture a of fangdouqi is signal tempcount1:integer range 0 to 5 :=0;signal tempcount2:integer range 0 to 5 :=0;begin p5:process(clk,btn1,btn2) beginif clk'event and clk='1' thenif btn1='1' thenif tempcount1=5 then tempcount1<=tempcount1;else tempcount1<=tempcount1+1; end if

7、;if tempcount1=4 then btn1_en<='1'else btn1_en<='0'end if;else tempcount1 <=0; end if;if btn2='1' thenif tempcount2=5 then tempcount2<=tempcount2;else tempcount2<=tempcount2+1; end if;if tempcount2=4 then btn2_en<='1'else btn2_en<='0'end i

8、f;else tempcount2 <=0; end if;end if;end process p5;end a;計數(shù)器library ieee;use ieee.std_logic_1164.all;entity jishuqi is port (clktmp:in std_logic; randnum2:out integer range 1 to 12; randnum :out integer range 1 to 12); end jishuqi;architecture a of jishuqi issignal randnum1: integer range 1 to 1

9、2;signal randnum3: integer range 1 to 12;beginp4:process(clktmp) -counter1 beginif clktmp'event and clktmp='1' thenif randnum1= 6 thenrandnum1<=1;elserandnum1<=randnum1+1;end if;if randnum3= 7 thenrandnum3<=1;elserandnum3<=randnum3+1;end if;end if;if randnum3=7 thenrandnum2&l

10、t;=1;elserandnum2<=randnum3;end if;randnum<=randnum1;end process p4;end a;擲骰子結果的產(chǎn)生:library ieee;use ieee.std_logic_1164.all;entity creaters is port (clk:in std_logic;clktmp:in std_logic;btn1_en,btn2_en :in std_logic;randnum,randnum1:in integer range 1 to 12;count:in integer range 0 to 5;sgn11,

11、sgn22 :out std_logic;a1,a2,b1,b2:out integer range 1 to 12;a3,a4,b3,b4:out integer range 1 to 12); end creaters;architecture a of creaters is signal a11,a22,b11,b22: integer range 1 to 12:=1;signal a33,a44,b33,b44: integer range 1 to 12;signal sgn1,sgn2:std_logic:='0'beginp1:process (a11,a22

12、,a33,sgn1,sgn2,b11,b22,b33,btn1_en,btn2_en,clktmp)begin if clktmp'event and clktmp='1'thenif sgn1='1'and sgn2='1'thensgn1<='0'sgn2<='0' end if;if btn1_en='1' and sgn1='0' thensgn1<='1'a11<=randnum;-get rand num;a22<=r

13、andnum1;a33<=randnum1+randnum;if count=0 thena44<=randnum1+randnum;end if;end if;if btn2_en='1' and sgn1='1'and sgn2='0' thensgn2<='1'b11<=randnum;b22<=randnum1;b33<=randnum1+randnum;if count=0 thenb44<=randnum1+randnum;end if;end if; end if;a1<

14、;=a11;a2<=a22;a3<=a33;b1<=b11;b2<=b22;b3<=b33;a4<=a44;b4<=b44;sgn11<=sgn1;sgn22<=sgn2;end process p1; end a ;判斷器:library ieee;use ieee.std_logic_1164.all;entity panduanqi is port (sgn1,sgn2 :in std_logic; clk:in std_logic; a3,a4,b3,b4: in integer range 1 to 12; disp77: out

15、 integer range 1 to 6; count1:out integer range 0 to 5; winsgn :out std_logic_vector(1 downto 0); end panduanqi; architecture a of panduanqi is signal count : integer range 0 to 5:=0;signal disp7 : integer range 0 to 5:=1; begin p7:process(clk,a3,a4,b3,b4,sgn1,sgn2) -judgmentbeginif clk'event an

16、d clk='1' thenif sgn1='1'and sgn2='1'then 規(guī)定甲先擲乙后擲if count=0 then if (a3=11 or a3=7) then winsgn<="10" disp7<=disp7+1 ;count<=0;elsif (b3=11 or b3=7) then winsgn<="01" disp7<=disp7+1 ;count<=0;else count<=count+1;end if; elsif count=5

17、then if (a3=11 or a3=7 ) then winsgn<="10" elsif (b3=11 or b3=7) then winsgn<="01"elsif a3>b3 then winsgn<="10"else winsgn<="01"end if; disp7<=disp7+1 ;count<=0;else if a3=a4 then winsgn<="10"disp7<=disp7+1 ;count<=0;els

18、if b3=b4 then winsgn<="01"disp7<=disp7+1 ;count<=0;else count<=count+1;end if;end if;end if;end if;count1<=count;if (disp7=7)thendisp77<=1;elsedisp77<=disp7;end if;end process p7;end a;譯碼器:library ieee;use ieee.std_logic_1164.all;entity yimaqi is port (clktmp:in std_lo

19、gic; a1,a2,b1,b2:in integer range 1 to 12; disp7: in integer range 1 to 6; num : out std_logic_vector(6 downto 0); cat : out std_logic_vector(5 downto 0); end yimaqi; architecture a of yimaqi is signal tempcat: std_logic_vector(5 downto 0); signal tempnum: integer range 0 to 6:=1; signal num1: std_l

20、ogic_vector(6 downto 0);signal cycle :integer range 0 to 4:=0; begin p6:process(clktmp) -translate the num1 to right num;beginif clktmp'event and clktmp='1' thenif(cycle=4)thencycle<=0;elsecycle<= cycle+1;end if;end if;case cycle iswhen 0 => tempnum<=a1; tempcat<="111

21、110"when 1 => tempnum<=a2;tempcat<="111101"when 2 => tempnum<=b1;tempcat<="111011"when 3 => tempnum<=b2;tempcat<="110111"when 4 => tempnum<=disp7;tempcat<="011111"end case;case tempnum iswhen 0=>num1<="111111

22、0"when 1=>num1<="0110000"when 2=>num1<="1101101"when 3=>num1<="1111001"when 4=>num1<="0110011"when 5=>num1<="1011011"when 6=>num1<="1011111"end case;num<=num1;cat<=tempcat;end process p6; end a

23、;顯示器:library ieee;use ieee.std_logic_1164.all;entity xianshiqi is port (clk:in std_logic;winsgn: in std_logic_vector(1 downto 0);row: out std_logic_vector(7 downto 0);col: out std_logic_vector(7 downto 0); end xianshiqi;architecture a of xianshiqi is signal cyc :integer range 0 to 7:=0;signal row1 :

24、std_logic_vector(7 downto 0);signal col1 :std_logic_vector(7 downto 0);begin p8:process(clk)begin if clk'event and clk='1' thenif cyc=7 thencyc<=0;elsecyc<=cyc+1; end if;if winsgn="10"thencase cyc is when 0=>row1<="01111111"col1<="01111100"whe

25、n 1=>row1<="10111111"col1<="01010100"when 2=>row1<="11011111"col1<="01111100"when 3=>row1<="11101111"col1<="01010100"when 4=>row1<="11110111"col1<="01111100"when 5=>row1<="1

26、1111011"col1<="00010000"when 6=>row1<="11111101"col1<="00010000"when 7=>row1<="11111110"col1<="00010000"end case;elsif winsgn= "01"thencase cyc is when 0=>row1<="01111111"col1<="11111111&quo

27、t;when 1=>row1<="10111111"col1<="01000000"when 2=>row1<="11011111"col1<="00100000"when 3=>row1<="11101111"col1<="00010000"when 4=>row1<="11110111"col1<="00001000"when 5=>row1<="11111011"col1<="00000100"when 6=>row1<="11111101"col1<="10000010"when 7=>row1&l

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論