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

📄 keyboard.vhd

📁 VHDL源程序
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity KeyBoard is
  port(
	clk,reset:in std_logic;
	kb0		:inout std_logic;
    getkey	:out std_logic;
	da_a	:in std_logic_vector(7 downto 0);
	keyvalue:out std_logic_vector(3 downto 0));
  end KeyBoard;

  architecture arch of KeyBoard is
    FUNCTION coder(da_a:std_logic_vector(7 downto 0))
				RETURN std_logic_vector IS
    VARIABLE result:std_logic_vector(2 downto 0);
    BEGIN
	   CASE da_a(7 downto 0) IS
		 WHEN "11111110" =>
			result := "000";
		 WHEN "11111101" =>
			result := "001";
		 WHEN "11111011" =>
			result := "010";
		 WHEN "11110111" =>
			result := "011";
		 WHEN "11101111" =>
			result := "100";
		 WHEN "11011111" =>
			result := "101";
		 WHEN "10111111" =>
			result := "110";
		 WHEN OTHERS =>
			result := "111";
	   END CASE;	
	   RETURN result;
    END coder;

	SIGNAL delay:std_logic;

  BEGIN

    read:PROCESS(clk,reset)
	variable second:integer range 0 to 3;
    variable keycode:std_logic_vector(3 downto 0);
    begin
	  if(reset='0') then
	     second := 0;
		 delay <= '0';
		 getkey <= '0';
	  elsif(clk'event and clk='1') then
         if(second /= 0) then
            second := second + 1;
   		 end if;
		 getkey <= delay;
	     if(da_a /= "11111111") then
			if(second = 0) then 
               keycode(2 downto 0) := coder(da_a);
 			   keycode(3) := kb0;
--			   if(keycode < "1010") then
                  second := second + 1;
			      delay <= '0';
			      getkey <= '0';
	--		   end if;
	        else
			   if(keycode(2 downto 0) = coder(da_a)) then
				  if(keycode(3) = kb0) then
					 if(keycode < "1010") then
					    keyvalue <= keycode;
					    delay <= '1';
					 end if;
			        second := 0;
				  end if;
			   end if;   
		    end if;
		 end if;
	  end if;
	end process read;

    scan:PROCESS(clk,reset)
	BEGIN
	   IF(reset = '0') THEN
		  kb0 <= '0';
	   ELSIF(clk'event and clk='0') THEN
		  kb0 <= NOT(kb0);
	   END IF;
    END PROCESS scan;

  END arch;

⌨️ 快捷键说明

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