数字式竞赛抢答器VHDL优选Word下载.docx
《数字式竞赛抢答器VHDL优选Word下载.docx》由会员分享,可在线阅读,更多相关《数字式竞赛抢答器VHDL优选Word下载.docx(17页珍藏版)》请在冰豆网上搜索。
信号鉴别模块、计时模块、计分模块、BCD译码模块、分频器,还有顶层模块。
信号鉴别模块。
此模块主要实现抢答器的抢答功能,并能够分辨是正常抢答还是提前抢答,选取最先按下的一路信号,锁存其余信号,实现信号选取功能。
在此模块中,用到的信号为抢答信号a、b、c、d;
抢答使能信号en;
抢答结果信号states;
警报时钟信号clk2;
复位信号
rst;
提前抢答信号fangui。
计时模块。
此模块主要实现抢答过程中的计时功能,在抢答开始后进行30秒的倒计时,且在30秒后显示无人抢答报警信号。
其中有抢答时钟信号clk;
系统复位信号rst;
无人抢答警报信号warn;
计时中止信号stop;
计时十位个位信号tb,ta。
计分模块。
此模块主要实现给四个抢答器计分的功能,初始条件下,为每个抢答器信号预制5分,当某组抢答且回答正确时加一分,答错减一分,未获答题机会时保持不变。
其中设有时钟信号clk;
复位信号rst;
抢答结果显示信号states;
记分加减信号add(add=‘1’时为加,add=‘0’时为减);
四个信号的得分显示信号a_out,b_out,c_out,d_out。
BCD译码模块。
此模块主要实现将抢答结果信号显示在bcd七段译码器上。
其中输入信号a;
输出译码结果信号q。
分频器。
此模块主要实现时钟分频功能。
在开头对时钟信号进行一次千分频。
其中时钟输入信号clkin,输出信号clk。
顶层模块。
将前几个模块综合在一起,形成一个整体。
分频器输出作为其他模块所需的时钟信号,使整个系统正常运转。
二、程序源代码及说明
抢答信号鉴别模块的程序:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityqdjbis
port(clk2,en,rst:
instd_logic;
a,b,c,d:
fangui:
outstd_logic;
states:
outstd_logic_vector(3downto0));
endqdjb;
architectureoneofqdjbis
signalsinor,fanguif,tmp:
std_logic;
signalcnt:
std_logic_vector(5downto0);
begin
sinor<
=aorborcord;
p1:
process(a,rst,b,c,d,tmp)
begin
ifrst='
1'
then--复位信号有效,系统复位。
tmp<
='
;
states<
="
0000"
elsiftmp='
then
ifa='
then--判断哪路信号变化,进行选取
states<
0001"
tmp<
0'
--对states进行置数
elsifb='
0010"
elsifc='
0011"
elsifd='
0100"
elsetmp<
endif;
endif;
endprocessp1;
p2:
process(clk2,en,rst,cnt)--判断是否提前抢答并报警
cnt<
000000"
fanguif<
--初始化提前抢答犯规信号
elsifclk2'
eventandclk2='
ifen='
andsinor='
ifcnt<
"
111111"
fanguif<
=notfanguif;
cnt<
=cnt+1;
elsefanguif<
endprocessp2;
fangui<
=fanguif;
endone;
计时模块的程序:
entityjsis
port(clk,rst,en,stop:
warn:
bufferstd_logic;
ta,tb:
bufferstd_logic_vector(3downto0));
endjs;
architectureoneofjsis
signalco:
process(clk,rst,en,stop,ta)--个位计时信号进行0到9循环计数
orstop='
ta<
elsifclk'
eventandclk='
co<
ifta="
1001"
co<
elseta<
=ta-1;
process(co,rst,en,stop,tb)--十位计时信号0到3变化
tb<
elsifco'
eventandco='
iftb="
thentb<
elsetb<
=tb-1;
p3:
process(rst,ta,tb)--计时时间到达,报警
warn<
elsifta="
andtb="
elsewarn<
endprocessp3;
计分模块的程序:
entityjfis
port(clk,rst,en,add:
instd_logic_vector(3downto0);
a_out,b_out,c_out,d_out:
endjf;
architectureoneofjfis
process(clk,rst,add,states,a_out,b_out,c_out,d_out)
if(rst='
)then
a_out<
0101"
b_out<
c_out<
d_out<
--初始化置5分
elsifen='
then
ifclk'
casestatesis
when"
=>
ifadd='
then--add信号为高时,加1分
ifa_out="
1111"
then--最多15分
a_out<
elsea_out<
=a_out+1;
endif;
elsifadd='
then--add信号为0,减1分
=a_out-1;
ifb_out="
b_out<
elseb_out<
=b_out+1;
=b_out-1;
ifc_out="
c_out<
elsec_out<
=c_out+1;
=c_out-1;
ifd_out="
d_out<
elsed_out<
=d_out+1;
=d_out-1;
whenothers=>
=a_out;
=b_out;
=c_out;
=d_out;
endcase;
抢答器顶层模块程序:
entityqiangdais
port(clkin,clk2,en,a,b,c,d,add,stop,rst:
fangui,alarm:
bufferstd_logic_vector(3downto0);
statesout:
outstd_logic_vector(0