?? myled4.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------------------------------
entity myled4 is
port(clk:in std_logic; --工作時鐘
p:out std_logic_vector(3 downto 0); --四個動態數碼管
key:in std_logic_vector(3 downto 1); --4*4鍵盤s1,s2,s3三個按鍵
y:out std_logic_vector(6 downto 0));
end myled4;
--------------------------------------------------------------------------
architecture bhv of myled4 is
signal a,b,c,d:integer range 0 to 9; --秒個位,秒十位,分個位,分十位
signal count_en,stop_en,clear_en:bit; --計數使能對應按鍵s2,停止使能對應按鍵s1,清零使能對應按鍵s3
begin
---------------------------------------------------------------------------
a1:process(clk,count_en)
variable t:integer range 0 to 4000; --1秒計數一次
begin
if clk'event and clk='1' then
if count_en='1' then
if t<4000 then
t:=t+1;
else t:=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;
if a=9 and b=5 and c=9 and d=5 then
a<=0;b<=0;c<=0;d<=0;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
end process;
------------------------------------------------------------------------------------
a2:process(clk,a,b,c,d,count_en,stop_en)
variable n:integer range 0 to 100;
begin
if clk'event and clk='1' then
if count_en='1' or stop_en='1' then
n:=n+1;
if n=1 then
p<="1110";
if a=0 then y<="0111111"; --7段數碼管顯示數字
elsif a=1 then y<="0000110";
elsif a=2 then y<="1011011";
elsif a=3 then y<="1001111";
elsif a=4 then y<="1100110";
elsif a=5 then y<="1101101";
elsif a=6 then y<="1111101";
elsif a=7 then y<="0000111";
elsif a=8 then y<="1111111";
elsif a=9 then y<="1101111";
end if;
elsif n=2 then
p<="1101";
if b=0 then y<="0111111";
elsif b=1 then y<="0000110";
elsif b=2 then y<="1011011";
elsif b=3 then y<="1001111";
elsif b=4 then y<="1100110";
elsif b=5 then y<="1101101";
end if;
elsif n=3 then
p<="1011";
if c=0 then y<="0111111";
elsif c=1 then y<="0000110";
elsif c=2 then y<="1011011";
elsif c=3 then y<="1001111";
elsif c=4 then y<="1100110";
elsif c=5 then y<="1101101";
elsif c=6 then y<="1111101";
elsif c=7 then y<="0000111";
elsif c=8 then y<="1111111";
elsif c=9 then y<="1101111";
end if;
elsif n=4 then
p<="0111";
if d=0 then y<="0111111";
elsif d=1 then y<="0000110";
elsif d=2 then y<="1011011";
elsif d=3 then y<="1001111";
elsif d=4 then y<="1100110";
elsif d=5 then y<="1101101";
end if;
elsif n=5 then
n:=0;
else
null;
end if;
elsif clear_en='1' then
p<="0000";
y<="0111111";
end if;
end if;
end process;
-----------------------------------------------------------------------------------
p3:process(key,clk)
variable c:integer range 0 to 12;
begin
if key="1111" then
c:=12;
elsif clk'event and clk='1' and clk'last_value='0' then
if c/=0 then
c:=c-1;
end if;
end if;
if c=0 then
if clk'event and clk='1' and clk'last_value='0' then
if key ="011" then
count_en<='0';
stop_en<='0';
clear_en<='1';
elsif key="110" then
count_en<='0';
stop_en<='1';
clear_en<='0';
elsif key="101" then
count_en<='1';
stop_en<='0';
clear_en<='0';
else null;
end if;
end if;
end if;
end process;
-------------------------------------------------------------------------------------
end bhv;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -