我真的很蠢 发表于 2012-1-4 22:20:35

大神们能帮我改下这个跑马灯的程序吗?老实说我这样写太烦了。

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;
谢谢大神指教!!

linzhjbtx 发表于 2012-1-5 15:16:10

请加注释!!!

apolloj 发表于 2012-1-5 16:34:45

为什么要写的这么复杂啊?

白开水的噩梦 发表于 2012-1-5 22:16:07

为什么要写的这么复杂啊?

白开水的噩梦 发表于 2012-1-5 22:16:09

为什么要写的这么复杂啊?

xkx 发表于 2012-5-28 09:51:00

用3-8译码器可以完成8位led跑马灯啊

@HDL现场 发表于 2012-5-30 23:28:54

跑马灯,不应该写得如此冗余吧。可以另外参考一些例程。
我本身学VERILOG HDL的,VHDL看得懂,不便于帮你修改了。

yshldq 发表于 2012-6-14 23:25:42

本帖最后由 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]
查看完整版本: 大神们能帮我改下这个跑马灯的程序吗?老实说我这样写太烦了。