數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第1頁
數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第2頁
數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第3頁
數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第4頁
數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

.PAGE.數(shù)字電路與邏輯設(shè)計(jì)實(shí)驗(yàn)報(bào)告題目:簡易鋼琴游戲?qū)W院:班級(jí):姓名:學(xué)號(hào):班內(nèi)序號(hào):[實(shí)驗(yàn)任務(wù)及要求]一.基本要求:1.、用8×8點(diǎn)陣進(jìn)行游戲顯示。2、BTN1~BTN7七個(gè)按鍵模擬鋼琴演奏時(shí)的"1234567"七個(gè)音符。點(diǎn)陣的第一列對應(yīng)音符"1",第二列對應(yīng)音符"2",依此類推,低中高音自定。3、光點(diǎn)在點(diǎn)陣第一行隨機(jī)出現(xiàn),逐點(diǎn)下落,下落速度為0.2秒/行,如圖1所示。4、在光點(diǎn)下落到點(diǎn)陣最后一行之前的過程中,如果按下與該列點(diǎn)陣相應(yīng)的音符鍵,該光點(diǎn)消失,蜂鳴器演奏相應(yīng)的音符聲音,計(jì)分器加1。如果在光點(diǎn)下落到最后一行依然沒有進(jìn)行相應(yīng)的按鍵操作,該光點(diǎn)消失,計(jì)分器不加分。計(jì)分器由數(shù)碼管顯示。每隔1秒在點(diǎn)陣的不同列的第一行出現(xiàn)一個(gè)光點(diǎn),如圖2所示。二、提高要求:1、光點(diǎn)在點(diǎn)陣某行隨機(jī)出現(xiàn),然后逐點(diǎn)下落。2、下落速度隨機(jī)變化。3、光點(diǎn)按照存儲(chǔ)的樂曲順序和速度的出現(xiàn)。4、自擬其它功能。三、創(chuàng)新功能:1.將游戲規(guī)則改為只有當(dāng)光電下落到最后一行,并及時(shí)按鍵后,才能加分并發(fā)出對應(yīng)音符,增加了游戲難度,使得游戲更好玩。游戲有兩種模式,通過一個(gè)撥碼開關(guān)控制,游戲中的光電是隨機(jī)出現(xiàn),或者是按照歌曲《小星星》出現(xiàn)。[功能說明] 本實(shí)驗(yàn)利用開發(fā)板模擬鋼琴游戲,總體上實(shí)現(xiàn)了30秒倒計(jì)時(shí),隨機(jī)出點(diǎn)下落,按樂曲出點(diǎn)下落,按鍵及時(shí)按下后用數(shù)碼管顯示計(jì)分,并使蜂鳴器發(fā)聲等功能。①30秒倒計(jì)時(shí):利用開發(fā)板的數(shù)碼管模塊進(jìn)行輸出,當(dāng)接通電源后,游戲的30秒開始倒計(jì)時(shí),當(dāng)計(jì)時(shí)到達(dá)0時(shí),停止出點(diǎn),游戲結(jié)束;可以撥動(dòng)SW0〔reset從新開始游戲。②隨機(jī)出點(diǎn)下落:利用開發(fā)板的點(diǎn)陣輸出模塊,每隔一秒隨機(jī)在第一行的任意一列隨機(jī)出現(xiàn)一個(gè)光點(diǎn),每隔0.2秒光點(diǎn)下落。③按樂曲音符出點(diǎn)下落:利用開發(fā)板的點(diǎn)陣輸出模塊,按照樂曲的音符在點(diǎn)陣的第一行的對應(yīng)位置出現(xiàn)光點(diǎn),每隔0.2秒光點(diǎn)下落。與隨機(jī)出點(diǎn)的功能以一個(gè)撥碼開關(guān)SW1,進(jìn)行切換。④按鍵檢測:利用開發(fā)板的按鍵部分,分別表示1—7中音音符,當(dāng)光點(diǎn)下落到對應(yīng)列的最后一行時(shí),按下對應(yīng)音符的按鍵,可加分,蜂鳴器發(fā)出響應(yīng)音符的響聲。⑤加分:利用開發(fā)板的數(shù)碼管輸出模塊,當(dāng)按鍵及時(shí)按下后,數(shù)碼管顯示的分?jǐn)?shù)對應(yīng)加一。⑥發(fā)聲:利用開發(fā)板的蜂鳴器輸出模塊,當(dāng)按鍵及時(shí)按下后,蜂鳴器發(fā)出該按鍵對應(yīng)的音符的響聲。[系統(tǒng)設(shè)計(jì)]一.設(shè)計(jì)思路通過對功能的分析,可將本系統(tǒng)分為五個(gè)模塊:①點(diǎn)陣模塊:這個(gè)部分是本系統(tǒng)比較重要的部分,主要控制點(diǎn)陣輸出模塊,每隔一秒在點(diǎn)陣的第一行輸出一個(gè)光點(diǎn),并每隔0.2秒控制整個(gè)點(diǎn)陣的光點(diǎn)下落;同時(shí)在該模塊中還應(yīng)判斷按鍵是否及時(shí)按下,輸出加分信號(hào)。②30秒計(jì)時(shí)以及計(jì)分模塊:這個(gè)部分主要是對數(shù)碼管顯示的控制,進(jìn)行30秒的倒計(jì)時(shí)并顯示,同時(shí)根據(jù)輸入的分?jǐn)?shù),顯示當(dāng)前的分?jǐn)?shù)。分?jǐn)?shù)和時(shí)間分別使用2個(gè)數(shù)碼管,本模塊肩負(fù)著對數(shù)碼管資源合理分配的責(zé)任。③出點(diǎn)模塊:這個(gè)部分主要是實(shí)現(xiàn)隨機(jī)產(chǎn)生即將出點(diǎn)的列號(hào)〔即相應(yīng)的音符,或者按照《小星星》這首歌曲的音符產(chǎn)生音符,將該音符值傳給點(diǎn)陣模塊,控制下一秒的出點(diǎn)。④發(fā)聲模塊:這個(gè)模塊主要實(shí)現(xiàn),按照點(diǎn)陣模塊傳入的分頻基準(zhǔn)值,對時(shí)鐘分頻,并輸出給蜂鳴器,從而發(fā)出對應(yīng)音符的聲響。⑤頂層模塊:這個(gè)模塊是以上幾個(gè)模塊的頂層控制,實(shí)現(xiàn)將系統(tǒng)的輸入輸出,以及分模塊之間的輸入輸出聯(lián)系起來的功能,利用compnoent集合以上幾個(gè)模塊。整體思路是分模塊實(shí)現(xiàn)不同的子功能,在不同的模塊對開發(fā)板的不同資源進(jìn)行控制,最后以頂層模塊集合不同模塊,以實(shí)現(xiàn)總體的功能。二.系統(tǒng)總體框圖1、系統(tǒng)硬件結(jié)構(gòu)框圖ModeReset計(jì)分計(jì)時(shí)ModeReset計(jì)分計(jì)時(shí)123456712345672、模塊劃分圖頂層模塊頂層模塊點(diǎn)陣控制,按鍵檢測模塊蜂鳴器發(fā)聲模塊隨機(jī)、按樂曲出點(diǎn)模塊計(jì)分、計(jì)時(shí)模塊3、模塊之間信息傳遞關(guān)系頂層模塊頂層模塊點(diǎn)陣模塊計(jì)分計(jì)時(shí)模塊發(fā)聲模塊出點(diǎn)模塊Input:button,reset,mode,clkOutput:Figure,cat,col,row,out_clk,Clk,reset,scoreFigure,Cat,stopClk,reset,button,yinfu,Col,row,score,freq,callClk,freq,callOut_clkClk,mode,reset,stopYinfuASM圖YESYES啟動(dòng)判斷是否倒計(jì)時(shí)到0NO每隔一秒出點(diǎn),每隔0.2秒點(diǎn)下落判斷光點(diǎn)是否到最后一行YES判斷按鍵是否及時(shí)按下加一分,蜂鳴器發(fā)聲,光點(diǎn)消失NONO結(jié)束YESMDS圖SW1=SW1=’1’SW0=’0’SW1=’1’SW0=’0’等待出點(diǎn)隨機(jī)出點(diǎn),游戲開始按樂曲出點(diǎn),游戲開始游戲結(jié)束30秒計(jì)時(shí)結(jié)束或SW0=’1’30秒計(jì)時(shí)結(jié)束或SW0=’1’SW0=’1’thenSW0=’0’三.分模塊設(shè)計(jì)〔具體代碼見"源程序"1.文件名:piano_game.vhd功能:頂層模塊 在頂層模塊中,我將分模塊以component的形式進(jìn)行聲明,并利用portmap地址映射將相關(guān)聯(lián)的接口參數(shù)映射在一起。2.文件名:dianzhen.vhd功能:點(diǎn)陣模塊該模塊主要完成點(diǎn)陣中每隔一秒出點(diǎn),以及每隔0.2秒下落的功能;同時(shí)檢測按鍵最后一行狀態(tài)對比,判斷是否加分和發(fā)聲;最后輸出點(diǎn)陣的行列信號(hào),分?jǐn)?shù),以及發(fā)聲的分頻基準(zhǔn)值。點(diǎn)陣的row分量用來掃描顯示,因此存入8個(gè)表示選中某一行的向量rowtemp0-rowtemp7用來掃描顯示;點(diǎn)陣的col分量用來表示每一行的狀態(tài),因此存入8個(gè)保存每行狀態(tài)的向量coltemp0-coltemp7。出點(diǎn):該模塊有一個(gè)輸入信號(hào)yinfu〔0-7的整數(shù),表示即將出現(xiàn)的點(diǎn)在哪一列上,用coltmp向量來表示下一個(gè)第一行的狀態(tài),每當(dāng)1S的時(shí)鐘沿到來后,將其賦給coltemp0;下落:每當(dāng)0.2秒的時(shí)鐘沿到來后,將coltemp6賦給coltemp7,coltemp5賦給coltemp6...以此類推,實(shí)現(xiàn)點(diǎn)的下落。鍵盤檢測、加分、發(fā)聲:將輸入的按鍵的向量與coltemp7相與,如果不為0則說明按鍵及時(shí)按下,分?jǐn)?shù)加一,同時(shí)按照相與結(jié)果輸出對應(yīng)音符的分頻基準(zhǔn)值。此處,應(yīng)注意進(jìn)行按鍵防抖,否則計(jì)分將出現(xiàn)問題。3.文件名:scoretime.vhd功能:計(jì)時(shí)計(jì)分模塊該模塊主要完成30秒倒計(jì)時(shí)和分?jǐn)?shù)顯示的功能;最后輸出數(shù)碼管的字符顯示向量和接地信號(hào),以及計(jì)時(shí)到0的游戲結(jié)束信號(hào)。計(jì)時(shí):進(jìn)行1S分頻,計(jì)數(shù)變量初始為30,每當(dāng)1S時(shí)鐘到來后,計(jì)數(shù)變量減一;顯示:根據(jù)計(jì)時(shí)變量,以及輸入的分?jǐn)?shù)值,分別用兩個(gè)數(shù)碼管顯示計(jì)時(shí)和計(jì)分。首先,在分頻進(jìn)程中分出一個(gè)address信號(hào),address取0—3的整數(shù),用來進(jìn)行數(shù)碼管的掃描顯示。當(dāng)address=0和1時(shí),對計(jì)時(shí)的兩個(gè)數(shù)碼管進(jìn)行掃描,當(dāng)address=2和3,對計(jì)分的兩個(gè)數(shù)碼管進(jìn)行掃描,最終達(dá)到同時(shí)顯示計(jì)時(shí)和計(jì)分的目的。4.文件名:tone.vhd功能:出點(diǎn)模塊 該模塊主要完成輸出下一個(gè)點(diǎn)將出現(xiàn)在哪一個(gè)音符對應(yīng)的列上的功能,包含兩種方式:隨機(jī)出點(diǎn)和按《小星星》歌曲出點(diǎn);最后輸出yinfu〔0-7的整數(shù)。隨機(jī)出點(diǎn):產(chǎn)生長度為15的M序列,每隔一秒產(chǎn)生一個(gè)符號(hào),以該符號(hào)位首位的四位二進(jìn)制數(shù)對應(yīng)一個(gè)音符,這樣近似1—7隨機(jī)出現(xiàn);按《小星星》樂曲音符順序出點(diǎn),將一秒規(guī)定為樂曲的一拍,按照《小星星》樂曲,每一秒輸出一個(gè)音符,使得輸出的yinfu變量按照歌曲變化。兩種出點(diǎn)方式以mode輸入?yún)^(qū)。5.文件名:speaker.vhd功能:發(fā)聲模塊 該模塊主要根據(jù)輸入的分頻基準(zhǔn)值進(jìn)行分頻,并將分頻后的時(shí)鐘輸出給蜂鳴器,從而發(fā)出對應(yīng)音符的響聲。此處給出分頻基準(zhǔn)值得確定方式: 由于分頻后對于每個(gè)音調(diào)的頻率都需滿足上值,而分頻器是由計(jì)數(shù)原理進(jìn)行實(shí)現(xiàn)的,因此要將頻率與計(jì)數(shù)之間的關(guān)系進(jìn)行推導(dǎo),得到如下公式,可求出各個(gè)音調(diào)的分頻基準(zhǔn)值:〔其中為分頻基準(zhǔn)值首先我先統(tǒng)一對所有音調(diào)進(jìn)行12分頻,即將50MHz的頻率化歸到4MHz左右,然后再除以每個(gè)音調(diào)傳入的分頻基準(zhǔn)值freq,便可得到相應(yīng)的音調(diào)頻率。本實(shí)驗(yàn)僅涉及到中音的七個(gè)音,分頻基準(zhǔn)值如下:音符1234567分頻基準(zhǔn)值7967709863235969531547354217[仿真波形及波形分析]1.文件名:scoretime.vhd功能:計(jì)時(shí)計(jì)分模塊如圖,計(jì)時(shí)計(jì)分模塊的仿真波形:從圖中可以看出,數(shù)碼管掃描顯示,當(dāng)cat=111101和111110時(shí)掃描顯示計(jì)時(shí),figure輸出對應(yīng)計(jì)時(shí)數(shù)值;當(dāng)cat=111011和110111時(shí)掃描顯示計(jì)分,figure輸出仿真設(shè)定的計(jì)分值4.從該圖中可以看出,計(jì)時(shí)從30到1,而后輸出stop的游戲結(jié)束信號(hào)。2.文件名:tone.vhd功能:出點(diǎn)模塊如圖,出點(diǎn)模塊的仿真波形:從圖中可以看出,當(dāng)mode=0時(shí)是隨機(jī)出點(diǎn)的模式,隨機(jī)輸出yinfu,可以看出yinfu基本是隨機(jī)的。從圖中可以看出,當(dāng)mode=1時(shí)是按照《小星星》歌曲出點(diǎn),yinfu輸出按照歌曲的音符順序輸出。3.文件名:speaker.vhd功能:發(fā)聲模塊如圖,發(fā)聲模塊的仿真波形:從圖中可以看出,只有當(dāng)call=1,即按鍵后才會(huì)發(fā)聲,否則不會(huì)發(fā)聲;且會(huì)按照輸入的分頻基準(zhǔn)值,進(jìn)行對應(yīng)的分頻。4.文件名:dianzhen.vhd功能:點(diǎn)陣模塊如圖,點(diǎn)陣模塊的仿真波形:從圖中可以看出,在row向量進(jìn)行掃描的過程中,col在逐漸下落〔仿真設(shè)置的輸入yinfu為2從圖中可以看出,在按下按鍵后,score會(huì)加一分;5.文件名:piano_game.vhd功能:頂層模塊由上圖可以看出,頂層仿真中光點(diǎn)隨機(jī)出現(xiàn)并下落,落到最后一行消失;其他功能也基本仿真成功。[源程序]1.文件名:piano_game.vhd功能:頂層模塊libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitypiano_gameisport<clk_top:instd_logic;button_top:instd_logic_vector<7downto0>;--按鍵輸入信號(hào)reset_top:instd_logic;mode_top:instd_logic;row_top:outstd_logic_vector<7downto0>;--點(diǎn)陣行輸出信號(hào)col_top:outstd_logic_vector<7downto0>;--點(diǎn)陣列輸出信號(hào)figure_top:outstd_logic_vector<6downto0>;--數(shù)碼管數(shù)值顯示信號(hào) cats_top:outstd_logic_vector<5downto0>;--數(shù)碼管接地信號(hào) out_top:outstd_logic>;endpiano_game;architecturebehavierofpiano_gameiscomponentdianzhenis--點(diǎn)陣模塊Port< clk_dianzhen:instd_logic; button_dianzhen:instd_logic_vector<7downto0>;row_dianzhen:outstd_logic_vector<7downto0>;col_dianzhen:outstd_logic_vector<7downto0>;call_dianzhen:outstd_logic; freq_dianzhen:outintegerrange0to50000000; score_dianzhen:outintegerrange0to30; stop_dianzhen:instd_logic; reset_dianzhen:instd_logic; yinfu_dianzhen:inintegerrange0to8>;endcomponent;componentscoretimeis--計(jì)時(shí)計(jì)分模塊Port< clk_scoretime:instd_logic;--systemclock reset_scoretime:instd_logic; add_score:inintegerrange0to30; stop_time:outstd_logic; figure_scoretime:outstd_logic_vector<6downto0>;--counttime cats_scoretime:outstd_logic_vector<5downto0>>;endcomponent;componentspeakeris--發(fā)聲模塊Port< clk_speaker:instd_logic; freq_speaker:inintegerrange0to50000000; call_speaker:instd_logic; out_speaker:outstd_logic>;endcomponent;componenttoneis--出點(diǎn)模塊Port< clk_tone:instd_logic; reset_tone:instd_logic; stop_tone:instd_logic; mode_tone:instd_logic; yinfu:outintegerrange0to7>;endcomponent;signalstop_top:std_logic;signalcall_top:std_logic;signalfreq_top:integerrange0to50000000;signalscore_top:integerrange0to30;signalyinfu_top:integerrange0to8;--參量對應(yīng)表beginu1:dianzhenportmap<clk_dianzhen=>clk_top,button_dianzhen=>button_top,row_dianzhen=>row_top,col_dianzhen=>col_top,call_dianzhen=>call_top,freq_dianzhen=>freq_top,score_dianzhen=>score_top,stop_dianzhen=>stop_top,reset_dianzhen=>reset_top,yinfu_dianzhen=>yinfu_top>;u2:scoretimeportmap<clk_scoretime=>clk_top,reset_scoretime=>reset_top,add_score=>score_top,stop_time=>stop_top,figure_scoretime=>figure_top,cats_scoretime=>cats_top>;u4:speakerportmap<clk_speaker=>clk_top,freq_speaker=>freq_top,call_speaker=>call_top,out_speaker=>out_top>;u5:toneportmap<clk_tone=>clk_top,reset_tone=>reset_top,stop_tone=>stop_top,yinfu=>yinfu_top,mode_tone=>mode_top>;endbehavier;2.文件名:scoretime.vhd功能:計(jì)時(shí)計(jì)分模塊libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityscoretimeisPort< clk_scoretime:instd_logic;--系統(tǒng)時(shí)鐘 reset_scoretime:instd_logic;--復(fù)位信號(hào) add_score:inintegerrange0to30;--分?jǐn)?shù)輸入 stop_time:outstd_logic;--游戲結(jié)束信號(hào) figure_scoretime:outstd_logic_vector<6downto0>;--數(shù)碼管數(shù)值輸出 cats_scoretime:outstd_logic_vector<5downto0>>;--數(shù)碼管接地輸出endscoretime;architecturebehavierofscoretimeissignalnum_jishi:integerrange0to31:=30;signaltmp:integerrange0to49999999; signaltmp1:integerrange0to2500; signaladdress:integerrange0to3; signalclk_tmp:std_logic; signalstop:std_logic:='0';--stopgamesignalbeginfenpin:process<clk_scoretime,reset_scoretime> begin ifreset_scoretime='1'then tmp<=0; tmp1<=0; elsif<clk_scoretime'eventandclk_scoretime='1'>then iftmp=49999999then--1s分頻 tmp<=0; else tmp<=tmp+1; endif; iftmp<25000000then clk_tmp<='0';elseclk_tmp<='1';endif;tmp1<=tmp1+1;--掃描數(shù)碼管選擇信號(hào)address iftmp1=1250thenif<address=3>thenaddress<=0;endif;tmp1<=0;address<=address+1;endif;endif;endprocess;jishi:process<clk_tmp,reset_scoretime,stop>--計(jì)時(shí)begin ifreset_scoretime='1'then num_jishi<=31; elsif<clk_tmp'eventandclk_tmp='1'>then if<num_jishi>0>then num_jishi<=num_jishi-1; ifnum_jishi=1then stop<='1'; endif; endif; endif; endprocess;stop_time<=stop;--掃描顯示計(jì)時(shí)和計(jì)分show:process<num_jishi,add_score,address>begincaseaddressis when0=> casenum_jishiis when0=>figure_scoretime<="1111110";cats_scoretime<="111101"; when1=>figure_scoretime<="1111110";cats_scoretime<="111101"; when2=>figure_scoretime<="1111110";cats_scoretime<="111101"; when3=>figure_scoretime<="1111110";cats_scoretime<="111101"; when4=>figure_scoretime<="1111110";cats_scoretime<="111101"; when5=>figure_scoretime<="1111110";cats_scoretime<="111101"; when6=>figure_scoretime<="1111110";cats_scoretime<="111101"; when7=>figure_scoretime<="1111110";cats_scoretime<="111101"; when8=>figure_scoretime<="1111110";cats_scoretime<="111101"; when9=>figure_scoretime<="1111110";cats_scoretime<="111101"; when10=>figure_scoretime<="0110000";cats_scoretime<="111101"; when11=>figure_scoretime<="0110000";cats_scoretime<="111101"; when12=>figure_scoretime<="0110000";cats_scoretime<="111101"; when13=>figure_scoretime<="0110000";cats_scoretime<="111101"; when14=>figure_scoretime<="0110000";cats_scoretime<="111101"; when15=>figure_scoretime<="0110000";cats_scoretime<="111101"; when16=>figure_scoretime<="0110000";cats_scoretime<="111101"; when17=>figure_scoretime<="0110000";cats_scoretime<="111101"; when18=>figure_scoretime<="0110000";cats_scoretime<="111101"; when19=>figure_scoretime<="0110000";cats_scoretime<="111101"; when20=>figure_scoretime<="1101101";cats_scoretime<="111101"; when21=>figure_scoretime<="1101101";cats_scoretime<="111101"; when22=>figure_scoretime<="1101101";cats_scoretime<="111101"; when23=>figure_scoretime<="1101101";cats_scoretime<="111101"; when24=>figure_scoretime<="1101101";cats_scoretime<="111101"; when25=>figure_scoretime<="1101101";cats_scoretime<="111101"; when26=>figure_scoretime<="1101101";cats_scoretime<="111101"; when27=>figure_scoretime<="1101101";cats_scoretime<="111101"; when28=>figure_scoretime<="1101101";cats_scoretime<="111101"; when29=>figure_scoretime<="1101101";cats_scoretime<="111101"; when30=>figure_scoretime<="1111001";cats_scoretime<="111101"; whenothers=>cats_scoretime<="111111"; endcase; when1=> casenum_jishiis when0=>figure_scoretime<="1111110";cats_scoretime<="111110"; when1=>figure_scoretime<="0110000";cats_scoretime<="111110"; when2=>figure_scoretime<="1101101";cats_scoretime<="111110"; when3=>figure_scoretime<="1111001";cats_scoretime<="111110"; when4=>figure_scoretime<="0110011";cats_scoretime<="111110"; when5=>figure_scoretime<="1011011";cats_scoretime<="111110"; when6=>figure_scoretime<="1011111";cats_scoretime<="111110"; when7=>figure_scoretime<="1110000";cats_scoretime<="111110"; when8=>figure_scoretime<="1111111";cats_scoretime<="111110"; when9=>figure_scoretime<="1111011";cats_scoretime<="111110"; when10=>figure_scoretime<="1111110";cats_scoretime<="111110"; when11=>figure_scoretime<="0110000";cats_scoretime<="111110"; when12=>figure_scoretime<="1101101";cats_scoretime<="111110"; when13=>figure_scoretime<="1111001";cats_scoretime<="111110"; when14=>figure_scoretime<="0110011";cats_scoretime<="111110"; when15=>figure_scoretime<="1011011";cats_scoretime<="111110"; when16=>figure_scoretime<="1011111";cats_scoretime<="111110"; when17=>figure_scoretime<="1110000";cats_scoretime<="111110"; when18=>figure_scoretime<="1111111";cats_scoretime<="111110"; when19=>figure_scoretime<="1111011";cats_scoretime<="111110"; when20=>figure_scoretime<="1111110";cats_scoretime<="111110"; when21=>figure_scoretime<="0110000";cats_scoretime<="111110"; when22=>figure_scoretime<="1101101";cats_scoretime<="111110"; when23=>figure_scoretime<="1111001";cats_scoretime<="111110"; when24=>figure_scoretime<="0110011";cats_scoretime<="111110"; when25=>figure_scoretime<="1011011";cats_scoretime<="111110"; when26=>figure_scoretime<="1011111";cats_scoretime<="111110"; when27=>figure_scoretime<="1110000";cats_scoretime<="111110"; when28=>figure_scoretime<="1111111";cats_scoretime<="111110"; when29=>figure_scoretime<="1111011";cats_scoretime<="111110"; when30=>figure_scoretime<="1111110";cats_scoretime<="111110"; whenothers=>cats_scoretime<="111111"; endcase; when2=> caseadd_scoreis when0=>figure_scoretime<="1111110";cats_scoretime<="110111"; when1=>figure_scoretime<="1111110";cats_scoretime<="110111"; when2=>figure_scoretime<="1111110";cats_scoretime<="110111"; when3=>figure_scoretime<="1111110";cats_scoretime<="110111"; when4=>figure_scoretime<="1111110";cats_scoretime<="110111"; when5=>figure_scoretime<="1111110";cats_scoretime<="110111"; when6=>figure_scoretime<="1111110";cats_scoretime<="110111"; when7=>figure_scoretime<="1111110";cats_scoretime<="110111"; when8=>figure_scoretime<="1111110";cats_scoretime<="110111"; when9=>figure_scoretime<="1111110";cats_scoretime<="110111"; when10=>figure_scoretime<="0110000";cats_scoretime<="110111"; when11=>figure_scoretime<="0110000";cats_scoretime<="110111"; when12=>figure_scoretime<="0110000";cats_scoretime<="110111"; when13=>figure_scoretime<="0110000";cats_scoretime<="110111"; when14=>figure_scoretime<="0110000";cats_scoretime<="110111"; when15=>figure_scoretime<="0110000";cats_scoretime<="110111"; when16=>figure_scoretime<="0110000";cats_scoretime<="110111"; when17=>figure_scoretime<="0110000";cats_scoretime<="110111"; when18=>figure_scoretime<="0110000";cats_scoretime<="110111"; when19=>figure_scoretime<="0110000";cats_scoretime<="110111"; when20=>figure_scoretime<="1101101";cats_scoretime<="110111"; when21=>figure_scoretime<="1101101";cats_scoretime<="110111"; when22=>figure_scoretime<="1101101";cats_scoretime<="110111"; when23=>figure_scoretime<="1101101";cats_scoretime<="110111"; when24=>figure_scoretime<="1101101";cats_scoretime<="110111"; when25=>figure_scoretime<="1101101";cats_scoretime<="110111"; when26=>figure_scoretime<="1101101";cats_scoretime<="110111"; when27=>figure_scoretime<="1101101";cats_scoretime<="110111"; when28=>figure_scoretime<="1101101";cats_scoretime<="110111"; when29=>figure_scoretime<="1101101";cats_scoretime<="110111"; when30=>figure_scoretime<="1111001";cats_scoretime<="110111"; whenothers=>cats_scoretime<="111111"; endcase; when3=> caseadd_scoreis when0=>figure_scoretime<="1111110";cats_scoretime<="111011"; when1=>figure_scoretime<="0110000";cats_scoretime<="111011"; when2=>figure_scoretime<="1101101";cats_scoretime<="111011"; when3=>figure_scoretime<="1111001";cats_scoretime<="111011"; when4=>figure_scoretime<="0110011";cats_scoretime<="111011"; when5=>figure_scoretime<="1011011";cats_scoretime<="111011"; when6=>figure_scoretime<="1011111";cats_scoretime<="111011"; when7=>figure_scoretime<="1110000";cats_scoretime<="111011"; when8=>figure_scoretime<="1111111";cats_scoretime<="111011"; when9=>figure_scoretime<="1111011";cats_scoretime<="111011"; when10=>figure_scoretime<="1111110";cats_scoretime<="111011"; when11=>figure_scoretime<="0110000";cats_scoretime<="111011"; when12=>figure_scoretime<="1101101";cats_scoretime<="111011"; when13=>figure_scoretime<="1111001";cats_scoretime<="111011"; when14=>figure_scoretime<="0110011";cats_scoretime<="111011"; when15=>figure_scoretime<="1011011";cats_scoretime<="111011"; when16=>figure_scoretime<="1011111";cats_scoretime<="111011"; when17=>figure_scoretime<="1110000";cats_scoretime<="111011"; when18=>figure_scoretime<="1111111";cats_scoretime<="111011"; when19=>figure_scoretime<="1111011";cats_scoretime<="111011"; when20=>figure_scoretime<="1111110";cats_scoretime<="111011"; when21=>figure_scoretime<="0110000";cats_scoretime<="111011"; when22=>figure_scoretime<="1101101";cats_scoretime<="111110"; when23=>figure_scoretime<="1111001";cats_scoretime<="111011"; when24=>figure_scoretime<="0110011";cats_scoretime<="111011"; when25=>figure_scoretime<="1011011";cats_scoretime<="111011"; when26=>figure_scoretime<="1011111";cats_scoretime<="111011"; when27=>figure_scoretime<="1110000";cats_scoretime<="111011"; when28=>figure_scoretime<="1111111";cats_scoretime<="111011"; when29=>figure_scoretime<="1111011";cats_scoretime<="111011"; when30=>figure_scoretime<="1111110";cats_scoretime<="111011"; whenothers=>cats_scoretime<="111111"; endcase; endcase; endprocess;endbehavier;3.文件名:dianzhen.vhd功能:點(diǎn)陣模塊libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitydianzhenisPort< clk_dianzhen:instd_logic; button_dianzhen:instd_logic_vector<7downto0>;--按鍵輸入信號(hào) stop_dianzhen:instd_logic;--游戲結(jié)束信號(hào) reset_dianzhen:instd_logic;--復(fù)位信號(hào) yinfu_dianzhen:inintegerrange0to8;--輸入的下一個(gè)點(diǎn)輸出的列號(hào)row_dianzhen:outstd_logic_vector<7downto0>;--點(diǎn)陣行輸出信號(hào)col_dianzhen:outstd_logic_vector<7downto0>;--點(diǎn)陣列輸出信號(hào)call_dianzhen:outstd_logic;--按鍵檢測信號(hào) freq_dianzhen:outintegerrange0to50000000;--音符的分頻系數(shù) score_dianzhen:outintegerrange0to30>;--分?jǐn)?shù)enddianzhen;architecturebehavierofdianzhenissignalpotary:integerrange0to7;signalrowtemp0:std_logic_vector<7downto0>:="01111111";--存儲(chǔ)八個(gè)row向量,用來掃描顯示signalrowtemp1:std_logic_vector<7downto0>:="10111111";signalrowtemp2:std_logic_vector<7downto0>:="11011111";signalrowtemp3:std_logic_vector<7downto0>:="11101111";signalrowtemp4:std_logic_vector<7downto0>:="11110111";signalrowtemp5:std_logic_vector<7downto0>:="11111011";signalrowtemp6:std_logic_vector<7downto0>:="11111101";signalrowtemp7:std_logic_vector<7downto0>:="11111110";signalcoltmp:std_logic_vector<7downto0>:="00000000";--下一個(gè)第一行的狀態(tài)signalcoltemp0:std_logic_vector<7downto0>:="00000000";--存儲(chǔ)8個(gè)col向量,用來表示每一行的狀態(tài)signalcoltemp1:std_logic_vector<7downto0>:="00000000";signalcoltemp2:std_logic_vector<7downto0>:="00000000";signalcoltemp3:std_logic_vector<7downto0>:="00000000";signalcoltemp4:std_logic_vector<7downto0>:="00000000";signalcoltemp5:std_logic_vector<7downto0>:="00000000";signalcoltemp6:std_logic_vector<7downto0>:="00000000";signalcoltemp7:std_logic_vector<7downto0>:="00000000";signalclk_tmp:std_logic:='0';signaltmp:integerrange0to5;signalbutton:std_logic_vector<7downto0>;signalscore:integerrange0to30;begin fenpin:process<clk_dianzhen,reset_dianzhen,stop_dianzhen> variableptime:integerrange0to100000; variableqtime:integerrange0to5000000; begin if<reset_dianzhen='1'orstop_dianzhen='1'>then ptime:=0; qtime:=0; elsif<clk_dianzhen'eventandclk_dianzhen='1'>then ptime:=ptime+1; qtime:=qtime+1; if<qtime=5000000>then clk_tmp<=notclk_tmp; qtime:=0; endif; if<ptime=100000>then--點(diǎn)陣掃描分頻 ifpotary=7thenpotary<=0; elsepotary<=potary+1; endif; ptime:=0; endif; endif;endprocess;setcol00:process<yinfu_dianzhen,reset_dianzhen,stop_dianzhen>--根據(jù)輸入的yinfu來翻譯出下一個(gè)第一行的狀態(tài) begin if<reset_dianzhen='1'orstop_dianzhen='1'>then coltmp<="00000000"; else caseyinfu_dianzhenis when7=>coltmp<="01000000"; when6=>coltmp<="00100000"; when5=>coltmp<="00010000"; when4=>coltmp<="00001000"; when3=>coltmp<="00000100"; when2=>coltmp<="00000010"; when1=>coltmp<="00000001"; whenothers=>coltmp<="00000000"; endcase;endif; endprocess;xialuo:process<clk_tmp,potary> begin if<clk_tmp'eventandclk_tmp='1'>then coltemp7<=coltemp6; coltemp6<=coltemp5; coltemp5<=coltemp4; coltemp4<=coltemp3; coltemp3<=coltemp2; coltemp2<=coltemp1; coltemp1<=coltemp0; coltemp0<="00000000"; tmp<=tmp+1; if<tmp=5>then coltemp0<=coltmp; tmp<=0; endif; endif; if<clk_dianzhen'eventandclk_dianzhen='1'>thencasepotaryis--橫向掃描,得到清晰的點(diǎn)陣信號(hào) when0=>row_dianzhen<=rowtemp0;col_dianzhen<=coltemp0; when1=>row_dianzhen<=rowtemp1;col_dianzhen<=coltemp1; when2=>row_dianzhen<=rowtemp2;col_dianzhen<=coltemp2; when3=>row_dianzhen<=rowtemp3;col_dianzhen<=coltemp3; when4=>row_dianzhen<=rowtemp4;col_dianzhen<=coltemp4; when5=>row_dianzhen<=rowtemp5;col_dianzhen<=coltemp5; when6=>row_dianzhen<=rowtemp6;col_dianzhen<=coltemp6; when7=>row_dianzhen<=rowtemp7;col_dianzhen<=coltemp7; endcase; endif; endprocess; jifen:process<button_dianzhen,coltemp7,reset_dianzhen>--判斷按鍵是否及時(shí)按下,計(jì)分,并輸出相應(yīng)的分頻基準(zhǔn)值begin button<=button_dianzhenandcoltemp7; if<reset_dianzhen='1'>then score<=0; else if<clk_tmp'eventandclk_tmp='1'>then casebuttonis when"00000001"=>freq_dianzhen<=7967;call_dianzhen<='1';score<=score+1; when"00000010"=>freq_dianzhen<=7098;call_dianzhen<='1';score<=score+1; when"00000100"=>freq_dianzhen<=6323;call_dianzhen<='1';score<=score+1; when"00001000"=>freq_dianzhen<=5969;call_dianzhen<='1';score<=score+1; when"00010000"=>freq_dianzhen<=5315;call_dianzhen<='1';score<=score+1; when"00100000"=>freq_dianzhen<=4735;call_dianzhen<='1';score<=score+1; when"01000000"=>freq_dianzhen<=4217;call_dianzhen<='1';score<=score+1; whenothers=>freq_dianzhen<=0;call_dianzhen<='0';score<=score+0; endcase; endif; endif; endprocess;score_dianzhen<=score;endbehavier;4.文件名:tone.vhd功能:出點(diǎn)模塊libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitytoneisPort< clk_tone:instd_logic; reset_tone:instd_logic; stop_tone:instd_logic; mode_tone:instd_logic; yinfu:outintegerrange0to7>;endtone;architecturebehavieroftoneissignaltmp:integerrange0to50000000;signaltmp2:integerrange0to30;signalclk_tmp:std_logic;signaltemp:std_logic_vector<3downto0>;begindivide_freq1:process<clk_tone>begin ifreset_tone='1'orstop_tone='1'then tmp<=0; elsifclk_tone'eventandclk_tone='1'then iftmp=49999999then--1s分頻 tmp<=0; else tmp<=tmp+1; endif; iftmp<25000000then clk_tmp<='0';elseclk_tmp<='1';endif; endif;endprocess;play_music:process<clk_tmp>beginif<mode_tone='1'>then--如果mode=1.則按照《小星星》這首歌出點(diǎn)ifclk_tmp'eventandclk_tmp='1'thentmp2<=tmp2+1;casetmp2iswhen1=>yinfu<=1;when2=>yinfu<=1;when3=>yinfu<=5;when4=>yinfu<=5;when5=>yinfu<=6;when6=>yinfu<=6;when7=>fyinfu<=5;when8=>yinfu<=4;when9=>fyinfu<=4;when10=>yinfu<=3;when11=>yinfu<=3;when12=>yinfu<=2;when13=>yinfu<=2;when14=>yinfu<=1;when15=>yinfu<=5;when16=>yinfu<=5;when17=>yinfu<=4when18=>yinfu<=4;when19=>yinfu<=3;when20=>yinfu<=3;when21=>yinfu<=2;when22=>yinfu<=5;when23=>yinfu<=5;when24=>yinfu<=4;when25=>yinfu<=4;when26=>yinfu<=3;when27=>yinfu<=3;when28=>yinfu<=2;when29=>yinfu<=1;when30=>yinfu<=1;tmp2<=0;whenothers=>yinfu<=0;endcase;endif;elsifmode_tone='0'then--如果mode=0,則,隨機(jī)出點(diǎn) if<temp="0000">thentemp<="0001"; elsif<clk_tmp'eventandclk_tmp='1'>then temp<0><=temp<0>xortemp<3>; temp<1><=temp<0>; temp<2><=temp<1>; temp<3><=temp<2>; endif; casetempis when"0000"=>yinfu<=1; when"0001"=>yinfu<=2; when"0010"=>yinfu<=3; when"0011"=>yinfu<=4; when"0100"=>yinfu<=5; when"0101"=>yinfu<=6; when"0110"=>yinfu<=7; when"0111"=>yinfu<=1; when"1000"=>yinfu<=2; when"1001"=>yinfu<=3; when"1010"=>yinfu<=4; when"1011"=>yinfu<=5; when"1100"=>yinfu<=6; when"1101"=>yinfu<=7; when"1110"=>yinfu<=1; when"1111"=>yinfu<=2; whenothers=>yinfu<=0; endcase; endif;endprocess;endbehavier;5.文件名:speaker.vhd功能:發(fā)聲模塊libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityspeakerisPort< clk_speaker:instd_logic;--系統(tǒng)時(shí)鐘 freq_speaker:inintegerrange0to50000000;--音符

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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ǔ)空間,僅對用戶上傳內(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論