北京邮电大学 数电实验下 报告
- 格式:docx
- 大小:1.18 MB
- 文档页数:31
数字电路实验报告掷骰子游戏电路班级:XXX学号:XXX姓名:XXX2014年11月8号目录一、任务要求 (2)二、系统设计 (2)1. 设计思路 (2)2. 系统框图 (3)3. 分块设计 (6)三、仿真波形及分析 (7)四、功能说明及资源利用情况 (8)五、故障及问题分析 (9)六、总结和结论 (9)七、源程序 (10)一、任务要求设计并实现一个掷骰子游戏电路。
基本要求:1.电路可供甲乙二人游戏,游戏者甲使用的按键为BTN0,游戏者乙使用的按键为BTN1。
2.每按一次按键,代表掷一次骰子,可随机得到1~6范围内的两个数字。
3.甲乙按键产生的随机数字分别用数码管DISP0-DISP1、DISP2-DISP3显示,并用DISP7显示比赛局数,比赛结束用8×8点阵显示获胜方,并伴有声音效果。
4.具体游戏规则如下:5.第一局比赛,甲乙依次各按一次按键,按键所得两数之和为7或11者胜;若无人取胜,则进行第二局比赛;6.第二局比赛,甲乙每人各按一次按键,按键所得二数之和与第一局比赛相同者获胜,若无人获胜,则进行第三局比赛,重复进行步骤(2),直到出现胜者为止。
7.游戏局数最多进行六局。
在第六局比赛时,若重复进行步骤(2)仍未出现胜者,以按键所得两数之和最大者为获胜方。
提高要求:1.增加多人游戏的功能,数码管可分时记录显示每个游戏者的骰子点数。
2.点阵显示增加游戏开机动画、结束动画,并伴有乐曲播放。
3.自拟其它功能。
二、系统设计1.设计思路首先,鉴于FPGA程序语言的特点与EPM系列芯片的功能,采用模块化设计,各模块通过VHDL或基本器件实现,然后通过电路原理图连接各模块。
设计方面,主要分为分频器、点阵显示模块、数码管显示模块、随机数生成模块、按键防抖模块、音频模块、逻辑模块。
由于数据量小,各模块内部通过编程语言实现寄存功能,而不单独设立储存器。
2.系统框图系统模块图:模块方案:MDS状态图:ASM流程图:3.分块设计如图,clk_1hz为分频模块,people为多人游戏控制器,point为点阵显示模块,tube_t 为数码管显示模块,comp包含了逻辑与随机数生成模块,anjian包含多人游戏按键控制及防抖。
三、仿真波形及分析由于多人多模式、开机动画、自动复位等附加功能涉及信号过多,且均建立在基础程序之上,未进行仿真,此仿真版本只实现了基本功能,包括:按键触发随机数,两人游戏逻辑及显示模块,蜂鸣器产生提示音,时钟clk为0.04us(25mhz)。
观测BUTTONTEST与fangdouTESTout,可见防抖模块运行正常,输出为高电平触发信号。
EndTESTa1、endTESTa2、endTESTjushu分别为随按键随机生成的两个数和增加的局数,可见a1呈2等差,印证了错误1(见错误分析),a2正常工作。
再对应观察numberTEST与segTEST,可见numberTEST正常工作,显示随机数对应的编码,但数码管选位信号segTEST未改变,未查明原因(电路正常工作)。
JuzhengTESTa、JuzhengTESTb、JuzhengTESTc为别为甲乙平三种状态对应的point模式选择函数,观察JuzhengTESTcol、JuzhengTESTrow,可见point模块正常工作。
另外,SPEAKER 输出信号正常工作。
luojiTESTa1、luojiTESTa2、luojiTESTg1分别对应逻辑判断模块甲乙的和及局数,luojiTESTa、luojiTESTb、luojiTESTc分别对应甲乙平三种状态选位输出。
可见,若将图中黑块视为低电平,则逻辑甲乙判断正确,但平始终为高电平输出,且在出判断结果后。
分析得出,黑块是由于在出结果后继续进行游戏导致的冲突,不影响游戏(此程序还未加入reset功能),平结果同样是其导致的标志位冲突(进入other条件)。
四、功能说明及资源利用情况●基本功能实现:能通过两个BTN按键实现两人游戏(可循环),随机生成1~6的骰子数并计算和,数码管能显示骰子结果与局数,点阵能正确显示胜利者(甲或乙),并有蜂鸣音提示,符合要求的游戏规则(第一局和为7或11者胜,2~5局与本人第一句和相同者胜,第6局和较大者胜)。
●扩展功能实现:能通过额外按键增加游戏人数(最大为6人)并实现所有的游戏功能,增加复位功能,开机动画及音效,以及可实现两音节的简单铃音。
解决游戏规则bug:若第6局平手则提示平局,并能实现自动复位。
可实现不同顺序进行游戏。
●资源利用情况:外围设备使用点阵、数码管、4个BTN按键、蜂鸣器及烧录模块。
由编译结果,芯片使用521个逻辑元件(41%),36个外部管脚(31%)。
规模在可执行范围内。
五、故障及问题分析●游戏规则bug:若第6局参赛者出现和相等(平手),规则未作出说明如何处理,自拟增加如下规则,若第六句平手,则提示平局,并自动复位。
●随机数生成bug:第一次设计时,采用两个随机数生成器同时生成某位选手的两个数,但由于同时性,为避免数字相同,分别采用+1和+2不断循环内部变量,但由于+2组不能生成奇数随机数,并且同时生成随机数带来一系列逻辑上的问题(难以比较取值)。
后改为由同一生成器分时取随机数,解决问题。
●游戏顺序改进:起初,由于设计上的缺陷,只能以规定顺序进行游戏,后经提醒,改进设计模式,增加按键分配模块,解决游戏顺序的缺陷,实现不同顺序游戏功能。
●时钟选择错误:起初,由于在逻辑模块方面使用为分频的时钟信号,频率过高,导致结果出错率较高(不能跑完代码),后引入1khz分频,解决逻辑错误。
六、总结和结论●关于分频:分频是FPGA设计非常重要的一环。
各个模块由于功能不同需要不同的触发条件,设计过程值得深究。
起初也由于这方面的失误久久无法解决逻辑上的问题(仿真无误,运行时出错)。
●设计模式:虽然此前接触C语言较久,但进行vhdl需要完全不同的思路,vhdl是一门硬件描述语言,采用的是自顶向下的设计思想,即先描述一个电路的总体功能,然后给予具体地实现。
就像搭建电路一样,先给出总体框图然后分块实现。
一个电路当然就有级联的和并联电路就是所谓的用“并行语句和顺序语句”来描述。
而c语言目前还没有一个编译器能把它翻译为硬件描述语言,尽管Verilog有点像c所谓象是他们的设计思路有点象,具体的语法规则还是有很大差异。
c语言目前几乎都是在cpu中运行所以只能按指令的形式按顺序执行下来。
因此,fpga设计时必须对系统做好提前的规划分配,也得益于这次规划比较好,实验进行的也还算顺利。
总的来说,进行了一次完全不同体验的设计,获益匪浅,也很有成就感。
七、源程序1khz分频器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_signed.all; use ieee.std_logic_signed.all;entity clk_1khz is---div frequent 1port (clk_in :in std_logic;clk:out std_logic); end entity clk_1khz;architecture c of clk_1khz is signal count0:integer range 0 to 49999;beginprocess (clk_in) isvariable clk_i:std_logic;beginif (clk_in ='1' and clk_in'event) thenif count0 = 49999 then count0 <= 0;else count0 <= count0+1;end if ;if count0 = 0 thenclk_i := not clk_i;end if;end if;clk <= clk_i;end process ;end c;●按键防抖:library ieee;use ieee.std_logic_1164.all; useieee.std_logic_unsigned.all; entity fangdou isport(reset,clk:in std_logic;reseto:out std_logic); end; architecture m1 of fangdou is signal tmp1,tmp2:std_logic; signal clkt:std_logic;beginprocess(clk)beginif clk 'event and clk='0' then tmp2<=tmp1;tmp1<=reset;end if;end process;reseto<=clk AND tmp1 AND (NOT tmp2);end;●逻辑与随机数:entity comp isport(re,clk_in,com:in std_logic;people:in integer range 2 to 6;ran1,ran2,ran3,ran4:out integer range 0 to 6;c:out integer range 1 to 6;resu:out integer range 0 to 6);end entity comp;architecture c of comp issignal count3:integer range 0 to 3;signal peo:integer range 1 to 7;signal count_t:integer range 1 to 6;signal num:integer range 0 to 1;signal sum_1,sum_2,sum_3,sum_4,sum_5,sum_6:integer range 0 to 12;signal sum1,sum2,sum3,sum4,sum5,sum6:integer range 0 to 12;signal random:integer range 1 to 6;signal random_1:integer range 1 to 7;beginprocess (clk_in,people,com,count_t,num)isvariable res:integer range 0 to 6;variable random_m0,random_n0:integer range 0 to 6;variable f1,f2,f3,f4,f5,f6:integer range 0 to 1;beginif (clk_in='1' and clk_in'event) thenif random=6 then random<=1;else random <=random+1;end if;if random_1=7 then random_1<=1;else random_1 <= random_1 + 1;end if;if re = '1' thencount_t <= 1;ran1 <= 0;ran2 <= 0;ran3 <= 0;ran4 <= 0;res := 0;peo <= 1;elseif peo >people thencase count_t iswhen 1 =>if(sum_1=7 or sum_1=11) then f1:=1;else f1:=0;end if;if(sum_2=7 or sum_2=11) then f2:=1;else f2:=0;end if;if(sum_3=7 or sum_3=11) then f3:=1;else f3:=0;end if;if(sum_4=7 or sum_4=11) then f4:=1;else f4:=0;end if;if(sum_5=7 or sum_5=11) then f5:=1;else f5:=0;end if;if(sum_6=7 or sum_6=11) then f6:=1;else f6:=0;end if;if(f1 = 1 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 1;count_t <= 1;elsif(f1 = 0 and f2 = 1 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 2;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 1 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 3;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 1 and f5 = 0 and f6 = 0) thenres := 4;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 1 and f6 = 0) thenres := 5;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 1) thenres := 6;count_t <= 1;elsecount_t <= count_t + 1;end if;when 2 to 5 =>if(sum1>0 and sum1=sum_1) then f1:=1;else f1:=0;end if;if(sum2>0 and sum2=sum_2) then f2:=1;else f2:=0;end if;if(sum3>0 and sum3=sum_3) then f3:=1;else f3:=0;end if;if(sum4>0 and sum4=sum_4) then f4:=1;else f4:=0;end if;if(sum5>0 and sum5=sum_5) then f5:=1;else f5:=0;end if;if(sum6>0 and sum6=sum_6) then f6:=1;else f6:=0;end if;if(f1 = 1 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 1;count_t <= 1;elsif(f1 = 0 and f2 = 1 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 2;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 1 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 3;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 1 and f5 = 0 and f6 = 0) thenres := 4;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 1 and f6 = 0) thenres := 5;count_t <= 1;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 1) thenres := 6;count_t <= 1;elsecount_t <= count_t + 1;end if;when 6 =>if(sum1>0 and sum1=sum_1) then f1:=1;else f1:=0;end if;if(sum2>0 and sum2=sum_2) then f2:=1;else f2:=0;end if;if(sum3>0 and sum3=sum_3) then f3:=1;else f3:=0;end if;if(sum4>0 and sum4=sum_4) then f4:=1;else f4:=0;end if;if(sum5>0 and sum5=sum_5) then f5:=1;else f5:=0;end if;if(sum6>0 and sum6=sum_6) then f6:=1;else f6:=0;end if;if(f1 = 1 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 1;elsif(f1 = 0 and f2 = 1 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 2;elsif(f1 = 0 and f2 = 0 and f3 = 1 and f4 = 0 and f5 = 0 and f6 = 0) thenres := 3;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 1 and f5 = 0 and f6 = 0) thenres := 4;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 1 and f6 = 0) thenres := 5;elsif(f1 = 0 and f2 = 0 and f3 = 0 and f4 = 0 and f5 = 0 and f6 = 1) thenres := 6;elseif(sum1 > sum2 and sum1 > sum3 and sum1 >sum4 and sum1 > sum5 and sum1 > sum6) thenres := 1;elsif(sum2 > sum1 and sum2 > sum3 and sum2 >sum4 and sum2 > sum5 and sum2 > sum6) thenres := 2;elsif(sum3 > sum1 and sum3 > sum2 and sum3 >sum4 and sum3 > sum5 and sum3 > sum6) thenres := 3;elsif(sum4 > sum1 and sum4 > sum2 and sum4 >sum3 and sum4 > sum5 and sum4 > sum6) thenres := 4;elsif(sum5 > sum1 and sum5 > sum2 and sum5 >sum3 and sum5 > sum4 and sum5 > sum6) thenres := 5;elsif(sum6 > sum1 and sum6 > sum2 and sum6 >sum3 and sum6 > sum4 and sum6 > sum5) thenres := 6;else res := 0;end if;end if;count_t <= 1;when others =>count_t <= 1;end case;peo <= 1;end if;case peo iswhen 1 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0 := random;ran1 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran2 <= random_m0;if count_t = 1 then sum_1 <= random_n0 + random_m0;else sum1 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when 2 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0:=random;ran3 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran4 <= random_m0;if count_t = 1 then sum_2 <= random_n0 + random_m0;else sum2 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when 3 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0 := random;ran1 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran2 <= random_m0;if count_t = 1 then sum_3 <= random_n0 + random_m0;else sum3 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when 4 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0:=random;ran3 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran4 <= random_m0;if count_t = 1 then sum_4 <= random_n0 + random_m0;else sum4 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when 5 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0:=random;ran1 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran2 <= random_m0;if count_t = 1 then sum_5 <= random_n0 + random_m0;else sum5 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when 6 =>if com = '1' thenif count3 = 3 then count3<=count3;else count3<=count3+1;end if;if count3 = 2 thenrandom_n0 := 0;random_m0 := 0;random_n0:=random;ran3 <= random_n0;if random_1 = 7 then random_m0 := 1;else random_m0 := random_1;end if;ran4 <= random_m0;if count_t = 1 then sum_6 <= random_n0 + random_m0;else sum6 <= random_n0 + random_m0;end if;peo <= peo + 1;end if;else count3 <= 0;end if;when others =>peo <= 1;end case;resu <= res;c<=count_t;end if;end if;end process;end c;游戏模式控制(2~6人): library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all; useieee.std_logic_unsigned.all;entity people isport (re,clk,p1,p2:in std_logic;sum:out integer range 2 to 6;sig:out std_logic);end entity people;architecture p of people is signal num:integer range 2 to 6;signal count5:integer range 0 to 3;beginprocess (clk,p1,p2) isbeginif (clk = '1' and clk'event) thenif re = '1' thensum <= 2;sig <= '0';elsif p2 = '1' thenif count5 = 3 then count5 <= count5;else count5 <= count5 + 1;end if;if count5 = 2 thensum <= num; num <= 2;sig <= '1';end if;elsif p1 = '1' thenif count5 = 3 then count5 <= count5;else count5 <= count5 + 1;end if;if count5 = 2 thenif num = 6 then num <= 2;else num <= num + 1;end if;sig <= '1';end if;else count5 <= 0;end if;end if;end process;end p;点阵显示:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_signed.all;use ieee.std_logic_signed.all;entity point isport(sig:in std_logic;clk_in:in std_logic;resu:in integer range 0 to 6;col:out std_logic_vector(7 downto 0);sound:out std_logic;raw:out std_logic_vector(7 downto 0));end point;architecture p of point issignal count6:integer range 1 to 8;signal count8:integer range 0 to 499;signal count9:integer range 1 to 8;signal count10:integer range 1 to 7;beginprocess (sig,clk_in,resu) isbeginif (clk_in='1' and clk_in'event) thenif sig = '0' thenif count8 = 499 thenif count10 = 7 then count10 <= 1;else count10 <= count10 + 1;end if;count8 <= 0;else count8 <= count8 + 1;end if;if count9 = 8 then count9 <= 1;else count9 <= count9 + 1;end if;case count10 iswhen 1=>case count9 is-- when 1=>raw<="11111111";col<="10000000";-- when 2=>raw<="11000001";col<="01000000";-- when 3=>raw<="10111111";col<="00100000";-- when 4=>raw<="11000001";col<="00010000";-- when 5=>raw<="10111111";col<="00001000";-- when 6=>raw<="11000001";col<="00000100";-- when 7=>raw<="11111111";col<="00000010";-- when 8=>raw<="11111111";col<="00000001";-- when others=>raw<="11111111";col<="00000000"; WHEN 1=>raw<="01111111";col<="11111111";WHEN 2=>raw<="10111111";col<="11111111";WHEN 3=>raw<="11011111";col<="11111111";WHEN 4=>raw<="11101111";col<="11111111";WHEN 5=>raw<="11110111";col<="11111111";WHEN 6=>raw<="11111011";col<="11111111";WHEN 7=>raw<="11111101";col<="11111111";WHEN 8=>raw<="11111110";col<="11111111";end case;sound<='1';when 2=>case count9 isWHEN 1=>raw<="01111111";col<="00111100";WHEN 2=>raw<="10111111";col<="00100000";WHEN 3=>raw<="11011111";col<="00100000";WHEN 4=>raw<="11101111";col<="00111100";WHEN 5=>raw<="11110111";col<="00100000";WHEN 6=>raw<="11111011";col<="00100000";WHEN 7=>raw<="11111101";col<="00111100";WHEN 8=>raw<="11111110";col<="00000000";WHEN OTHERS=>count6<=1;end case;sound<='0';when 3=>case count9 isWHEN 1=>raw<="01111111";col<="00111100";WHEN 2=>raw<="10111111";col<="00100000"; WHEN 3=>raw<="11011111";col<="00100000"; WHEN 4=>raw<="11101111";col<="00111100"; WHEN 5=>raw<="11110111";col<="00000100"; WHEN 6=>raw<="11111011";col<="00000100"; WHEN 7=>raw<="11111101";col<="00111100"; WHEN 8=>raw<="11111110";col<="00000000"; WHEN OTHERS=>count6<=1;end case;sound<='1';when 4=>case count9 isWHEN 1=>raw<="01111111";col<="00100000"; WHEN 2=>raw<="10111111";col<="00100000"; WHEN 3=>raw<="11011111";col<="00100000"; WHEN 4=>raw<="11101111";col<="00100000"; WHEN 5=>raw<="11110111";col<="00100000"; WHEN 6=>raw<="11111011";col<="00100000"; WHEN 7=>raw<="11111101";col<="00100000"; WHEN 8=>raw<="11111110";col<="00000000"; WHEN OTHERS=>count6<=1;end case;sound<='0';when 5=>case count9 isWHEN 1=>raw<="01111111";col<="00111100"; WHEN 2=>raw<="10111111";col<="00100100"; WHEN 3=>raw<="11011111";col<="00100100"; WHEN 4=>raw<="11101111";col<="00100100"; WHEN 5=>raw<="11110111";col<="00100100"; WHEN 6=>raw<="11111011";col<="00100100"; WHEN 7=>raw<="11111101";col<="00111100"; WHEN 8=>raw<="11111110";col<="00000000"; WHEN OTHERS=>count6<=1;end case;sound<='1';when 6=>case count9 isWHEN 1=>raw<="01111111";col<="11111111"; WHEN 2=>raw<="10111111";col<="11111111"; WHEN 3=>raw<="11011111";col<="11000011"; WHEN 4=>raw<="11101111";col<="11000011"; WHEN 5=>raw<="11110111";col<="11000011"; WHEN 6=>raw<="11111011";col<="11111111";WHEN 7=>raw<="11111101";col<="11111111";WHEN 8=>raw<="11111110";col<="11111111";end case;sound<='0';when 7=>case count9 isWHEN 1=>raw<="01111111";col<="11111111";WHEN 2=>raw<="10111111";col<="10000001";WHEN 3=>raw<="11011111";col<="10000001";WHEN 4=>raw<="11101111";col<="10000001";WHEN 5=>raw<="11110111";col<="10000001";WHEN 6=>raw<="11111011";col<="10000001";WHEN 7=>raw<="11111101";col<="11111111";WHEN 8=>raw<="11111110";col<="11111111";end case;sound<='0';end case;elsecount10 <= 1;if count6 = 8 then count6 <= 1;else count6 <= count6 + 1;end if;case resu iswhen 1 =>case count6 is-- when 5 => col <= "00001000"; raw <= "00000000"; -- when others => col <= "00000000"; raw <= "00000000";WHEN 1=>raw<="01111111";col<="00000000";WHEN 2=>raw<="10111111";col<="01111100";WHEN 3=>raw<="11011111";col<="01000000";WHEN 4=>raw<="11101111";col<="00100000";WHEN 5=>raw<="11110111";col<="00010000";WHEN 6=>raw<="11111011";col<="00001000";WHEN 7=>raw<="11111101";col<="01111100";WHEN 8=>raw<="11111110";col<="00000000";WHEN OTHERS=>count6<=1;end case;sound<='1';when 2 =>case count6 isWHEN 1=>raw<="01111111";col<="00000000"; WHEN 2=>raw<="10111111";col<="01111100"; WHEN 3=>raw<="11011111";col<="01010100"; WHEN 4=>raw<="11101111";col<="01111100"; WHEN 5=>raw<="11110111";col<="01010100"; WHEN 6=>raw<="11111011";col<="01111100"; WHEN 7=>raw<="11111101";col<="00010000"; WHEN 8=>raw<="11111110";col<="00010000"; WHEN OTHERS=>count6<=1;end case;sound<='1';when 3 =>case count6 is--WHEN 1=>raw<="01111111";col<="00000000"; WHEN 2=>raw<="10111111";col<="01111100"; WHEN 3=>raw<="11011111";col<="01000000"; WHEN 4=>raw<="11101111";col<="00100000"; WHEN 5=>raw<="11110111";col<="00010000"; WHEN 6=>raw<="11111011";col<="00001000"; WHEN 7=>raw<="11111101";col<="01111100"; WHEN 8=>raw<="11111110";col<="00000000"; WHEN OTHERS=>count6<=1;end case;sound<='1';when 4 =>case count6 isWHEN 1=>raw<="01111111";col<="00010000"; WHEN 2=>raw<="10111111";col<="00010000"; WHEN 3=>raw<="11011111";col<="00010000"; WHEN 4=>raw<="11101111";col<="00010000"; WHEN 5=>raw<="11110111";col<="11111111"; WHEN 6=>raw<="11111011";col<="00111000"; WHEN 7=>raw<="11111101";col<="01111100"; WHEN 8=>raw<="11111110";col<="00000000"; WHEN OTHERS=>count6<=1;end case;when 5 =>case count6 isWHEN 1=>raw<="01111111";col<="00000000"; WHEN 2=>raw<="10111111";col<="00000000"; WHEN 3=>raw<="11011111";col<="00000000";WHEN 4=>raw<="11101111";col<="00000000";WHEN 5=>raw<="11110111";col<="11111111";WHEN 6=>raw<="11111011";col<="11111111";WHEN 7=>raw<="11111101";col<="11111111";WHEN 8=>raw<="11111110";col<="11111111";end case;when 6 =>case count6 isWHEN 1=>raw<="01111111";col<="11111111";WHEN 2=>raw<="10111111";col<="11111111";WHEN 3=>raw<="11011111";col<="11111111";WHEN 4=>raw<="11101111";col<="11111111";WHEN 5=>raw<="11110111";col<="00000000";WHEN 6=>raw<="11111011";col<="00000000";WHEN 7=>raw<="11111101";col<="00000000";WHEN 8=>raw<="11111110";col<="00000000";end case;when others =>col <= "00000000"; raw <= "11111111";end case;end if;end if;end process;end p;数码管显示:library ieee;use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; use ieee.std_logic_signed.all;entity tube_t isport(clk:in std_logic;ran1,ran2,ran3,ran4:in integer range 0 to 6;c:in integer range 1 to 6;control:outstd_logic_vector(5 downto 0);tube:out std_logic_vector(6 downto 0));end tube_t;architecture t of tube_t is signal count7:integer range 0 to 5;procedure show(variable random:in integer range 0 to 6;variable tube:out std_logic_vector(6 downto 0)) isbegincase random iswhen 1 => tube := "0110000";when 2 => tube := "1101101";when 3 => tube := "1111001";when 4 => tube := "0110011";when 5 => tube :="1011011";when 6 => tube := "1011111";when others => tube :="0000000";end case;end procedure show;beginprocess(clk,ran1,ran2,ran3, ran4,c) isvariabletube_n:std_logic_vector(6 downto 0);variableran_1,ran_2,ran_3,ran_4,c_c:int eger range 1 to 6;beginif (clk='1' and clk'event) thenif count7=5 then count7<=0;elsecount7<=count7+1;end if;case count7 iswhen 0 =>control<="111110";ran_1 := ran1;show(ran_1,tube_n);tube<=tube_n;when 1 =>control<="111101";ran_2 := ran2;show(ran_2,tube_n);tube<=tube_n;when 2 =>control<="111011";ran_3 := ran3;show(ran_3,tube_n);tube<=tube_n;when 3 =>control<="110111";ran_4 := ran4;show(ran_4,tube_n);tube<=tube_n;when 5 =>control<="011111";c_c := c;show(c_c,tube_n);tube<=tube_n;when others =>control <= "111111";tube<="0000000";end case;end if;end process;end t;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all; useieee.std_logic_unsigned.all; entity yinjie isport(clk:in std_logic;tone_index:in integer range 0 to 7;sound:out std_logic);end yinjie;architecture y of yinjie is signal tone:std_logic_vector(10 downto 0);signaltone_count:std_logic_vector(10 downto 0);signal temp:std_logic;beginprocess (clk,tone_index) isbegincase tone_index iswhen0=>tone<="11111111111"; --no outputwhen1=>tone<="01100000101"; --773when2=>tone<="01110010000"; --912when3=>tone<="10000001100";--1036when4=>tone<="10001010111";--1111when5=>tone<="10010101101";--1197when6=>tone<="10100001010";--1290when7=>tone<="10101011100";--1372whenothers=>tone<="11111111111";--others:no outputend case;if(clk'event and clk='1') thenif(tone_count="11111111111") thentone_count <= tone;if(tone < 2047) thentemp <= not temp;end if;elsetone_count <= tone_count + 1;end if;sound <= temp;end if;end process;end y;音乐模块:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_signed.all; use ieee.std_logic_signed.all; entity music_1 isport(sig:in std_logic;resu: in integer range 0 to 6;clk: in std_logic;-- sound: out std_logic;tone_index:out integer range 0 to 7);end music_1;architecture m of music_1 is signal count4:integer range 0 to 41;beginprocess (clk,resu,sig) isbeginif(clk'event and clk='1') then。