📄 qiangda8.vhd
字号:
--tmjdone@163.com
--LanZhou University
--05DX
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity QiangDa8 is
generic(Tout:integer:=21);
port (CLK : IN STD_LOGIC;--时钟脉冲,计时用
--
disClk:IN STD_LOGIC;--显示用时钟脉冲
DisLed : out std_logic_vector(6 downto 0);--先使用abcdefg
DisSelect : out std_logic_vector(3 downto 0);--选择数码管用
--以下是测试用管脚
status : buffer std_logic_vector(2 downto 0);--当前状态
CurPlayer:buffer std_logic_vector(3 downto 0);--当前选手
DisPlayer: buffer std_logic_vector(3 downto 0);--显示选手
timeRecord: buffer std_logic_vector(7 downto 0);--2位10进制数,记录当前时间
TimerEnable:buffer std_logic_vector(1 downto 0);--00 清零,01允许计时,10 停止计时
TimeOut: buffer std_logic;--0未超时,1超时
--
Players: in std_logic_vector(7 downto 0);--抢答输入
Start:in std_logic;--开始按钮
Reset:in std_logic--复位按钮
);
end QiangDa8;
architecture art of QiangDa8 is
signal flag: std_logic_vector(1 downto 0);--用于循环选择数码管
signal Disout : std_logic_vector(3 downto 0);--当前数码管显示数据
--signal status : std_logic_vector(2 downto 0);--当前状态
--signal CurPlayer:std_logic_vector(3 downto 0);--当前选手
--signal DisPlayer:std_logic_vector(3 downto 0);--显示选手
--signal timeRecord: std_logic_vector(7 downto 0);--2位10进制数,记录当前时间
--signal ActOK:std_logic_vector(1 downto 0);--01 完成抢答 10--提前抢答
--signal TimerEnable:std_logic_vector(1 downto 0);--00 清零,01允许计时,10 停止计时
--signal TimeOut:std_logic;--0未超时,1超时
begin
process(Players,Reset) is
begin
--000 准备状态:计时器归零, 状态0,选手0
--001 开始状态:计时器计时, 状态1,选手0
--010 完成抢答:计时器显示当前时间,状态2,选手x
--011 超时状态:计时器显示超时时间,状态3,选手0
--100 提前抢答:计时器归零, 状态4,选手x
if(Reset='1') then
CurPlayer<="0000";
else
if(Status="000" or Status="001") then
if Players(0)='1' then CurPlayer<="0001";
elsif Players(1)='1' then CurPlayer<="0010";
elsif Players(2)='1' then CurPlayer<="0011";
elsif Players(3)='1' then CurPlayer<="0100";
elsif Players(4)='1' then CurPlayer<="0101";
elsif Players(5)='1' then CurPlayer<="0110";
elsif Players(6)='1' then CurPlayer<="0111";
elsif Players(7)='1' then CurPlayer<="1000";
end if;
end if;
end if;
end process;
process(CurPlayer,TimeOut,start,Reset) is
begin
if reset='1' then
status<="000";
elsif status/="010" then
if status="000" and start='1' then
status<="001";
elsif status="000" and CurPlayer/="0000" then
status<="100";
elsif status="001" and TimeOut='0' and TimerEnable="01" and CurPlayer/="0000" then
--DisPlayer<=CurPlayer;
status<="010";
elsif status="001" and TimeOut='1' and TimerEnable="01" and CurPlayer="0000" then
status<="011";
-- else
-- if status="000" and CurPlayer/="0000" then
-- status<="100";
-- elsif status="001" and TimeOut='0' then
-- status<="010";
-- elsif status="001" and TimeOut='1' then
-- status<="011";
-- end if;
end if;
end if;
if status="000" then
TimerEnable<="00";
--DisPlayer<="0000";
elsif status="001" then
TimerEnable<="01";
--DisPlayer<="0000";
elsif status="010" then
--DisPlayer<=CurPlayer;
TimerEnable<="10";
elsif status="011" then
TimerEnable<="10";
--DisPlayer<="0000";
elsif status="100" then
--DisPlayer<=CurPlayer;
TimerEnable<="00";
end if;
if status="010" or status="100" then
DisPlayer<=CurPlayer;
else
DisPlayer<="0000";
end if;
end process;
process(CLK) is
begin
if (CLK'EVENT AND CLK='1') THEN
if(TimerEnable="01") then
if(timeRecord>Tout) then
TimeOut<='1';
elsif(timeRecord(3 downto 0)<9) then
timeRecord<=timeRecord+1;--TimeOut<='0';
else
timeRecord<=timeRecord+7;--TimeOut<='0';
end if;
elsif(TimerEnable="00") then
timeRecord<="00000000";TimeOut<='0';
--elsif(TimerEnable="01") then
-- timeRecord<=timeRecord;
end if;
end if;
end process;
process(disCLK) IS
BEGIN
IF (disCLK'EVENT AND disCLK='1') THEN
IF FLAG="00" THEN
DisOut<=DisPlayer;
DisSelect<="1110";
FLAG<="01";
ELSIF FLAG="01" THEN
DisOut<='0'&status;
DisSelect<="1101";
FLAG<="10";
ELSIF FLAG="10" THEN
DisOut<=timeRecord(3 downto 0);
DisSelect<="1011";
FLAG<="11";
ELSE
DisOut<=timeRecord(7 downto 4);
DisSelect<="0111";
FLAG<="00";
END IF;
END IF;
END PROCESS;
PROCESS(DisOut) IS
BEGIN
CASE DisOut IS
WHEN "0000"=>DisLed<="0111111";--显示0
WHEN "0001"=>DisLed<="0000110";--显示1
WHEN "0010"=>DisLed<="1011011";--显示2
WHEN "0011"=>DisLed<="1001111";--显示3
WHEN "0100"=>DisLed<="1100110";--显示4
WHEN "0101"=>DisLed<="1101101";--显示5
WHEN "0110"=>DisLed<="1111101";--显示6
WHEN "0111"=>DisLed<="0000111";--显示7
WHEN "1000"=>DisLed<="1111111";--显示8
WHEN "1001"=>DisLed<="1101111";--显示9
WHEN "1010"=>DisLed<="1110111";--显示A
WHEN "1011"=>DisLed<="1111100";--显示B
WHEN "1100"=>DisLed<="0111001";--显示C
WHEN "1101"=>DisLed<="1011110";--显示D
WHEN "1110"=>DisLed<="1111001";--显示E
WHEN "1111"=>DisLed<="1110001";--显示F
WHEN OTHERS=>DisLed<="0000000";
END CASE;
END PROCESS;
end art;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -