六人抢答器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一课程设计题目
六人抢答器
二实现的功能
1、抢答器同时供六名选手比赛,抢答按钮分别为P1,P2,P3,P4,P5,P6
2、test状态检测抢答装置是否正常。
3、在start状态下,最快按下按钮的选手抢答成功,且绿灯亮,至本轮结束。
4、在读题时,即prepare状态,按下抢答键视为犯规,红灯亮,取消本轮抢
答机会。
5、主持人可以设置抢答时间,当系统鉴定出第一抢答后,自动开始倒计时,
倒计时完后发出响声。
若在规定时间内回答,由主持人按使能开关,停
止倒计时。
6、抢答器具有预置分和手动加分功能。
7、系统能显示分数和时间。
三系统结构框图
P1P2P3P4P5P6控制
三程序流程1、抢答模块
2、时间模块
3、记分模块
4、显示模块
四模块连接
五程序设计
1.程序代码:
抢答模块:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity qiangdasix is
port(test:in std_logic; --测试
prepare:in std_logic; --读题
start:in std_logic; --开始抢答
p1:in std_logic; --抢答按钮
p2:in std_logic;
p3:in std_logic;
p4:in std_logic;
p5:in std_logic;
p6:in std_logic;
result:out std_logic_vector(3 downto 0); --抢答结果
led1_green:out std_logic; --绿灯,抢答成功
led2_green:out std_logic;
led3_green:out std_logic;
led4_green:out std_logic;
led5_green:out std_logic;
led6_green:out std_logic;
led1_red:out std_logic; --红灯犯规
led2_red:out std_logic;
led3_red:out std_logic;
led4_red:out std_logic;
led5_red:out std_logic;
led6_red:out std_logic;
over:out std_logic); --抢答结束
end qiangdasix;
architecture behav of qiangdasix is
signal stop:std_logic:='0';
signal tled1_green:std_logic:='0'; --用于测试
signal tled2_green:std_logic:='0';
signal tled3_green:std_logic:='0';
signal tled4_green:std_logic:='0';
signal tled5_green:std_logic:='0';
signal tled6_green:std_logic:='0';
signal qled1_green:std_logic:='0';
signal qled2_green:std_logic:='0'; --用于抢答
signal qled3_green:std_logic:='0';
signal qled4_green:std_logic:='0';
signal qled5_green:std_logic:='0';
signal qled6_green:std_logic:='0';
signal qualify1:std_logic:='0'; --犯规标志
signal qualify2:std_logic:='0';
signal qualify3:std_logic:='0';
signal qualify4:std_logic:='0';
signal qualify5:std_logic:='0';
signal qualify6:std_logic:='0';
signal sell:std_logic_vector(5 downto 0);
begin
check:process(test,start,prepare,p1,p2,p3,p4,p5,p6)
begin
if prepare='1'then --测试数据初始化
tled1_green<='0';tled2_green<='0';tled3_green<='0';tled4_green<='0'; tled5_green<='0';tled6_green<='0';
elsif test='1'and start='0'then --测试
if p1='1' then tled1_green<='1';end if; --检查抢答按键
if p2='1' then tled2_green<='1';end if;
if p3='1' then tled3_green<='1';end if;
if p4='1' then tled4_green<='1';end if;
if p5='1' then tled5_green<='1';end if;
if p6='1' then tled6_green<='1';end if;
end if;
end process check;
qiang:process(start,test,prepare,p1,p2,p3,stop,qualify1,qualify2,qualify3) begin
if(prepare='1')then
stop<='0';qualify1<='0';qualify2<='0';qualify3<='0';qualify4<='0'; qualify5<='0';qualify6<='0';qled1_green<='0';qled2_green<='0';
qled3_green<='0';qled4_green<='0';qled5_green<='0';qled6_green<='0'; led1_red<='0';led2_red<='0';led3_red<='0';
led4_red<='0';led5_red<='0';led6_red<='0'; --数据初始化elsif(start='0'and test='0')then --还未开始抢答,按下按键犯规if(p1='1')then qualify1<='1';led1_red<='1';end if;
if(p2='1')then qualify2<='1';led2_red<='1';end if;
if(p3='1')then qualify3<='1';led3_red<='1';end if;
if(p4='1')then qualify4<='1';led4_red<='1';end if;
if(p5='1')then qualify5<='1';led5_red<='1';end if;
if(p6='1')then qualify6<='1';led6_red<='1';end if;
elsif(stop='0'and test='0'and start='1') the--开始抢答,没犯规且按
--下按键,抢答成功if (p1='1'and qualify1='0') then qled1_green<='1';end if;
if (p2='1'and qualify2='0') then qled2_green<='1';end if;
if (p3='1'and qualify3='0') then qled3_green<='1';end if;
if (p4='1'and qualify4='0') then qled4_green<='1';end if;
if (p5='1'and qualify5='0') then qled5_green<='1';end if;
if (p6='1'and qualify6='0') then qled6_green<='1';end if;
if(qled1_green<='0'and qled2_green<='0'and qled3_green<='0'and qled4_green<='0'and qled5_green<='0'and qled6_green<='0')then
stop<='0'; --还没有人抢答成功,不关进程
else stop<='1'; --有人抢答成功,不继续扫描按键
end if;
else null;
end if;
over<=stop;
end process qiang;
evaluate:process(tled1_green,tled2_green,tled3_green,tled4_green,tled5_ green,tled6_green,qled1_green,qled2_green,qled3_green,qled4_green,qle d5_green,qled6_green) --绿灯显示
begin
led1_green<=tled1_green or qled1_green;
led2_green<=tled2_green or qled2_green;
led3_green<=tled3_green or qled3_green;
led4_green<=tled4_green or qled4_green;
led5_green<=tled5_green or qled5_green;
led6_green<=tled6_green or qled6_green;
sell<=qled1_green&qled2_green&qled3_green&qled4_green&
qled5_green&qled6_green;
case sell is --输出抢答结果,用于加分模块
when"100000"=>result<="0001";
when"010000"=>result<="0010";
when"001000"=>result<="0011";
when"100100"=>result<="0100";
when"000010"=>result<="0101";
when"000001"=>result<="0110";
when others=> result<="0000";
end case;
end process evaluate;
end behav;
时间模块:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity tim is
port(settime:in std_logic; --时间设置
load:in std_logic; --读入预置数
en:in std_logic; --使能端
clk:in std_logic; --时钟信号
bell:out std_logic; --时间到,蜂鸣器响
q1,q0:out std_logic_vector(3 downto 0));--当前时间输出,用于显示end tim;
architecture art of tim is
signal clk1:bit;
signal q:std_logic_vector(7 downto 0);
signal tim1:std_logic_vector(3 downto 0);
signal tim0:std_logic_vector(3 downto 0);
signal time1:std_logic_vector(3 downto 0);
signal stop:std_logic;
begin
dividefreq:process(clk)
begin
if(clk'event and clk='1') then --该进程用于产生秒信号
q<=q+1;
if q="11111010" then
q<="00000000";clk1<=not clk1;
else null;
end if;
end if;
end process dividefreq;
set:process(settime)
begin
if(settime'event and settime='1') then --时间设置
if time1="1001"then time1<="0000";
else time1<=time1+'1';
end if;
end if;
end process set;
timm:process(clk1,load,en,stop)
begin
if (load='1')then --读入预置时间
tim1<=time1;tim0<="0000";stop<='0';bell<='0';
elsif(clk1'event and clk1='1')then
if stop='0'and en='1' then --开始计时
if tim0="0000"and tim1="0000"then bell<='1';stop<='1';
else
if(tim0="0000")then
tim0<="1001";tim1<=tim1-'1';
else tim0<=tim0-'1';
end if;
end if;
end if;
end if;
end process timm;
q1<=tim1;q0<=tim0;
end art;
计分模块:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity score is
port(set:in std_logic; --分数初始化
add:in std_logic; --加分
chos:in std_logic_vector(3 downto 0); --选择加分的选手
a1,a2,a0:out std_logic_vector(3 downto 0);--寄存分数值
b1,b2,b0:out std_logic_vector(3 downto 0);
c1,c2,c0:out std_logic_vector(3 downto 0);
d1,d2,d0:out std_logic_vector(3 downto 0);
e1,e2,e0:out std_logic_vector(3 downto 0);
f1,f2,f0:out std_logic_vector(3 downto 0));
end score;
architecture art of score is
signal points_a2,points_a1:std_logic_vector(3 downto 0);
signal points_b2,points_b1:std_logic_vector(3 downto 0);
signal points_c2,points_c1:std_logic_vector(3 downto 0);
signal points_d2,points_d1:std_logic_vector(3 downto 0);
signal points_e2,points_e1:std_logic_vector(3 downto 0);
signal points_f2,points_f1:std_logic_vector(3 downto 0);
begin
process(set,add,chos)
begin
if set='1'then --分数初始化
points_a2<="0001";points_a1<="0000";
points_b2<="0001";points_b1<="0000";
points_c2<="0001";points_c1<="0000";
points_d2<="0001";points_d1<="0000";
points_e2<="0001";points_e1<="0000";
points_f2<="0001";points_f1<="0000";
else
if(add'event and add='1')then --对选中的选手加分
if (chos="0001")then
if points_a1="1001"then points_a1<="0000";
if points_a2="1001"then points_a2<="1010";
else points_a2<=points_a2+1;
end if;
else points_a1<=points_a1+'1';
end if;
elsif chos="0010"then
if points_b1="1001"then points_b1<="0000";
if points_b2="1001"then points_b2<="1010";
else points_b2<=points_b2+1;
end if;
else points_b1<=points_b1+'1';
end if;
elsif chos="0011"then
if points_c1="1001"then points_c1<="0000";
if points_c2<="1001"then points_c2<="1010";
else points_c2<=points_c2+1;
end if;
else points_c1<=points_c1+'1';
end if;
elsif chos="0100"then
if points_d1="1001"then points_d1<="0000";
if points_d1="1001"then points_d2<="1010";
else points_d2<=points_d2+1;
end if;
else points_d1<=points_d1+'1';
end if;
elsif chos="0101"then
if points_e1="1001"then points_e1<="0000";
if points_e2="1001"then points_e2<="1010";
else points_e2<=points_e2+1;
end if;
else points_e1<=points_e1+'1';
end if;
elsif chos="0110"then
if points_f1="1001"then points_f1<="0000";
if points_f2="1001"then points_f2<="1010";
else points_f2<=points_f2+1;
end if;
else points_f1<=points_f1+'1';
end if;
end if;
end if;
end if;
end process;
a2<=points_a2;a1<=points_a1;a0<="0000"; --用于显示b2<=points_b2;b1<=points_b1;b0<="0000";
c2<=points_c2;c1<=points_c1;c0<="0000";
d2<=points_d2;d1<=points_d1;d0<="0000";
e2<=points_e2;e1<=points_e1;e0<="0000";
f2<=points_f2;f1<=points_f1;f0<="0000";
end art;
显示模块:
library ieee;
use ieee.std_logic_1164.all;
entity display is --用动态扫描法,扫描时间,分数port(clk:in std_logic; --共14位数
q1,q0:in std_logic_vector(3 downto 0);--时间
a1,a2:in std_logic_vector(3 downto 0);--各选手成绩
b1,b2:in std_logic_vector(3 downto 0);
c1,c2:in std_logic_vector(3 downto 0);
d1,d2:in std_logic_vector(3 downto 0);
e1,e2:in std_logic_vector(3 downto 0);
f1,f2:in std_logic_vector(3 downto 0);
lsd:out bit_vector(13 downto 0);
bcd:out std_logic_vector(3 downto 0));
end display;
architecture behav of display is
type dis_p is array(0 to 13)of std_logic_vector(3 downto 0);
signal dis_p1:dis_p;
signal cnt: integer range 0 to 14;
begin
process(clk,a1,a2,b1,b2,c1,c2,d1,d2,e1,e2,f1,f2,q1,q0)
begin --把要显示的数据装入数组,便于循环dis_p1(0)<=q1;dis_p1(1)<=q0;dis_p1(2)<=a2;dis_p1(3)<=a1;dis_p1(4)< =b2;dis_p1(5)<=b1;dis_p1(6)<=c2;dis_p1(7)<=c1;
dis_p1(8)<=d2;dis_p1(9)<=d1;dis_p1(10)<=e2;dis_p1(11)<=e1;dis_p1(1 2)<=f2;dis_p1(13)<=f1;
if rising_edge(clk)then
case cnt is
when 0=>lsd<="10000000000000";
when 1=>lsd<="01000000000000";
when 2=>lsd<="00100000000000";
when 3=>lsd<="00010000000000";
when 4=>lsd<="00001000000000";
when 5=>lsd<="00000100000000";
when 6=>lsd<="00000010000000";
when 7=>lsd<="00000001000000";
when 8=>lsd<="00000000100000";
when 9=>lsd<="00000000010000";
when 10=>lsd<="00000000001000";
when 11=>lsd<="00000000000100";
when 12=>lsd<="00000000000010";
when 13=>lsd<="00000000000001";
when others=> null;
end case;
bcd<=dis_p1(cnt);
cnt<=cnt+1;
if(cnt=13) then cnt<=0; end if; end if;
end process;
end behav;
3.波形仿真:
①抢答部分的仿真,无人犯规
②抢答部分的仿真,有人犯规
③计时模块仿真(设置30秒)
④计分模块仿真(初始100分,选手2加10分,选手3加20分,选手4加40分,选手5加10分)
⑤显示模块(分别显示q0,q1,a2·····e2,e1,f1,f2的值)。