📄 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 + -