集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2148|回复: 0

状态机,但是仿真显示状态不变化

[复制链接]
ANG 发表于 2010-6-26 00:19:11 | 显示全部楼层 |阅读模式
状态机,但是仿真显示状态不变化
       



library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity iic is
port(
clk:in std_logic;
rst:in std_logic;
ena:in std_logic;
clk_fp_out
       
ut std_logic;
complete
       
ut std_logic
);
end iic;
architecture structure of iic is
type states is(idle,start,addr_sel,addr_data,ack_s,write,stop);
signal current_state,next_state:states;
signal state_mask:std_logic_vector(3 downto 0);
signal clk_fp:std_logic;
signal cnt_byte:integer range 0 to 7;
begin
clk_fp_out<=clk_fp;
process(clk,rst)
variable cnt:std_logic_vector(7 downto 0);
begin
if(rst='1')then
  cnt:="00000000";
  clk_fp<='0';
elsif(clk'event and clk='1')then
   if(cnt="00001000"
       
then
    clk_fp<='1';
    cnt:="00000000";
   else
    if(ena='1')then
     cnt:=cnt+1;
    end if;
    clk_fp<='0';
   end if;
end if;
end process;
process(current_state,state_mask,cnt_byte)
begin
  case current_state is
   when idle=>
    next_state<=start;
    cnt_byte<=0;
    state_mask<="0000";
   when start=>
    next_state<=addr_sel;
    cnt_byte<=0;
    state_mask<="0001";
   when addr_sel=>
    if(cnt_byte=7)then
     next_state<=ack_s;
     cnt_byte<=0;
    else
     next_state<=addr_sel;
     cnt_byte<=cnt_byte+1;
    end if;
    state_mask<="0010";
   when addr_data=>
    if(cnt_byte=7)then
     next_state<=ack_s;
     cnt_byte<=0;
    else
     next_state<=addr_data;
     cnt_byte<=cnt_byte+1;
    end if;
    state_mask<="0011";
    when ack_s=>
     case state_mask is
      when "0010"=>next_state<=addr_data;
      when "0011"=>next_state<=write;
      when "0101"=>next_state<=stop;     
      when others=>null;
     end case;
     state_mask<="0100";
    when write=>
     if(cnt_byte=7)then
      next_state<=ack_s;
      cnt_byte<=0;
     else
      next_state<=write;
      cnt_byte<=cnt_byte+1;
     end if;
     state_mask<="0101";
   when stop=>
      next_state<=idle;
      cnt_byte<=0;
      state_mask<="0110";
  end case;
end process;
process(clk_fp,rst)
begin
if(rst='1')then
  current_state<=idle;
elsif(clk_fp'event and clk_fp='1')then
   current_state<=next_state;
end if;
end process;
process(current_state)
begin
  case current_state is
   when idle=>
    complete<='0';
   when start=>
    complete<='0';
   when addr_sel=>
    complete<='0';
   when addr_data=>
    complete<='0';
   when ack_s=>
    complete<='0';
   when write=>
    complete<='0';
   when stop=>
    complete<='1';
  end case;
end process;
end structure;
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

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

GMT+8, 2024-12-24 00:06 , Processed in 0.058297 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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