📄 jp4x4.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity jp4x4 is
port(clk:in std_logic; --扫描时钟信号
start:in std_logic; --开始信号,高电平有效
kbcol:in std_logic_vector(3 downto 0); --行扫描信号
kbrow:out std_logic_vector(3 downto 0); --列扫描信号
seg7_out:out std_logic_vector(6 downto 0) :="1111111"; --7段显示控制信号
scan:out std_logic_vector(3 downto 0)); --数码管地址选择控制信号
end jp4x4;
architecture one of jp4x4 is
signal count:std_logic_vector(1 downto 0);
signal sta:std_logic_vector(1 downto 0);
signal seg7:std_logic_vector(6 downto 0);
signal dat:std_logic_vector(4 downto 0);
signal fn:std_logic; --按键标志位,判断是否有键被按下
begin
scan<="0001"; --只使用一个数码管显示
--循环扫描计数器
process(clk)
begin
if clk'event and clk='1' then count<=count+1;
end if;
end process;
--循环列扫描
process(clk)
begin
if clk'event and clk='1' then
case count is
when "00"=>kbrow<="0001";sta<="00";
when "01"=>kbrow<="0010";sta<="01";
when "10"=>kbrow<="0100";sta<="10";
when "11"=>kbrow<="1000";sta<="11";
when others=>kbrow<="1111";
end case;
end if;
end process;
--行扫描译码
process(clk,start)
begin
if start='0' then seg7<="1111111";dat<="10000"; --全灭
elsif clk'event and clk='1' then
case sta is
when "00"=>
case kbcol is
when "0001"=>seg7<="0110000";dat<="00011"; --3
when "0010"=>seg7<="0100100";dat<="00010"; --2
when "0100"=>seg7<="1111001";dat<="00001"; --1
when "1000"=>seg7<="1000000";dat<="00000"; --0
when others=>seg7<="1111111";dat<="11111";
end case;
when "01"=>
case kbcol is
when "0001"=>seg7<="1111000";dat<="00111"; --7
when "0010"=>seg7<="0000010";dat<="00110"; --6
when "0100"=>seg7<="0010010";dat<="00101"; --5
when "1000"=>seg7<="0011001";dat<="00100"; --4
when others=>seg7<="1111111";dat<="11111";
end case;
when "10"=>
case kbcol is
when "0001"=>seg7<="0000011";dat<="01011"; --b
when "0010"=>seg7<="0001000";dat<="01010"; --a
when "0100"=>seg7<="0010000";dat<="01001"; --9
when "1000"=>seg7<="0000000";dat<="01000"; --8
when others=>seg7<="1111111";dat<="11111";
end case;
when "11"=>
case kbcol is
when "0001"=>seg7<="0001110";dat<="01111"; --f
when "0010"=>seg7<="0000110";dat<="01110"; --e
when "0100"=>seg7<="0100001";dat<="01101"; --d
when "1000"=>seg7<="0100111";dat<="01100"; --c
when others=>seg7<="1111111";dat<="11111";
end case;
when others=>seg7<="1111111";
end case;
end if;
end process;
fn<=not(dat(0) and dat(1) and dat(2) and dat(3) and dat(4));
--产生按键标志位,用于存储按键信息
process(fn)
begin
if fn'event and fn='1' then --按键信息存储
seg7_out<=seg7;
end if;
end process;
end one;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -