集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2953|回复: 7

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

[复制链接]
我真的很蠢 发表于 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 : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           q1 : out  STD_LOGIC;
           q2 : out  STD_LOGIC;
           q3 : out  STD_LOGIC;
           q4 : out  STD_LOGIC;
           q5 : out  STD_LOGIC;
           q6 : out  STD_LOGIC;
           q7 : out  STD_LOGIC;
           q8 : out  STD_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现场 该用户已被删除
@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 [7:0]date_out;

reg [7:0]date_out;
always@(posedge clk or negedge nreset)begin
    if(!nreset)begin
        date_out<=8'h0a;
    end
    else begin
         date_out[7:1] <=date_out[6:0];
         date_out[0] <=date_out[7];
    end
end
endmodule

临时起意写出来的,理想跑出来的效果是:8位灯上有2个间隔的灯始终是亮着,并循环移动,用quartus仿真结果如图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?我要注册

x
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-26 02:11 , Processed in 0.071855 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表