大神们能帮我改下这个跑马灯的程序吗?老实说我这样写太烦了。
library IEEE;use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity liushui is
Port ( clk : inSTD_LOGIC;
rst : inSTD_LOGIC;
q1 : outSTD_LOGIC;
q2 : outSTD_LOGIC;
q3 : outSTD_LOGIC;
q4 : outSTD_LOGIC;
q5 : outSTD_LOGIC;
q6 : outSTD_LOGIC;
q7 : outSTD_LOGIC;
q8 : outSTD_LOGIC);
end liushui;
architecture Behavioral of liushui is
signal q11,q22,q33,q44,q55,q66,q77,q88:std_logic;
signal k: integer range 0 to integer'high;
signal m:integer range 0 to 7;
signal n: integer range 0 to 2;
begin
q1<=q11;
q2<=q22;
q3<=q33;
q4<=q44;
q5<=q55;
q6<=q66;
q7<=q77;
q8<=q88;
process(clk,rst)
begin
if rst='1' then
q11<='0';
q22<='0';
q33<='0';
q44<='0';
q55<='0';
q66<='0';
q77<='0';
q88<='0';
k<=0;
m<=0;
n<=0;
elsif clk'event and clk='1' then
k<=k+1;
if k=12000000 then
if m=7 then
if n=2 then
n<=0;
else
n<=n+1;
m<=0;
end if;
else
m<=m+1;
end if;
k<=0;
end if;
if n=0 then
if m=0 then
q88<='0';
q11<='1';
elsif m=1 then
q11<='0';
q22<='1';
elsif m=2 then
q22<='0';
q33<='1';
elsif m=3 then
q33<='0';
q44<='1';
elsif m=4then
q44<='0';
q55<='1';
elsif m=5 then
q55<='0';
q66<='1';
elsif m=6 then
q66<='0';
q77<='1';
elsif m=7 then
q77<='0';
q88<='1';
end if ;
end if;
if n=1 then
if m=0 then
q77<='0';
q88<='0';
q11<='1';
q22<='1';
elsif m=1 then
q11<='0';
q22<='0';
q33<='1';
q44<='1';
elsif m=2 then
q33<='0';
q44<='0';
q55<='1';
q66<='1';
elsif m=3 then
q55<='0';
q66<='0';
q77<='1';
q88<='1';
elsif m=4 then
q66<='0';
q88<='0';
q11<='1';
q33<='1';
elsif m=5 then
q11<='0';
q33<='0';
q22<='1';
q44<='1';
elsif m=6 then
q22<='0';
q44<='0';
q55<='1';
q77<='1';
elsif m=7 then
q55<='0';
q77<='0';
q66<='1';
q88<='1';
end if;
end if;
if n=2 then
if m=0 then
q11<='0';
q88<='0';
q44<='1';
q55<='1';
elsif m=1 then
q44<='0';
q55<='0';
q33<='1';
q66<='1';
elsif m=2 then
q33<='0';
q66<='0';
q22<='1';
q77<='1';
elsif m=3 then
q22<='0';
q77<='0';
q11<='1';
q88<='1';
elsif m=4 then
q11<='1';
q33<='1';
q55<='1';
q77<='1';
q22<='0';
q44<='0';
q66<='0';
q88<='0';
elsif m=5 then
q11<='0';
q33<='0';
q55<='0';
q77<='0';
q22<='1';
q44<='1';
q66<='1';
q88<='1';
elsif m=6 then
q11<='0';
q33<='0';
q55<='1';
q77<='1';
q22<='0';
q44<='0';
q66<='1';
q88<='1';
elsif m=7 then
q11<='1';
q33<='1';
q55<='0';
q77<='0';
q22<='1';
q44<='1';
q66<='0';
q88<='0';
end if;
end if;
end if;
end process;
end Behavioral;
谢谢大神指教!! 请加注释!!! 为什么要写的这么复杂啊? 为什么要写的这么复杂啊? 为什么要写的这么复杂啊? 用3-8译码器可以完成8位led跑马灯啊 跑马灯,不应该写得如此冗余吧。可以另外参考一些例程。
我本身学VERILOG HDL的,VHDL看得懂,不便于帮你修改了。 本帖最后由 yshldq 于 2012-6-14 23:38 编辑
不知道跑马灯具体怎么跑的,给你一个大体的程序看看吧,用Verilog,VHDL写起太麻烦了
module liushui (
clk,
nreset,
date_out
);
input clk,nreset;
output date_out;
reg date_out;
always@(posedge clk or negedge nreset)begin
if(!nreset)begin
date_out<=8'h0a;
end
else begin
date_out <=date_out;
date_out <=date_out;
end
end
endmodule
临时起意写出来的,理想跑出来的效果是:8位灯上有2个间隔的灯始终是亮着,并循环移动,用quartus仿真结果如图
页:
[1]