数字电路与逻辑设计实验报告_第1页
数字电路与逻辑设计实验报告_第2页
数字电路与逻辑设计实验报告_第3页
数字电路与逻辑设计实验报告_第4页
数字电路与逻辑设计实验报告_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

.PAGE.数字电路与逻辑设计实验报告题目:简易钢琴游戏学院:班级:姓名:学号:班内序号:[实验任务及要求]一.基本要求:1.、用8×8点阵进行游戏显示。2、BTN1~BTN7七个按键模拟钢琴演奏时的"1234567"七个音符。点阵的第一列对应音符"1",第二列对应音符"2",依此类推,低中高音自定。3、光点在点阵第一行随机出现,逐点下落,下落速度为0.2秒/行,如图1所示。4、在光点下落到点阵最后一行之前的过程中,如果按下与该列点阵相应的音符键,该光点消失,蜂鸣器演奏相应的音符声音,计分器加1。如果在光点下落到最后一行依然没有进行相应的按键操作,该光点消失,计分器不加分。计分器由数码管显示。每隔1秒在点阵的不同列的第一行出现一个光点,如图2所示。二、提高要求:1、光点在点阵某行随机出现,然后逐点下落。2、下落速度随机变化。3、光点按照存储的乐曲顺序和速度的出现。4、自拟其它功能。三、创新功能:1.将游戏规则改为只有当光电下落到最后一行,并及时按键后,才能加分并发出对应音符,增加了游戏难度,使得游戏更好玩。游戏有两种模式,通过一个拨码开关控制,游戏中的光电是随机出现,或者是按照歌曲《小星星》出现。[功能说明] 本实验利用开发板模拟钢琴游戏,总体上实现了30秒倒计时,随机出点下落,按乐曲出点下落,按键及时按下后用数码管显示计分,并使蜂鸣器发声等功能。①30秒倒计时:利用开发板的数码管模块进行输出,当接通电源后,游戏的30秒开始倒计时,当计时到达0时,停止出点,游戏结束;可以拨动SW0〔reset从新开始游戏。②随机出点下落:利用开发板的点阵输出模块,每隔一秒随机在第一行的任意一列随机出现一个光点,每隔0.2秒光点下落。③按乐曲音符出点下落:利用开发板的点阵输出模块,按照乐曲的音符在点阵的第一行的对应位置出现光点,每隔0.2秒光点下落。与随机出点的功能以一个拨码开关SW1,进行切换。④按键检测:利用开发板的按键部分,分别表示1—7中音音符,当光点下落到对应列的最后一行时,按下对应音符的按键,可加分,蜂鸣器发出响应音符的响声。⑤加分:利用开发板的数码管输出模块,当按键及时按下后,数码管显示的分数对应加一。⑥发声:利用开发板的蜂鸣器输出模块,当按键及时按下后,蜂鸣器发出该按键对应的音符的响声。[系统设计]一.设计思路通过对功能的分析,可将本系统分为五个模块:①点阵模块:这个部分是本系统比较重要的部分,主要控制点阵输出模块,每隔一秒在点阵的第一行输出一个光点,并每隔0.2秒控制整个点阵的光点下落;同时在该模块中还应判断按键是否及时按下,输出加分信号。②30秒计时以及计分模块:这个部分主要是对数码管显示的控制,进行30秒的倒计时并显示,同时根据输入的分数,显示当前的分数。分数和时间分别使用2个数码管,本模块肩负着对数码管资源合理分配的责任。③出点模块:这个部分主要是实现随机产生即将出点的列号〔即相应的音符,或者按照《小星星》这首歌曲的音符产生音符,将该音符值传给点阵模块,控制下一秒的出点。④发声模块:这个模块主要实现,按照点阵模块传入的分频基准值,对时钟分频,并输出给蜂鸣器,从而发出对应音符的声响。⑤顶层模块:这个模块是以上几个模块的顶层控制,实现将系统的输入输出,以及分模块之间的输入输出联系起来的功能,利用compnoent集合以上几个模块。整体思路是分模块实现不同的子功能,在不同的模块对开发板的不同资源进行控制,最后以顶层模块集合不同模块,以实现总体的功能。二.系统总体框图1、系统硬件结构框图ModeReset计分计时ModeReset计分计时123456712345672、模块划分图顶层模块顶层模块点阵控制,按键检测模块蜂鸣器发声模块随机、按乐曲出点模块计分、计时模块3、模块之间信息传递关系顶层模块顶层模块点阵模块计分计时模块发声模块出点模块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启动判断是否倒计时到0NO每隔一秒出点,每隔0.2秒点下落判断光点是否到最后一行YES判断按键是否及时按下加一分,蜂鸣器发声,光点消失NONO结束YESMDS图SW1=SW1=’1’SW0=’0’SW1=’1’SW0=’0’等待出点随机出点,游戏开始按乐曲出点,游戏开始游戏结束30秒计时结束或SW0=’1’30秒计时结束或SW0=’1’SW0=’1’thenSW0=’0’三.分模块设计〔具体代码见"源程序"1.文件名:piano_game.vhd功能:顶层模块 在顶层模块中,我将分模块以component的形式进行声明,并利用portmap地址映射将相关联的接口参数映射在一起。2.文件名:dianzhen.vhd功能:点阵模块该模块主要完成点阵中每隔一秒出点,以及每隔0.2秒下落的功能;同时检测按键最后一行状态对比,判断是否加分和发声;最后输出点阵的行列信号,分数,以及发声的分频基准值。点阵的row分量用来扫描显示,因此存入8个表示选中某一行的向量rowtemp0-rowtemp7用来扫描显示;点阵的col分量用来表示每一行的状态,因此存入8个保存每行状态的向量coltemp0-coltemp7。出点:该模块有一个输入信号yinfu〔0-7的整数,表示即将出现的点在哪一列上,用coltmp向量来表示下一个第一行的状态,每当1S的时钟沿到来后,将其赋给coltemp0;下落:每当0.2秒的时钟沿到来后,将coltemp6赋给coltemp7,coltemp5赋给coltemp6...以此类推,实现点的下落。键盘检测、加分、发声:将输入的按键的向量与coltemp7相与,如果不为0则说明按键及时按下,分数加一,同时按照相与结果输出对应音符的分频基准值。此处,应注意进行按键防抖,否则计分将出现问题。3.文件名:scoretime.vhd功能:计时计分模块该模块主要完成30秒倒计时和分数显示的功能;最后输出数码管的字符显示向量和接地信号,以及计时到0的游戏结束信号。计时:进行1S分频,计数变量初始为30,每当1S时钟到来后,计数变量减一;显示:根据计时变量,以及输入的分数值,分别用两个数码管显示计时和计分。首先,在分频进程中分出一个address信号,address取0—3的整数,用来进行数码管的扫描显示。当address=0和1时,对计时的两个数码管进行扫描,当address=2和3,对计分的两个数码管进行扫描,最终达到同时显示计时和计分的目的。4.文件名:tone.vhd功能:出点模块 该模块主要完成输出下一个点将出现在哪一个音符对应的列上的功能,包含两种方式:随机出点和按《小星星》歌曲出点;最后输出yinfu〔0-7的整数。随机出点:产生长度为15的M序列,每隔一秒产生一个符号,以该符号位首位的四位二进制数对应一个音符,这样近似1—7随机出现;按《小星星》乐曲音符顺序出点,将一秒规定为乐曲的一拍,按照《小星星》乐曲,每一秒输出一个音符,使得输出的yinfu变量按照歌曲变化。两种出点方式以mode输入区。5.文件名:speaker.vhd功能:发声模块 该模块主要根据输入的分频基准值进行分频,并将分频后的时钟输出给蜂鸣器,从而发出对应音符的响声。此处给出分频基准值得确定方式: 由于分频后对于每个音调的频率都需满足上值,而分频器是由计数原理进行实现的,因此要将频率与计数之间的关系进行推导,得到如下公式,可求出各个音调的分频基准值:〔其中为分频基准值首先我先统一对所有音调进行12分频,即将50MHz的频率化归到4MHz左右,然后再除以每个音调传入的分频基准值freq,便可得到相应的音调频率。本实验仅涉及到中音的七个音,分频基准值如下:音符1234567分频基准值7967709863235969531547354217[仿真波形及波形分析]1.文件名:scoretime.vhd功能:计时计分模块如图,计时计分模块的仿真波形:从图中可以看出,数码管扫描显示,当cat=111101和111110时扫描显示计时,figure输出对应计时数值;当cat=111011和110111时扫描显示计分,figure输出仿真设定的计分值4.从该图中可以看出,计时从30到1,而后输出stop的游戏结束信号。2.文件名:tone.vhd功能:出点模块如图,出点模块的仿真波形:从图中可以看出,当mode=0时是随机出点的模式,随机输出yinfu,可以看出yinfu基本是随机的。从图中可以看出,当mode=1时是按照《小星星》歌曲出点,yinfu输出按照歌曲的音符顺序输出。3.文件名:speaker.vhd功能:发声模块如图,发声模块的仿真波形:从图中可以看出,只有当call=1,即按键后才会发声,否则不会发声;且会按照输入的分频基准值,进行对应的分频。4.文件名:dianzhen.vhd功能:点阵模块如图,点阵模块的仿真波形:从图中可以看出,在row向量进行扫描的过程中,col在逐渐下落〔仿真设置的输入yinfu为2从图中可以看出,在按下按键后,score会加一分;5.文件名:piano_game.vhd功能:顶层模块由上图可以看出,顶层仿真中光点随机出现并下落,落到最后一行消失;其他功能也基本仿真成功。[源程序]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>;--按键输入信号reset_top:instd_logic;mode_top:instd_logic;row_top:outstd_logic_vector<7downto0>;--点阵行输出信号col_top:outstd_logic_vector<7downto0>;--点阵列输出信号figure_top:outstd_logic_vector<6downto0>;--数码管数值显示信号 cats_top:outstd_logic_vector<5downto0>;--数码管接地信号 out_top:outstd_logic>;endpiano_game;architecturebehavierofpiano_gameiscomponentdianzhenis--点阵模块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--计时计分模块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--发声模块Port< clk_speaker:instd_logic; freq_speaker:inintegerrange0to50000000; call_speaker:instd_logic; out_speaker:outstd_logic>;endcomponent;componenttoneis--出点模块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;--参量对应表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功能:计时计分模块libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityscoretimeisPort< clk_scoretime:instd_logic;--系统时钟 reset_scoretime:instd_logic;--复位信号 add_score:inintegerrange0to30;--分数输入 stop_time:outstd_logic;--游戏结束信号 figure_scoretime:outstd_logic_vector<6downto0>;--数码管数值输出 cats_scoretime:outstd_logic_vector<5downto0>>;--数码管接地输出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;--扫描数码管选择信号address iftmp1=1250thenif<address=3>thenaddress<=0;endif;tmp1<=0;address<=address+1;endif;endif;endprocess;jishi:process<clk_tmp,reset_scoretime,stop>--计时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;--扫描显示计时和计分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功能:点阵模块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>;--按键输入信号 stop_dianzhen:instd_logic;--游戏结束信号 reset_dianzhen:instd_logic;--复位信号 yinfu_dianzhen:inintegerrange0to8;--输入的下一个点输出的列号row_dianzhen:outstd_logic_vector<7downto0>;--点阵行输出信号col_dianzhen:outstd_logic_vector<7downto0>;--点阵列输出信号call_dianzhen:outstd_logic;--按键检测信号 freq_dianzhen:outintegerrange0to50000000;--音符的分频系数 score_dianzhen:outintegerrange0to30>;--分数enddianzhen;architecturebehavierofdianzhenissignalpotary:integerrange0to7;signalrowtemp0:std_logic_vector<7downto0>:="01111111";--存储八个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";--下一个第一行的状态signalcoltemp0:std_logic_vector<7downto0>:="00000000";--存储8个col向量,用来表示每一行的状态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--点阵扫描分频 ifpotary=7thenpotary<=0; elsepotary<=potary+1; endif; ptime:=0; endif; endif;endprocess;setcol00:process<yinfu_dianzhen,reset_dianzhen,stop_dianzhen>--根据输入的yinfu来翻译出下一个第一行的状态 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--横向扫描,得到清晰的点阵信号 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>--判断按键是否及时按下,计分,并输出相应的分频基准值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功能:出点模块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.则按照《小星星》这首歌出点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,则,随机出点 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功能:发声模块libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityspeakerisPort< clk_speaker:instd_logic;--系统时钟 freq_speaker:inintegerrange0to50000000;--音符

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论