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

📄 keyboard4_4.vhd

📁 基于CPLD的4X4键盘输入+液晶显示程序
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity keyboard4_4 is
    port(
        clk        :    in    std_logic;
		keyin    :    in    std_logic_vector(3 downto 0);
        scan    :    out    std_logic_vector(3 downto 0);
        leds    :    out    std_logic_vector(3 downto 0);
		keypress: 		out 	  std_logic);
end keyboard4_4;

architecture keyboard4_4_arch of keyboard4_4 is
    signal cntscn    :    std_logic_vector(2 downto 0);
    signal scnlin    :    std_logic_vector(3 downto 0);
    signal lednum    :    std_logic_vector(7 downto 0);
	signal count1	 :	  integer range 0 to 15;
	signal count2	 :	  integer range 0 to 255;
	signal haskey,hold		:	  std_logic;
BEGIN
  PROCESS(clk)    -- 根据扫描时钟产生扫描线    
    begin
        if CLK'event and CLK = '1' then
            if cntscn = "100" then
                cntscn <= "000";
            else
                cntscn <= cntscn+1;
            end if;
            case cntscn is
				when "000" => scnlin <= "1110";
                when "001" => scnlin <= "1101";
                when "010" => scnlin <= "1011";
                when "011" => scnlin <= "0111";
				when "100" => scnlin <= "0000";
                when others => null;
            end case;
        end if;        
    end process;            
    
    process(CLK) -- 根据按键点亮相应的leds
    begin
        if CLK'event and CLK = '1' then
			case lednum is
                when "11010111" =>	 leds <= "0000";
                when "11101110" =>   leds <= "0001";
                when "11011110" =>   leds <= "0010";
                when "10111110" =>   leds <= "0011";
                when "11101101" =>   leds <= "0100";
                when "11011101" =>   leds <= "0101";
                when "10111101" =>   leds <= "0110";
                when "11101011" =>   leds <= "0111";                              
                when "11011011" =>   leds <= "1000";
                when "10111011" =>   leds <= "1001";
                when "01111110" =>   leds <= "1010"; --a
                when "01111101" =>   leds <= "1011"; --b
                when "01111011" =>   leds <= "1100"; --c
                when "01110111" =>   leds <= "1101"; --d
                when "10110111" =>	 leds <= "1110"; --#
				when "11100111" =>   leds <= "1111"; --*
                when others =>  		null;
			 end case;
        end if;
    end process;

					 
  	process(CLK)
	begin
		if CLK'event and CLK = '1' then
		
			if scnlin="0000" then
				if keyin/="1111" then
					if count1=10 then
						haskey<='1';
						count1<=0;
					else 
						count1<=count1+1;
					end if;
				else haskey<='0';
				end if;
			end if;
						
			if haskey='1' then
				if hold='0' and count2=10 then
					keypress<='1';
					hold<='1';
					count2<=0;
				else
					if hold='1' and count2=250 then
						 keypress<='1';
							count2<=0;
					else
						count2<=count2 +1;
						keypress<='0';
					end if;
				end if;
			else hold<='0';
				 count2<=0;
			end if;
			
		end if;
	end process;
	
	scan<=scnlin;
	lednum <= scnlin&keyin;
		    
end keyboard4_4_arch;
    

⌨️ 快捷键说明

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