北京郵電大學(xué) 數(shù)電實(shí)驗(yàn)下 報(bào)告_第1頁
北京郵電大學(xué) 數(shù)電實(shí)驗(yàn)下 報(bào)告_第2頁
北京郵電大學(xué) 數(shù)電實(shí)驗(yàn)下 報(bào)告_第3頁
北京郵電大學(xué) 數(shù)電實(shí)驗(yàn)下 報(bào)告_第4頁
北京郵電大學(xué) 數(shù)電實(shí)驗(yàn)下 報(bào)告_第5頁
已閱讀5頁,還剩25頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

20/30數(shù)字電路實(shí)驗(yàn)報(bào)告擲骰子游戲電路班級(jí):XXX學(xué)號(hào):XXX姓名:XXX2014年11月8號(hào)目錄一、 任務(wù)要求 1二、 系統(tǒng)設(shè)計(jì) 11. 設(shè)計(jì)思路 12. 系統(tǒng)框圖 23. 分塊設(shè)計(jì) 5三、 仿真波形及分析 6四、 功能說明及資源利用情況 7五、 故障及問題分析 7六、 總結(jié)和結(jié)論 8七、 源程序 9任務(wù)要求設(shè)計(jì)并實(shí)現(xiàn)一個(gè)擲骰子游戲電路?;疽螅弘娐房晒┘滓叶擞螒颍螒蛘呒资褂玫陌存I為BTN0,游戲者乙使用的按鍵為BTN1。每按一次按鍵,代表擲一次骰子,可隨機(jī)得到1~6范圍內(nèi)的兩個(gè)數(shù)字。甲乙按鍵產(chǎn)生的隨機(jī)數(shù)字分別用數(shù)碼管DISP0-DISP1、DISP2-DISP3顯示,并用DISP7顯示比賽局?jǐn)?shù),比賽結(jié)束用8×8點(diǎn)陣顯示獲勝方,并伴有聲音效果。具體游戲規(guī)則如下:第一局比賽,甲乙依次各按一次按鍵,按鍵所得兩數(shù)之和為7或11者勝;若無人取勝,則進(jìn)行第二局比賽;第二局比賽,甲乙每人各按一次按鍵,按鍵所得二數(shù)之和與第一局比賽相同者獲勝,若無人獲勝,則進(jìn)行第三局比賽,重復(fù)進(jìn)行步驟(2),直到出現(xiàn)勝者為止。游戲局?jǐn)?shù)最多進(jìn)行六局。在第六局比賽時(shí),若重復(fù)進(jìn)行步驟(2)仍未出現(xiàn)勝者,以按鍵所得兩數(shù)之和最大者為獲勝方。提高要求:增加多人游戲的功能,數(shù)碼管可分時(shí)記錄顯示每個(gè)游戲者的骰子點(diǎn)數(shù)。點(diǎn)陣顯示增加游戲開機(jī)動(dòng)畫、結(jié)束動(dòng)畫,并伴有樂曲播放。自擬其它功能。系統(tǒng)設(shè)計(jì)設(shè)計(jì)思路首先,鑒于FPGA程序語言的特點(diǎn)與EPM系列芯片的功能,采用模塊化設(shè)計(jì),各模塊通過VHDL或基本器件實(shí)現(xiàn),然后通過電路原理圖連接各模塊。設(shè)計(jì)方面,主要分為分頻器、點(diǎn)陣顯示模塊、數(shù)碼管顯示模塊、隨機(jī)數(shù)生成模塊、按鍵防抖模塊、音頻模塊、邏輯模塊。由于數(shù)據(jù)量小,各模塊內(nèi)部通過編程語言實(shí)現(xiàn)寄存功能,而不單獨(dú)設(shè)立儲(chǔ)存器。系統(tǒng)框圖系統(tǒng)模塊圖:模塊方案:MDS狀態(tài)圖:ASM流程圖:分塊設(shè)計(jì)如圖,clk_1hz為分頻模塊,people為多人游戲控制器,point為點(diǎn)陣顯示模塊,tube_t為數(shù)碼管顯示模塊,comp包含了邏輯與隨機(jī)數(shù)生成模塊,anjian包含多人游戲按鍵控制及防抖。仿真波形及分析由于多人多模式、開機(jī)動(dòng)畫、自動(dòng)復(fù)位等附加功能涉及信號(hào)過多,且均建立在基礎(chǔ)程序之上,未進(jìn)行仿真,此仿真版本只實(shí)現(xiàn)了基本功能,包括:按鍵觸發(fā)隨機(jī)數(shù),兩人游戲邏輯及顯示模塊,蜂鳴器產(chǎn)生提示音,時(shí)鐘clk為0.04us(25mhz)。觀測BUTTONTEST與fangdouTESTout,可見防抖模塊運(yùn)行正常,輸出為高電平觸發(fā)信號(hào)。EndTESTa1、endTESTa2、endTESTjushu分別為隨按鍵隨機(jī)生成的兩個(gè)數(shù)和增加的局?jǐn)?shù),可見a1呈2等差,印證了錯(cuò)誤1(見錯(cuò)誤分析),a2正常工作。再對(duì)應(yīng)觀察numberTEST與segTEST,可見numberTEST正常工作,顯示隨機(jī)數(shù)對(duì)應(yīng)的編碼,但數(shù)碼管選位信號(hào)segTEST未改變,未查明原因(電路正常工作)。JuzhengTESTa、JuzhengTESTb、JuzhengTESTc為別為甲乙平三種狀態(tài)對(duì)應(yīng)的point模式選擇函數(shù),觀察JuzhengTESTcol、JuzhengTESTrow,可見point模塊正常工作。另外,SPEAKER輸出信號(hào)正常工作。luojiTESTa1、luojiTESTa2、luojiTESTg1分別對(duì)應(yīng)邏輯判斷模塊甲乙的和及局?jǐn)?shù),luojiTESTa、luojiTESTb、luojiTESTc分別對(duì)應(yīng)甲乙平三種狀態(tài)選位輸出??梢?,若將圖中黑塊視為低電平,則邏輯甲乙判斷正確,但平始終為高電平輸出,且在出判斷結(jié)果后。分析得出,黑塊是由于在出結(jié)果后繼續(xù)進(jìn)行游戲?qū)е碌臎_突,不影響游戲(此程序還未加入reset功能),平結(jié)果同樣是其導(dǎo)致的標(biāo)志位沖突(進(jìn)入other條件)。功能說明及資源利用情況基本功能實(shí)現(xiàn):能通過兩個(gè)BTN按鍵實(shí)現(xiàn)兩人游戲(可循環(huán)),隨機(jī)生成1~6的骰子數(shù)并計(jì)算和,數(shù)碼管能顯示骰子結(jié)果與局?jǐn)?shù),點(diǎn)陣能正確顯示勝利者(甲或乙),并有蜂鳴音提示,符合要求的游戲規(guī)則(第一局和為7或11者勝,2~5局與本人第一句和相同者勝,第6局和較大者勝)。擴(kuò)展功能實(shí)現(xiàn):能通過額外按鍵增加游戲人數(shù)(最大為6人)并實(shí)現(xiàn)所有的游戲功能,增加復(fù)位功能,開機(jī)動(dòng)畫及音效,以及可實(shí)現(xiàn)兩音節(jié)的簡單鈴音。解決游戲規(guī)則bug:若第6局平手則提示平局,并能實(shí)現(xiàn)自動(dòng)復(fù)位??蓪?shí)現(xiàn)不同順序進(jìn)行游戲。資源利用情況:外圍設(shè)備使用點(diǎn)陣、數(shù)碼管、4個(gè)BTN按鍵、蜂鳴器及燒錄模塊。由編譯結(jié)果,芯片使用521個(gè)邏輯元件(41%),36個(gè)外部管腳(31%)。規(guī)模在可執(zhí)行范圍內(nèi)。故障及問題分析游戲規(guī)則bug:若第6局參賽者出現(xiàn)和相等(平手),規(guī)則未作出說明如何處理,自擬增加如下規(guī)則,若第六句平手,則提示平局,并自動(dòng)復(fù)位。隨機(jī)數(shù)生成bug:第一次設(shè)計(jì)時(shí),采用兩個(gè)隨機(jī)數(shù)生成器同時(shí)生成某位選手的兩個(gè)數(shù),但由于同時(shí)性,為避免數(shù)字相同,分別采用+1和+2不斷循環(huán)內(nèi)部變量,但由于+2組不能生成奇數(shù)隨機(jī)數(shù),并且同時(shí)生成隨機(jī)數(shù)帶來一系列邏輯上的問題(難以比較取值)。后改為由同一生成器分時(shí)取隨機(jī)數(shù),解決問題。游戲順序改進(jìn):起初,由于設(shè)計(jì)上的缺陷,只能以規(guī)定順序進(jìn)行游戲,后經(jīng)提醒,改進(jìn)設(shè)計(jì)模式,增加按鍵分配模塊,解決游戲順序的缺陷,實(shí)現(xiàn)不同順序游戲功能。時(shí)鐘選擇錯(cuò)誤:起初,由于在邏輯模塊方面使用為分頻的時(shí)鐘信號(hào),頻率過高,導(dǎo)致結(jié)果出錯(cuò)率較高(不能跑完代碼),后引入1khz分頻,解決邏輯錯(cuò)誤??偨Y(jié)和結(jié)論關(guān)于分頻:分頻是FPGA設(shè)計(jì)非常重要的一環(huán)。各個(gè)模塊由于功能不同需要不同的觸發(fā)條件,設(shè)計(jì)過程值得深究。起初也由于這方面的失誤久久無法解決邏輯上的問題(仿真無誤,運(yùn)行時(shí)出錯(cuò))。設(shè)計(jì)模式:雖然此前接觸C語言較久,但進(jìn)行vhdl需要完全不同的思路,vhdl是一門硬件描述語言,采用的是自頂向下的設(shè)計(jì)思想,即先描述一個(gè)電路的總體功能,然后給予具體地實(shí)現(xiàn)。就像搭建電路一樣,先給出總體框圖然后分塊實(shí)現(xiàn)。一個(gè)電路當(dāng)然就有級(jí)聯(lián)的和并聯(lián)電路就是所謂的用“并行語句和順序語句”來描述。而c語言目前還沒有一個(gè)編譯器能把它翻譯為硬件描述語言,盡管Verilog有點(diǎn)像c所謂象是他們的設(shè)計(jì)思路有點(diǎn)象,具體的語法規(guī)則還是有很大差異。c語言目前幾乎都是在cpu中運(yùn)行所以只能按指令的形式按順序執(zhí)行下來。因此,fpga設(shè)計(jì)時(shí)必須對(duì)系統(tǒng)做好提前的規(guī)劃分配,也得益于這次規(guī)劃比較好,實(shí)驗(yàn)進(jìn)行的也還算順利。總的來說,進(jìn)行了一次完全不同體驗(yàn)的設(shè)計(jì),獲益匪淺,也很有成就感。源程序1khz分頻器:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;useieee.std_logic_signed.all;entityclk_1khzis divfrequent1port(clk_in:instd_logic;clk:outstd_logic);endentityclk_1khz;architecturecofclk_1khzissignalcount0:integerrange0to49999;begin process(clk_in)is variableclk_i:std_logic; begin if(clk_in='1'andclk_in'event)then ifcount0=49999thencount0<=0; elsecount0<=count0+1; endif; ifcount0=0thenclk_i:=notclk_i; endif; endif; clk<=clk_i; endprocess;endc;按鍵防抖:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityfangdouisport( reset,clk:instd_logic; reseto:outstd_logic);end;architecturem1offangdouissignaltmp1,tmp2:std_logic;signalclkt:std_logic;beginprocess(clk)beginifclk'eventandclk='0'thentmp2<=tmp1;tmp1<=reset;endif;endprocess;reseto<=clkANDtmp1AND(NOTtmp2);end;邏輯與隨機(jī)數(shù):entitycompis port(re,clk_in,com:instd_logic; people:inintegerrange2to6; ran1,ran2,ran3,ran4:outintegerrange0to6; c:outintegerrange1to6; resu:outintegerrange0to6);endentitycomp;architecturecofcompis signalcount3:integerrange0to3; signalpeo:integerrange1to7; signalcount_t:integerrange1to6; signalnum:integerrange0to1; signalsum_1,sum_2,sum_3,sum_4,sum_5,sum_6:integerrange0to12; signalsum1,sum2,sum3,sum4,sum5,sum6:integerrange0to12; signalrandom:integerrange1to6; signalrandom_1:integerrange1to7; begin process(clk_in,people,com,count_t,num)is variableres:integerrange0to6; variablerandom_m0,random_n0:integerrange0to6; variablef1,f2,f3,f4,f5,f6:integerrange0to1; begin if(clk_in='1'andclk_in'event)then ifrandom=6thenrandom<=1; elserandom<=random+1; endif; ifrandom_1=7thenrandom_1<=1; elserandom_1<=random_1+1; endif; ifre='1'then count_t<=1; ran1<=0; ran2<=0; ran3<=0; ran4<=0; res:=0; peo<=1; else ifpeo>peoplethen casecount_tis when1=> if(sum_1=7orsum_1=11)thenf1:=1; elsef1:=0; endif; if(sum_2=7orsum_2=11)thenf2:=1; elsef2:=0; endif; if(sum_3=7orsum_3=11)thenf3:=1; elsef3:=0; endif; if(sum_4=7orsum_4=11)thenf4:=1; elsef4:=0; endif; if(sum_5=7orsum_5=11)thenf5:=1; elsef5:=0; endif; if(sum_6=7orsum_6=11)thenf6:=1; elsef6:=0; endif; if(f1=1andf2=0andf3=0andf4=0andf5=0andf6=0)then res:=1; count_t<=1; elsif(f1=0andf2=1andf3=0andf4=0andf5=0andf6=0)then res:=2; count_t<=1; elsif(f1=0andf2=0andf3=1andf4=0andf5=0andf6=0)then res:=3; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=1andf5=0andf6=0)then res:=4; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=0andf5=1andf6=0)then res:=5; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=0andf5=0andf6=1)then res:=6; count_t<=1; else count_t<=count_t+1; endif; when2to5=> if(sum1>0andsum1=sum_1)thenf1:=1; elsef1:=0; endif; if(sum2>0andsum2=sum_2)thenf2:=1; elsef2:=0; endif; if(sum3>0andsum3=sum_3)thenf3:=1; elsef3:=0; endif; if(sum4>0andsum4=sum_4)thenf4:=1; elsef4:=0; endif; if(sum5>0andsum5=sum_5)thenf5:=1; elsef5:=0; endif; if(sum6>0andsum6=sum_6)thenf6:=1; elsef6:=0; endif; if(f1=1andf2=0andf3=0andf4=0andf5=0andf6=0)then res:=1; count_t<=1; elsif(f1=0andf2=1andf3=0andf4=0andf5=0andf6=0)then res:=2; count_t<=1; elsif(f1=0andf2=0andf3=1andf4=0andf5=0andf6=0)then res:=3; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=1andf5=0andf6=0)then res:=4; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=0andf5=1andf6=0)then res:=5; count_t<=1; elsif(f1=0andf2=0andf3=0andf4=0andf5=0andf6=1)then res:=6; count_t<=1; else count_t<=count_t+1; endif; when6=> if(sum1>0andsum1=sum_1)thenf1:=1; elsef1:=0; endif; if(sum2>0andsum2=sum_2)thenf2:=1; elsef2:=0; endif; if(sum3>0andsum3=sum_3)thenf3:=1; elsef3:=0; endif; if(sum4>0andsum4=sum_4)thenf4:=1; elsef4:=0; endif; if(sum5>0andsum5=sum_5)thenf5:=1; elsef5:=0; endif; if(sum6>0andsum6=sum_6)thenf6:=1; elsef6:=0; endif; if(f1=1andf2=0andf3=0andf4=0andf5=0andf6=0)then res:=1; elsif(f1=0andf2=1andf3=0andf4=0andf5=0andf6=0)then res:=2; elsif(f1=0andf2=0andf3=1andf4=0andf5=0andf6=0)then res:=3; elsif(f1=0andf2=0andf3=0andf4=1andf5=0andf6=0)then res:=4; elsif(f1=0andf2=0andf3=0andf4=0andf5=1andf6=0)then res:=5; elsif(f1=0andf2=0andf3=0andf4=0andf5=0andf6=1)then res:=6; else if(sum1>sum2andsum1>sum3andsum1>sum4andsum1>sum5andsum1>sum6)then res:=1; elsif(sum2>sum1andsum2>sum3andsum2>sum4andsum2>sum5andsum2>sum6)then res:=2; elsif(sum3>sum1andsum3>sum2andsum3>sum4andsum3>sum5andsum3>sum6)then res:=3; elsif(sum4>sum1andsum4>sum2andsum4>sum3andsum4>sum5andsum4>sum6)then res:=4; elsif(sum5>sum1andsum5>sum2andsum5>sum3andsum5>sum4andsum5>sum6)then res:=5; elsif(sum6>sum1andsum6>sum2andsum6>sum3andsum6>sum4andsum6>sum5)then res:=6; elseres:=0; endif; endif; count_t<=1; whenothers=> count_t<=1; endcase; peo<=1; endif; casepeois when1=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran1<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran2<=random_m0; ifcount_t=1thensum_1<=random_n0+random_m0; elsesum1<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; when2=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran3<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran4<=random_m0; ifcount_t=1thensum_2<=random_n0+random_m0; elsesum2<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; when3=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran1<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran2<=random_m0; ifcount_t=1thensum_3<=random_n0+random_m0; elsesum3<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; when4=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran3<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran4<=random_m0; ifcount_t=1thensum_4<=random_n0+random_m0; elsesum4<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; when5=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran1<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran2<=random_m0; ifcount_t=1thensum_5<=random_n0+random_m0; elsesum5<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; when6=> ifcom='1'then ifcount3=3thencount3<=count3; elsecount3<=count3+1;endif; ifcount3=2then random_n0:=0; random_m0:=0; random_n0:=random; ran3<=random_n0; ifrandom_1=7thenrandom_m0:=1; elserandom_m0:=random_1; endif; ran4<=random_m0; ifcount_t=1thensum_6<=random_n0+random_m0; elsesum6<=random_n0+random_m0; endif; peo<=peo+1; endif; elsecount3<=0; endif; whenothers=> peo<=1; endcase; resu<=res; c<=count_t; endif; endif; endprocess;endc;游戲模式控制(2~6人):libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entitypeopleisport(re,clk,p1,p2:instd_logic; sum:outintegerrange2to6; sig:outstd_logic);endentitypeople;architecturepofpeopleis signalnum:integerrange2to6; signalcount5:integerrange0to3;begin process(clk,p1,p2)is begin if(clk='1'andclk'event)then ifre='1'then sum<=2; sig<='0'; elsifp2='1'then ifcount5=3thencount5<=count5; elsecount5<=count5+1;endif; ifcount5=2then sum<=num;num<=2;sig<='1'; endif; elsifp1='1'then ifcount5=3thencount5<=count5; elsecount5<=count5+1;endif; ifcount5=2then ifnum=6thennum<=2; elsenum<=num+1; endif; sig<='1'; endif; elsecount5<=0; endif; endif; endprocess;endp;點(diǎn)陣顯示:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;useieee.std_logic_signed.all;entitypointisport(sig:instd_logic; clk_in:instd_logic; resu:inintegerrange0to6; col:outstd_logic_vector(7downto0); sound:outstd_logic; raw:outstd_logic_vector(7downto0));endpoint;architecturepofpointis signalcount6:integerrange1to8; signalcount8:integerrange0to499; signalcount9:integerrange1to8; signalcount10:integerrange1to7;begin process(sig,clk_in,resu)is begin if(clk_in='1'andclk_in'event)then ifsig='0'then ifcount8=499then ifcount10=7thencount10<=1; elsecount10<=count10+1; endif; count8<=0; elsecount8<=count8+1; endif; ifcount9=8thencount9<=1; elsecount9<=count9+1; endif; casecount10is when1=> casecount9is-- when1=>raw<="11111111";col<="10000000";-- when2=>raw<="11000001";col<="01000000";-- when3=>raw<="10111111";col<="00100000";-- when4=>raw<="11000001";col<="00010000";-- when5=>raw<="10111111";col<="00001000";-- when6=>raw<="11000001";col<="00000100";-- when7=>raw<="11111111";col<="00000010";-- when8=>raw<="11111111";col<="00000001";-- whenothers=>raw<="11111111";col<="00000000";WHEN1=>raw<="01111111";col<="11111111";WHEN2=>raw<="10111111";col<="11111111";WHEN3=>raw<="11011111";col<="11111111";WHEN4=>raw<="11101111";col<="11111111";WHEN5=>raw<="11110111";col<="11111111";WHEN6=>raw<="11111011";col<="11111111";WHEN7=>raw<="11111101";col<="11111111";WHEN8=>raw<="11111110";col<="11111111"; endcase; sound<='1'; when2=> casecount9isWHEN1=>raw<="01111111";col<="00111100";WHEN2=>raw<="10111111";col<="00100000";WHEN3=>raw<="11011111";col<="00100000";WHEN4=>raw<="11101111";col<="00111100";WHEN5=>raw<="11110111";col<="00100000";WHEN6=>raw<="11111011";col<="00100000";WHEN7=>raw<="11111101";col<="00111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='0'; when3=> casecount9isWHEN1=>raw<="01111111";col<="00111100";WHEN2=>raw<="10111111";col<="00100000";WHEN3=>raw<="11011111";col<="00100000";WHEN4=>raw<="11101111";col<="00111100";WHEN5=>raw<="11110111";col<="00000100";WHEN6=>raw<="11111011";col<="00000100";WHEN7=>raw<="11111101";col<="00111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='1'; when4=> casecount9isWHEN1=>raw<="01111111";col<="00100000";WHEN2=>raw<="10111111";col<="00100000";WHEN3=>raw<="11011111";col<="00100000";WHEN4=>raw<="11101111";col<="00100000";WHEN5=>raw<="11110111";col<="00100000";WHEN6=>raw<="11111011";col<="00100000";WHEN7=>raw<="11111101";col<="00100000";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='0'; when5=> casecount9isWHEN1=>raw<="01111111";col<="00111100";WHEN2=>raw<="10111111";col<="00100100";WHEN3=>raw<="11011111";col<="00100100";WHEN4=>raw<="11101111";col<="00100100";WHEN5=>raw<="11110111";col<="00100100";WHEN6=>raw<="11111011";col<="00100100";WHEN7=>raw<="11111101";col<="00111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='1'; when6=> casecount9isWHEN1=>raw<="01111111";col<="11111111";WHEN2=>raw<="10111111";col<="11111111";WHEN3=>raw<="11011111";col<="11000011";WHEN4=>raw<="11101111";col<="11000011";WHEN5=>raw<="11110111";col<="11000011";WHEN6=>raw<="11111011";col<="11111111";WHEN7=>raw<="11111101";col<="11111111";WHEN8=>raw<="11111110";col<="11111111"; endcase; sound<='0'; when7=> casecount9isWHEN1=>raw<="01111111";col<="11111111";WHEN2=>raw<="10111111";col<="10000001";WHEN3=>raw<="11011111";col<="10000001";WHEN4=>raw<="11101111";col<="10000001";WHEN5=>raw<="11110111";col<="10000001";WHEN6=>raw<="11111011";col<="10000001";WHEN7=>raw<="11111101";col<="11111111";WHEN8=>raw<="11111110";col<="11111111"; endcase; sound<='0'; endcase; else count10<=1; ifcount6=8thencount6<=1; elsecount6<=count6+1; endif; caseresuis when1=> casecount6is-- when5=>col<="00001000";raw<="00000000";-- whenothers=>col<="00000000";raw<="00000000";WHEN1=>raw<="01111111";col<="00000000";WHEN2=>raw<="10111111";col<="01111100";WHEN3=>raw<="11011111";col<="01000000";WHEN4=>raw<="11101111";col<="00100000";WHEN5=>raw<="11110111";col<="00010000";WHEN6=>raw<="11111011";col<="00001000";WHEN7=>raw<="11111101";col<="01111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='1'; when2=> casecount6isWHEN1=>raw<="01111111";col<="00000000";WHEN2=>raw<="10111111";col<="01111100";WHEN3=>raw<="11011111";col<="01010100";WHEN4=>raw<="11101111";col<="01111100";WHEN5=>raw<="11110111";col<="01010100";WHEN6=>raw<="11111011";col<="01111100";WHEN7=>raw<="11111101";col<="00010000";WHEN8=>raw<="11111110";col<="00010000";WHENOTHERS=>count6<=1; endcase; sound<='1'; when3=> casecount6is-- WHEN1=>raw<="01111111";col<="00000000";WHEN2=>raw<="10111111";col<="01111100";WHEN3=>raw<="11011111";col<="01000000";WHEN4=>raw<="11101111";col<="00100000";WHEN5=>raw<="11110111";col<="00010000";WHEN6=>raw<="11111011";col<="00001000";WHEN7=>raw<="11111101";col<="01111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; sound<='1'; when4=> casecount6isWHEN1=>raw<="01111111";col<="00010000";WHEN2=>raw<="10111111";col<="00010000";WHEN3=>raw<="11011111";col<="00010000";WHEN4=>raw<="11101111";col<="00010000";WHEN5=>raw<="11110111";col<="11111111";WHEN6=>raw<="11111011";col<="00111000";WHEN7=>raw<="11111101";col<="01111100";WHEN8=>raw<="11111110";col<="00000000";WHENOTHERS=>count6<=1; endcase; when5=> casecount6isWHEN1=>raw<="01111111";col<="00000000";WHEN2=>raw<="10111111";col<="00000000";WHEN3=>raw<="11011111";col<="00000000";WHEN4=>raw<="11101111";col<="00000000";WHEN5=>raw<="11110111";col<="11111111";WHEN6=>raw<="11111011";col<="11111111";WHEN7=>raw<="11111101";col<="11111111";WHEN8=>raw<="11111110";col<="11111111"; endcase; when6=> casecount6isWHEN1=>raw<="01111111";col<="11111111";WHEN2=>raw<="10111111";col<="11111111";WHEN3=>raw<="11011111";col<="11111111";WHEN4=>raw<="11101111";col<="11111111";WHEN5=>raw<="11110111";col<="00000000";WHEN6=>raw<="11111011";col<="00000000";WHEN7=>raw<="11111101";col<="00000000";WHEN8=>raw<="11111110";col<="00000000"; endcase; whenothers=> col<="00000000";raw<="11111111"; endcase; endif; endif; endprocess;endp;數(shù)碼管顯示:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;useieee.std_logic_signed.all;entitytube_tisport(clk:instd_logic; ran1,ran2,ran3,ran4:inintegerrange0to6; c:inintegerrange1to6; control:outstd_logic_vector(5downto0); tube:outstd_logic_vector(6downto0));endtube_t;architecturetoftube_tissignalcount7:integerrange0to5;procedureshow(variablerandom:inintegerrange0to6;variabletube:outstd_logic_vector(6downto0))is begin caserandomis when1=>tube:="0110000"; when2=>tube:="1101101"; when3=>tube:="1111001"; when4=>tube:="0110011"; when5=>tube:="1011011"; when6=>tube:="1011111"; whenothers=>tube:="0000000"; endcase; endprocedureshow; begin process(clk,ran1,ran2,ran3,ran4,c)is variabletube_n:std_logic_vector(6downto0); variableran_1,ran_2,ran_3,ran_4,c_c:integerrange1to6; begin if(clk='1'andclk'event)then ifcount7=5thencount7<=0; elsecount7<=count7+1; endif; casecount7is when0=> control<="111110"; ran_1:=ran1; show(ran_1,tube_n); tube<=tube_n; when1=> control<="111101"; ran_2:=ran2; show(ran_2,tube_n); tube<=tube_n; when2=> control<="111011"; ran_3:=ran3; show(ran_3,tube_n); tube<=tube_n; when3=> control<="110111"; ran_4:=ran4; show(ran_4,tube_n); tube<=tube_n; when5=> control<="011111"; c_c:=c; show(c_c,tube_n); tube<=tube_n; whenothers=> control<="111111"; tube<="0000000"; endcase; endif; endprocess;endt;libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entityyinjieisport(clk:instd_logic; tone_index:inintegerrange0to7; sound:outstd_logic);endyinjie;architectureyofyinjieissignaltone:std_logic_vector(10downto0);signaltone_count:std_logic_vector(10downto0);signaltemp:std_logic;begin process(clk,tone_index)isbegin caseton

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論