📄 button.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity button is
port (clk:in bit;
press:in std_logic_vector(3 downto 0);-----------an jian
show:out std_logic_vector(6 downto 0);----------count show
s:out std_logic_vector(3 downto 0));---------select digitron
end entity button;
architecture bhv of button is
signal a,c:integer range 0 to 9;-----------------ge wei
signal b,d:integer range 0 to 5;-----------------shi wei
signal cnt_en,pass:bit;------------------------------count enable
begin
one:process(clk)
variable con:integer range 0 to 200;
begin
if clk'event and clk='1' then
con:=con+1;
if con<100 then
pass<='0';
elsif con<200 then
pass<='1';
else pass<='0';
end if;
end if;
end process;
tow:process(press,clk,pass) ------------------avoid shake
variable m:integer range 0 to 20;
begin
if press="1111" then m:=0;
elsif clk'event and clk'last_value='0' and clk='1'
then m:=m+1;
end if;
if m=20 then
if pass'event and pass'last_value='0' and pass='1' then
if press="1011" then
cnt_en<='1';
elsif press="1101" then
cnt_en<='0';
else null;
end if;
end if;
end if;
end process;
thr:process(clk)-----------------------------------------take count
variable k:integer range 0 to 4000;
begin
if clk'event and clk'last_value='0' and clk='1'
then
if cnt_en='1' then
if k<4000 then k:=k+1;
else k:=0;
if a<9 then a<=a+1;
else a<=0;
if b<5 then b<=b+1;
else b<=0;
if c<9 then c<=c+1;
else c<=0;
if d<5 then d<=d+1;
else d<=0;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end process;
fou:process(clk)----------------------------------------show numble
variable n:integer range 0 to 100;
begin
if clk'event and clk'last_value='0' and clk='1'
then
if cnt_en='1' then
n:=n+1;
if n=1 then
if a=0 then show<="0111111";
elsif a=1 then show<="0000110";
elsif a=2 then show<="1011011";
elsif a=3 then show<="1001111";
elsif a=4 then show<="1100110";
elsif a=5 then show<="1101101";
elsif a=6 then show<="1111101";
elsif a=7 then show<="0000111";
elsif a=8 then show<="1111111";
else show<="1101111";
end if;
s<="1110";
elsif n=2 then
if b=0 then show<="0111111";
elsif b=1 then show<="0000110";
elsif b=2 then show<="1011011";
elsif b=3 then show<="1001111";
elsif b=4 then show<="1100110";
else show<="1101101";
end if;
s<="1101";
elsif n=3 then
if c=0 then show<="0111111";
elsif c=1 then show<="0000110";
elsif c=2 then show<="1011011";
elsif c=3 then show<="1001111";
elsif c=4 then show<="1100110";
elsif c=5 then show<="1101101";
elsif c=6 then show<="1111101";
elsif c=7 then show<="0000111";
elsif c=8 then show<="1111111";
else show<="1101111";
end if;
s<="1011";
elsif n=4 then
if d=0 then show<="0111111";
elsif d=1 then show<="0000110";
elsif d=2 then show<="1011011";
elsif d=3 then show<="1001111";
elsif d=4 then show<="1100110";
else show<="1101101";
end if;
s<="0111";
elsif n=5 then n:=0;
else null;
end if;
end if;
end if;
end process;
end bhv;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -