北京邮电大学 数电实验下 报告_第1页
北京邮电大学 数电实验下 报告_第2页
北京邮电大学 数电实验下 报告_第3页
北京邮电大学 数电实验下 报告_第4页
北京邮电大学 数电实验下 报告_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

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

文档简介

20/30数字电路实验报告掷骰子游戏电路班级:XXX学号:XXX姓名:XXX2014年11月8号目录一、 任务要求 1二、 系统设计 11. 设计思路 12. 系统框图 23. 分块设计 5三、 仿真波形及分析 6四、 功能说明及资源利用情况 7五、 故障及问题分析 7六、 总结和结论 8七、 源程序 9任务要求设计并实现一个掷骰子游戏电路。基本要求:电路可供甲乙二人游戏,游戏者甲使用的按键为BTN0,游戏者乙使用的按键为BTN1。每按一次按键,代表掷一次骰子,可随机得到1~6范围内的两个数字。甲乙按键产生的随机数字分别用数码管DISP0-DISP1、DISP2-DISP3显示,并用DISP7显示比赛局数,比赛结束用8×8点阵显示获胜方,并伴有声音效果。具体游戏规则如下:第一局比赛,甲乙依次各按一次按键,按键所得两数之和为7或11者胜;若无人取胜,则进行第二局比赛;第二局比赛,甲乙每人各按一次按键,按键所得二数之和与第一局比赛相同者获胜,若无人获胜,则进行第三局比赛,重复进行步骤(2),直到出现胜者为止。游戏局数最多进行六局。在第六局比赛时,若重复进行步骤(2)仍未出现胜者,以按键所得两数之和最大者为获胜方。提高要求:增加多人游戏的功能,数码管可分时记录显示每个游戏者的骰子点数。点阵显示增加游戏开机动画、结束动画,并伴有乐曲播放。自拟其它功能。系统设计设计思路首先,鉴于FPGA程序语言的特点与EPM系列芯片的功能,采用模块化设计,各模块通过VHDL或基本器件实现,然后通过电路原理图连接各模块。设计方面,主要分为分频器、点阵显示模块、数码管显示模块、随机数生成模块、按键防抖模块、音频模块、逻辑模块。由于数据量小,各模块内部通过编程语言实现寄存功能,而不单独设立储存器。系统框图系统模块图:模块方案:MDS状态图:ASM流程图:分块设计如图,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分频器: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;逻辑与随机数: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;点阵显示: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;数码管显示: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等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论