基於VHDL的四路搶答器設計(程序)+注釋
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity carrie is
port
(
CLK:std_logic; --掃描脈衝
host : in std_logic; --主持人信號
answer : in std_logic_vector(3 downto 0); --搶答信號
light : out std_logic_vector(3 downto 0) --指示燈
);
end entity;
architecture rtl of carrie is
signal lock:std_logic; --定義一個‘鎖’信號使得一人搶答後其他人不能再搶答
begin
process (host,answer,CLK)
begin
if(host='0')then -- 主持人清零
light<="0000"; --清零
lock<='0';
elsif (HOST='1')then --主持人置‘1’,開始搶答
IF(LOCK='0') THEN --控製 信號,完成隻能有一路選通
IF(CLK'EVENT AND CLK='1') THEN --脈衝掃描
case answer is
when "1000"=>light<="1000";lock<='1'; --lock 信號使得一人搶答後其他人不能再搶答上
when "0100"=>light<="0100";lock<='1';
when "0010"=>light<="0010";lock<='1';
when "0001"=>light<="0001";lock<='1';
when others=>light<="0000";
end case;
end if;
end if;
end if;
end process;
end rtl;
最後更新:2017-04-03 20:19:07