📄 keyboard4_4.vhd
字号:
--******************************************************************
--* 4x4标准键盘板读取并点亮开发板上相应led
--* Filename: keyboard4_4
--* 扫描键盘,译码并点亮开发板上相应led
--* 尚未仔细考虑一些细节问题,譬如防颤等
--******************************************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_unsigned.all;
entity keyboard4_4 is
port(
rst : in std_logic;
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)
);
end keyboard4_4;
architecture keyboard4_4_arch of keyboard4_4 is
signal clkfrq : std_logic;
signal cntscn : std_logic_vector(1 downto 0);
signal scnlin : std_logic_vector(3 downto 0);
--signal cntfrq : std_logic_vector(14 downto 0);
signal cntfrq : std_logic_vector(3 downto 0);
signal lednum : std_logic_vector(7 downto 0);
begin
process(rst,clk) -- 晶振为50MHz,进行25000分频产生扫描时钟(1000Hz)
begin
if rst = '0' then
clkfrq <= '0';
cntfrq <= (others => '0');
elsif clk'event and clk = '1' then
-- if cntfrq = "110000110101000" then
if cntfrq = "1111" then
cntfrq <= (others => '0');
clkfrq <= not clkfrq;
else
cntfrq <= cntfrq + 1;
end if;
end if;
end process;
process(rst,clkfrq) -- 根据扫描时钟产生扫描线
begin
if rst = '0' then
cntscn <= "00";
elsif clkfrq'event and clkfrq = '1' then
if cntscn = "11" then
cntscn <= "00";
else
cntscn <= cntscn+1;
end if;
case cntscn is
when "00" => scnlin <= "0001";
when "01" => scnlin <= "0010";
when "10" => scnlin <= "0100";
when "11" => scnlin <= "1000";
when others => null;
end case;
end if;
end process;
process(rst, clkfrq) -- 根据按键点亮相应的leds
begin
if(rst = '0' ) then
leds <= "1111";
elsif clkfrq'event and clkfrq = '0' then
case lednum is
when "00010001" =>
leds <= "0000";
when "00010010" =>
leds <= "0001";
when "00010100" =>
leds <= "0010";
when "00011000" =>
leds <= "0011";
when "00100001" =>
leds <= "0100";
when "00100010" =>
leds <= "0101";
when "00100100" =>
leds <= "0110";
when "00101000" =>
leds <= "0111";
when "01000001" =>
leds <= "1000";
when "01000010" =>
leds <= "1001";
when "01000100" =>
leds <= "1010";
when "01001000" =>
leds <= "1011";
when "10000001" =>
leds <= "1100";
when "10000010" =>
leds <= "1101";
when "10000100" =>
leds <= "1110";
when "10001000" =>
leds <= "1111";
when others => null;
end case;
end if;
end process;
scan <= scnlin;
lednum <= scnlin&keyin;
end keyboard4_4_arch;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -