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

📄 keyboard.txt

📁 多功能秒表:可以顺计时和倒计时的秒表,用三位数码管显示。
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity keyboard is
 port(clk_out:in std_logic;
      keyin:in std_logic_vector(3 downto 0);--键盘输出信号KX3~KX0
      keyout:out std_logic_vector(3 downto 0):="1110";--键盘扫描信号KY3~KY0
      bell2,a,b,c,reset,change,start:out std_logic);
end entity;
architecture behav of keyboard is 
  type state_type is (s0,s1);
  signal pre_state,next_state:state_type:=s0;
  signal reg2:std_logic_vector(7 downto 0);
  signal reg3:std_logic_vector(3 downto 0);
begin
  pro1:process(clk_out)
   begin
    if rising_edge (clk_out) then 
      if keyin="1111" then 
           pre_state<=next_state;
      end if;
    end if;
 end process pro1;
  pro2:process(pre_state,keyin)
   begin
    case pre_state is
     when s0=>reg3<="1110";next_state<=s1;
     when s1=>reg3<="1101";next_state<=s0;
    end case;
 end process pro2;
pro3:process(clk_out,keyin,reg3)
 begin
  if rising_edge(clk_out) then 
     case reg3&keyin is
     when "11101110"=>reg2<="00000001";bell2<='1';--1键,顺时计时
     when "11101101"=>reg2<="00000010";bell2<='1';--2键,倒计时
     when "11101011"=>reg2<="00000011";bell2<='1';--3键,开始计时
     when "11100111"=>reg2<="00000100";bell2<='1';--4键,结束计时
     when "11011110"=>reg2<="00000101";bell2<='1';--5键,控制数码管十位加1
     when "11011101"=>reg2<="00000110";bell2<='1';--6键,控制数码管个位加1
     when "11011011"=>reg2<="00000111";bell2<='1';--7键,控制数码管十分位加1
     when others=>reg2<="00000000";bell2<='0';
     end case;
 end if;
end process pro3;
pro4:process(clk_out,reg2)
    begin
    if rising_edge (clk_out) then 
     if reg2="00000000" then a<='1';b<='1';c<='1';reset<='1';change<='1';start<='0';
     elsif reg2="00000001" then change<='1';start<='0';reset<='0';
     elsif reg2="00000010" then change<='0';start<='0';reset<='0';
     elsif reg2="00000011" then start<='1';
     elsif reg2="00000100" then start<='0';
     elsif reg2="00000101" then c<='0';
     elsif reg2="00000110" then b<='0';
     elsif reg2="00000111" then a<='0';
     end if;
    end if;
end process pro4;
end behav;
      

⌨️ 快捷键说明

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