⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 count_dn.vhd

📁 四路抢答器
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity count_dn is
  port(clk,rst,en,stop:in std_logic;--stop由反馈信号BACK
            warn20:buffer std_logic;--倒计时警告信号
         cnt_one:buffer std_logic_vector(3 downto 0);--倒计时个位
         cnt_ten:buffer std_logic_vector(3 downto 0));--倒计时十位
end count_dn;
architecture one of count_dn is
signal cout,tmp:std_logic;--警告信号,count进位
signal score:std_logic_vector(3 downto 0);--计数
begin
p1:process(clk,rst,en,stop,cnt_one)--个位倒计时
    begin
      if rst='1' then
         cnt_one<="0000";
      elsif stop='0' then
          cnt_one<="0000";
     
      elsif clk'event and clk='1' then
         cout<='0';
         if en='1'  then
           cnt_one<=cnt_one-1;
         if cnt_one="0000" then
              if cnt_ten="0000" then cnt_one<="0000";
              else cnt_one<="1001";cout<='1';
              end if;
         end if;
     end if;
    end if;
 end process p1;
p2:process(cout,rst,en,stop,cnt_ten)--十位倒计时
   begin
     if rst='1' then
       cnt_ten<="0010";
     elsif stop='0' then
       cnt_ten<="0010";
     elsif cout'event and cout='1' then
        if en='1'  then
            if cnt_ten="0000" then
               cnt_ten<="0000";   
        else  cnt_ten<=cnt_ten-1;
          end if;
        end if;
     end if;
   end process p2;
p3:process(rst,cout,cnt_one,cnt_ten,stop)--计时超时警告
   begin
   if rst='1' then score<="0000";tmp<='0';
     elsif clk'event and clk='1' then 
       if stop='1' and cnt_one="0000" and cnt_ten="0000" then 
        if score<"1010" then tmp<=not tmp;score<=score+1;
       else tmp<='0';
       end if;
       end if;
       end if;
 end process p3;
warn20<=tmp;
end one;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -