?? program.txt
字號:
liberary ieee;
use ieee.std_logic_1164.all;
entity contraler is
port( clock:in std_logic;
light1,light2,light3,pause:out std_logic;
contral:out std_logic;
pause:in std_logic;
run,start:in std_logic;
led7:out std_logic_vector(6 downto 0));
end;
architecture behave of contraler is
signal clk:std_logic;
signal cnt3:std_logic_vector(2 downto 0);
signal cnt4:std_logic_vector(3 downto 0);
begin
runp:process(run)--單鍵設置所運行程序,分五種狀態
begin
if run'event and run ='1' then cnt3:=cnt3+1;
end if;
if cnt3="101" then cnt3:="000";
end if;
end process runp;
start:process(start)--按下開始鍵開始計數
begin
if start'event and start='1' then clk<=clock;pause<="0";
end if;
end process start;
timecontral:process(cnt3)--把五種狀態轉化為運行時間,控制指示燈跳轉
begin
case cnt3 is
when "000"=> cnt3t<="010";cnt4 <="0000";light1<="1";
when "001"=> cnt3t<="001";cnt4 <="0101";light2<="1";
when "010"=> cnt3t<="001";cnt4 <="0000";light3<="1";
when "011"=> cnt3t<="011";cnt4 <="0000";light1<="1";light3<="1";
when "100"=> cnt3t<="100";cnt4 <="0101";light1<="1";light2<="1";light3<="1";
when others=> null;
end case;
end process timecontral;
timer:process(clk)--把6M時鐘65536分頻,兩個數碼管控制為十進制計數
variable cnt8:std_logic_vector(15 downto 0);
begin
if clk'event and clk='1' then
if cnt8="1111111111111111" then--65536分頻
cnt8:="0000000000000000";
if cnt4="0000" then cnt4:="1000";--個位計數
if cnt3t="000" then pause<="1";--程序運行完畢,暫停指示
else cnt3t:=cnt3t-1;--十位計數
end if;
else cnt4:=cnt4-1;
end if;
else cnt8:=cnt8+1;
end if;
end if;
end process timer;
clockshow:process(cnt3,cnt4)--數碼管顯示
begin
case cnt3 is--十位顯示
when "000"=> led7 <="0111111";
when "001"=> led7 <="0000110";
when "010"=> led7 <="1011011";
when "011"=> led7 <="1001111";
when "100"=> led7 <="1100110";
when others=> null;
end case;
case cnt4 is--個位顯示
when "0000"=> led7 <="0111111";
when "0001"=> led7 <="0000110";
when "0010"=> led7 <="1011011";
when "0011"=> led7 <="1001111";
when "0100"=> led7 <="1100110";
when "0101"=> led7 <="1101101";
when "0110"=> led7 <="1111101";
when "0111"=> led7 <="0000111";
when "1000"=> led7 <="1111111";
when "1001"=> led7 <="1101111";
when others=> null;
end case;
end process;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -