用有限状态机(FSM)在BASYS3开发板实现流水灯

一、实验所需环境

1、Basys3开发板;
2、Vivado2017.4开发环境;
3、VHDL硬件描述语言。

二、相关代码

1、代码

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity running_led is
    Port ( clk     : in  STD_LOGIC;
           rst     : in  STD_LOGIC;
           q       : out STD_LOGIC_VECTOR (7 downto 0));     
end entity running_led;

architecture Behavioral of running_led is
  type states is(s0,s1,s2,s3);                          --定义四种模式
  signal present   : states:=s0;
  signal nex_state : states;  
  signal q_tmp     : std_logic_vector(7 downto 0):="10000000"; 
  signal count     : std_logic_vector(2 downto 0):="000";  
  signal cnt_f     : std_logic_vector(25 downto 0):=(others=>'0');
  signal clk_f     : std_logic:='0';  
begin
--clk=100MHZ,clk_f=2HZ,0.5s
  cnt_f_gen:process(clk)
  begin
    if(clk'event and clk='1') then
      if(cnt_f=24999999)then               --计数个数N=(clk/clk_f)/2-1
        cnt_f<=(others=>'0');
      else
        cnt_f<=cnt_f+1;        
      end if;
    end if;
  end process;
  
  clk_f_gen:process(clk)
  begin
      if(clk'event and clk='1') then
        if(cnt_f=0) then
          clk_f<=not clk
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值