verilogHDL抢答器(两个程序)Word版.doc

上传人:rrsccc 文档编号:9420378 上传时间:2021-02-24 格式:DOC 页数:11 大小:87.50KB
返回 下载 相关 举报
verilogHDL抢答器(两个程序)Word版.doc_第1页
第1页 / 共11页
verilogHDL抢答器(两个程序)Word版.doc_第2页
第2页 / 共11页
verilogHDL抢答器(两个程序)Word版.doc_第3页
第3页 / 共11页
verilogHDL抢答器(两个程序)Word版.doc_第4页
第4页 / 共11页
verilogHDL抢答器(两个程序)Word版.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《verilogHDL抢答器(两个程序)Word版.doc》由会员分享,可在线阅读,更多相关《verilogHDL抢答器(两个程序)Word版.doc(11页珍藏版)》请在三一文库上搜索。

1、传播优秀Word版文档 ,希望对您有帮助,可双击去除!一、设计任务智力竞赛抢答器Verilog HDL要求有6位参赛者进行抢答,有六个抢答信号进行抢答。当有抢答选手按下抢答键后系统能够快速准确的判断是那一组选手按下了抢答信号,由于系统比较小,速度比较快一般不会有同时按下的可能,所以只有六种状态,然后系统能够根据这六种状态进行适时的显示和提示。当有选手按下以后就对抢答信号进行锁存,其他选手的输入无效。然后就是对抢答进行时间限制了,根据设定的时间进行倒计时,当倒计时完成还没有人抢答的时候系统发出警报声音提示时间已经到了。当有选手在主持人未按下抢答键抢答时视为超前抢答,系统显示该选手号,同时蜂鸣器响

2、,该抢答无效。还有清除复位键,抢答完成以后按复位键即可清除已有的状态。通过Verilog HDL程序代码实现系统的各个功能。二、设计目的与要求目的:理论联系实际,巩固和运用所学课程,提高分析、解决计算机技术实际问题的独立工作能力,培养学生正确的设计思想,严肃认真、实事求是的科学态度和勇于探索的创新精神。通过对一个智力抢答器的设计,进一步加深对计算机原理以及数字电路应用技术方面的了解与认识,进一步熟悉数字电路系统设计、制作与调试的方法和步骤,通过Verilog 程序的编写,进一步熟悉Verilog HDL 的语法知识;规范化训练学生撰写技术研究报告,提高书面表达能力。要求: 掌握FPGA设计系统

3、的一般方法。 熟练掌握使用modelsim软件设计较复杂的数字逻辑电路。 培养学生独立分析问题和解决实际问题的能力。三、 课程设计的内容设计一抢答器,要求如下:(1)抢答台数为6;(2)具有抢答开始后20s倒计时,20秒倒计时后6人抢答显示超时,并报警;(3)能显示超前抢答台号并显示犯规报警;(4)系统复位后进入抢答状态,当有一路抢答按键按下,该路抢答信号将其余各路抢答信号封锁,同时铃声响起,直至该路按键松开,显示牌显示该路抢答台号。四、系统设计方案传播优秀Word版文档 ,希望对您有帮助,可双击去除!根据系统设计要求可知,系统的输入信号有:主持人按钮inputEn,各选手的抢答按钮分别是in

4、putL1、inputL2、inputL3、inputL4,inputL5,inputL6,主持人和选手抢答按钮都是低电平有效,系统复位信号clr(高电平有效),系统时钟信号clk,系统的输出信号有:六个人抢答成功与否的指示灯控制信号输出口Led2,犯规抢答时报警器Buzzer(低电平有效)。本系统应具有的功能有:能够准确的判断出是哪位抢答者,当主持人没按抢答时,有人抢答了则蜂鸣器报警,并显示该选手号,当主持人按了抢答键时有人抢答了,同时封锁抢答信号,其他选手抢答无效,不显示该选手号。五、仿真过程与仿真结果仿真过程:使用ModelSim进行功能测试,首先在里面进行相应的设置,在工程文件夹下面会

5、新建一个modelsim的文件夹,然后编写实现功能的程序和测试文件,最后保存编译执行就可以进行功能仿真了。仿真结果 : 结果分析与讨论:可以看到0时刻系统复位状态,2s时2号超前抢答(inputEn为高电平,inputL2为低电平),系统显示2蜂鸣器并犯规报警(Buzzer为低电平),8s时系统复位状态,12s时4号选手先抢答成功(inputL4为低电平)显示4,14s时3号选手后抢答,不显示3,20s时系统复位。六、总结传播优秀Word版文档 ,希望对您有帮助,可双击去除! 通过本次合成设计,我又一遍熟悉了Verilog HDL语言进行建模,并且通过实际操作学会了怎么使用Modelsim这个

6、软件来完成一个完整的课程设计。以及对基于FPGA的系统开发流程有了一个整体认识,我越来越认识到一点, 编程对项目实现有着至关重要的, 我们在硬件开发的过程中更应该重视编程, 将编程看作是完善开发的不可缺少的一部分。虽然题目简单,但这也磨练了我的意志。第一次做的太复杂了,然后一次次修改,做成最简单功能的。在一次次的反复设计、论证和测试中, 提高了逻辑分析能力、全面分析问题的能力以及发现问题、解决问题的能力。通过对各方面资料的收集, 我的知识面也进一步拓宽了。同时,我也发现了自己的不足, 像语言表达还比较差, 不能更清楚地表达自己的意思, 逻辑分析能力和编程能力有待提高,有些预先的想法都未能实现。

7、在系统的结构设计上也还有很长的路需要走,这是需要时间去积累的。在今后的学习中我还得加以改进。七、程序系统主要Verilog HDL源程序:module QiangDaQi(clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led2,Buzzer); /一开始声明有哪些端口input clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6;output 0:7Led2;/Led2显示选手号output Buzzer;/低电平时蜂鸣器发出声音reg

8、EnFlat=1b0;/EnFlat为高电平时开始抢答reg 0:2Led2=3d0;reg Buzzer=1b1;always (posedge clk)/时钟上升沿begin if(inputEn=1)/如果主持人没按按钮就有人抢答 begin if(inputL1=0) begin Led2=3d1;Buzzer=1b0;end if(inputL2=0) begin Led2=3d2;Buzzer=1b0;end if(inputL3=0) begin Led2=3d3;Buzzer=1b0;end if(inputL4=0) begin Led2=3d4;Buzzer=1b0;end

9、 if(inputL5=0) begin Led2=3d5;Buzzer=1b0;end if(inputL6=0) begin Led2=3d6;Buzzer=1b0;end end if(inputEn=1b0)/为低电平时表示主持人按下抢答按钮开始抢答 begin EnFlat=1b1;传播优秀Word版文档 ,希望对您有帮助,可双击去除! if(EnFlat=1b1) begin if(inputL1=1b0)/一号选手抢答 begin Led2=3d1; EnFlat=1b0;/为低电平禁止其他选手抢答 Buzzer=1b1; end else/一开始没加else发现仿真结果随着输入

10、数据变化而变化 if(inputL2=1b0)/二号选手抢答 begin Led2=3d2; EnFlat=1b0; Buzzer=1b0; end else if(inputL3=1b0)/三号选手抢答 begin Led2=3d3; EnFlat=1b0;/为低电平禁止其他选手抢答 Buzzer=1b1; endelse if(inputL4=1b0)/四号选手抢答 begin Led2=3d4; EnFlat=1b0;/为低电平禁止其他选手抢答 Buzzer=1b1; end else if(inputL5=1b0)/五号选手抢答 begin Led2=3d5; EnFlat=1b0;/

11、为低电平禁止其他选手抢答 Buzzer=1b1; end else if(inputL6=1b0)/六号选手抢答 begin Led2=3d6; EnFlat=1b0;/为低电平禁止其他选手抢答 Buzzer=1b1; end end传播优秀Word版文档 ,希望对您有帮助,可双击去除! end if(clr)/按下clr键以后各组参数重置,整个比赛重新开始 begin EnFlat=1b0; Led2=3d0;/为低电平时,选手前的灯点亮 Buzzer=1b1;/为高电平不响 endendendmodule测试程序timescale 1s/1smodule qiangdaqi_test();

12、 reg clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6;/输入口 wire 0:7Led2;/Led2显示选手号 wire Buzzer;/低电平时蜂鸣器发出声音 QiangDaQi u1(clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led2,Buzzer); initial begin #0 clk=1;clr=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5

13、=1;inputL6=1; #2 inputL2=0;/二号选手超前抢答 #4 clr=1;inputL2=1;/复位 #2 clr=0; #4 inputEn=0;inputL4=0;/四号选手先抢答显示4 #2 inputL3=0;/三号选手后抢答不显示3 #4 clr=1;inputEn=1;inputL3=1;inputL4=1; #2 clr=0; end always #1 clk=clk;endmodule程序二module QiangDaQi(clk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inpu

14、tL6,Led1,Led2,Led3,Buzzer); /一开始声明有哪些端口input clk,clr,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,add,stu;/输入口output 0:5Led1;/对应参赛选手前的灯传播优秀Word版文档 ,希望对您有帮助,可双击去除!output 0:7Led2,Led3;/Led2显示选手号Led3显示选手分数output Buzzer;/低电平时蜂鸣器发出声音reg EnFlat=1b1;/EnFlat为高电平时开始抢答reg BuClk=1b0;/为高电平时进入蜂鸣器处理程序/

15、reg add,stu;/add答题正确加一分stu答题错误减一分/reg clr=0;/重置键reg 0:5Led1=6b111111;reg 0:2 answer=3d0;reg0:3 score=4d0,score1=4d0,score2=4d0;reg0:3 score3=4d0,score4=4d0,score5=4d0,score6=4d0;/各选手分数计算reg Buzzer=1;reg 0:4 daojishi=5d20;/用于产生20s倒计时reg 0:7Led2=8b11111111,Led3=8b11111111;always (posedge clk)/时钟上升沿beg

16、in if(inputEn=1)/如果主持人没按按钮就有人抢答 begin if(inputL1=0) begin Led1=6b111110;answer=3d1;BuClk=1b1;end if(inputL2=0) begin Led2=6b111101;answer=3d2;BuClk=1b1;end if(inputL3=0) begin Led2=6b111011;answer=3d3;BuClk=1b1;end if(inputL4=0) begin Led2=6b110111;answer=3d4;BuClk=1b1;end if(inputL5=0) begin Led2=6

17、b101111;answer=3d5;BuClk=1b1;end if(inputL6=0) begin Led2=6b011111;answer=3d6;BuClk=1b1;end end if(inputEn=1b0)/为低电平时表示主持人按下抢答按钮开始抢答beginLed1=6b111111;/为低电平时,选手前的灯点亮BuClk=1b0;Buzzer=1b1;/为高电平不响end if(EnFlat=1b1) begin begin if(inputL1=1b0)/一号选手抢答 begin EnFlat=1b0;/为低电平禁止其他选手抢答 answer=3d1;/为高电平时转到对应选

18、手加减分程序中去 BuClk=1b1;/转到蜂鸣器程序传播优秀Word版文档 ,希望对您有帮助,可双击去除! end if(inputL2=1b0)/二号选手抢答 beginEnFlat=1b0;answer=3d2;BuClk=1b1; end if(inputL3=1b0)/三号选手抢答 beginEnFlat=1b0;answer=3d3;BuClk=1b1; end if(inputL4=1b0)/四号选手抢答 beginEnFlat=1b0;answer=3d4;BuClk=1b1; end if(inputL5=1b0)/五号选手抢答 beginEnFlat=1b0;answer=

19、3d5;BuClk=1b1; end if(inputL6=1b0)/六号选手抢答 beginEnFlat=1b0;answer=3d6;BuClk=1b1; end end begin if(daojishi!=5d0)/用于1Hz信号 daojishi=daojishi-1; else/倒计时结束抢答器还没按下则抢答停止且蜂鸣器响 begin daojishi=5d20; EnFlat=1b0; BuClk=1b1; end end begin if(BuClk=1b1)/当蜂鸣器标志为1时传播优秀Word版文档 ,希望对您有帮助,可双击去除! Buzzer=1b0;/蜂鸣器发声 end

20、begin if(answer =3d1)/第一组加减分 begin Led1=6b111110;/点亮该选手前的LED灯 Led2=8hf9;/选手号数码管显示1 if(add) score1=score1+1;/当主持人判定选手的回答正确时,按下add键进行加分操作 else if(stu|inputEn)&(score1!=0) score1=score1-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score1=0; score=score1;/把第一组的分数赋值给分数寄存器 end if(answer =3d2)/第二组加减分 begin Led1=6b1

21、11101;Led2=8ha4; if(add) score2=score2+1;/当主持人判定选手的回答正确时,按下add键进行加分操作 else if(stu|inputEn)&(score2!=0) score2=score2-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score2=0; score=score2;/把第一组的分数赋值给分数寄存器 end if(answer =3d3)/第三组加减分 begin Led1=6b111011;Led2=8hb0; if(add) score3=score3+1;/当主持人判定选手的回答正确时,按下add键进行加

22、分操作 else if(stu|inputEn)&(score3!=0) score3=score3-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score3=0; score=score3;/把第一组的分数赋值给分数寄存器 end if(answer =3d4)/第四组加减分 begin Led1=6b110111;Led2=8h99; if(add)传播优秀Word版文档 ,希望对您有帮助,可双击去除! score4=score4+1;/当主持人判定选手的回答正确时,按下add键进行加分操作 else if(stu|inputEn)&(score4!=0) sc

23、ore4=score4-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score4=0; score=score4;/把第一组的分数赋值给分数寄存器 end if(answer =3d5)/第五组加减分 begin Led1=6b101111;Led2=8h92; if(add) score5=score5+1;/当主持人判定选手的回答正确时,按下add键进行加分操作 else if(stu|inputEn)&(score5!=0) score5=score5-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score5=0; score=sc

24、ore5;/把第一组的分数赋值给分数寄存器 end if(answer =3d6)/第六组加减分 begin Led1=6b011111;Led2=8h82; if(add) score6=score6+1;/当主持人判定选手的回答正确时,按下add键进行加分操作 else if(stu|inputEn)&(score6!=0) score6=score6-1;/当主持人判定选手的回答错误时,按下stu键进行加分操作 else score6=0; score=score6;/把第一组的分数赋值给分数寄存器 end begin case(score)/? 4d0:Led3=8hc0;4d1:Le

25、d3=8hf9;4d2:Led3=8ha4; 4d3:Led3=8hb0;4d4:Led3=8h99;4d5:Led3=8h92; 4d6:Led3=8h82;4d7:Led3=8hf8;4d8:Led3=8h80; 4d9:Led3=8h90;default:Led3=8hff; endcase end end end if(clr)/按下clr键以后各组参数重置,整个比赛重新开始 begin传播优秀Word版文档 ,希望对您有帮助,可双击去除! EnFlat=1b1; daojishi=5d20; Led1=6b111111;/重置时六个Led全灭 Led2=8b11111111;/熄灭选

26、手号静态数码管 Led3=8b11111111;/熄灭分数显示数码管 BuClk=1b0;/蜂鸣器标志位重置 Buzzer=1b1;/蜂鸣器控制管脚重置 score=0; /score1=4d0;score2=4d0;score3=4d0; /score4=4d0;score5=4d0;score6=4d0; answer=3d0; endendendmodule测试程序timescale 1s/1smodule qiangdaqi_test(); reg clk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,input

27、L6; /reg clr;/重置键 /reg add,stu;/add答题正确加一分stu答题错误减一分 wire 0:5Led1;/对应参赛选手前的灯 wire 0:7Led2,Led3;/Led2显示选手号Led3显示选手分数 wire Buzzer;/低电平时蜂鸣器发出声音 QiangDaQi u1(clk,clr,add,stu,inputEn,inputL1,inputL2,inputL3,inputL4,inputL5,inputL6,Led1,Led2,Led3,Buzzer); initial begin #0 clk=1;add=0;stu=0;clr=0;inputEn=1

28、;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 inputEn=0;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inputL5=1;inputL6=1;add=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0; #2 inputEn=0;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inp

29、utL5=1;inputL6=1;add=1; #1 inputL3=0;add=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0;传播优秀Word版文档 ,希望对您有帮助,可双击去除! #2 inputEn=1;inputL1=1;inputL2=0;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;in

30、putL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0; #2 inputEn=0;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #40 inputEn=0;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0;

31、#2 inputEn=0;inputL1=0;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;add=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0; #2 inputEn=0;inputL1=0;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1;stu=1; #2 clr=1;add=0;stu=0;inputEn=1;inputL1=1;inputL2=1;inputL3=1;inputL4=1;inputL5=1;inputL6=1; #2 clr=0; end always #1 clk=clk;endmodule

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1