找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2610|回复: 0
打印 上一主题 下一主题
收起左侧

状态机

[复制链接]
跳转到指定楼层
楼主
ID:262 发表于 2014-10-17 18:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
查看状态机

显示结果:


Library ieee;
use ieee.std_logic_1164.all;
entity zhuangt is
Port(f10MHz:in bit;
     input,reset:in bit;
     output:out integer range 0 to 4);
end;
architecture dd of zhuangt is
type state_Type is (s1,s0,s2,s3);
signal state :state_Type;
signal cnt:integer range 0 to 10000000;
signal clk:std_logic;
begin
process(f10MHz)
    begin
      if f10MHz'event and f10MHz='1' then
           if cnt=4999999 then cnt<=0;clk<=not clk;
           else cnt<=cnt+1;
           end if;
       end if;
end process;
Process(clk,reset)
   begin
     if reset='1' then state<=s0;
     elsif clk'event and clk='1' then
          case state is
           when s0=> state <=s1;
           when s1=>
                   if input='1' then state <=s2;
                   else state<=s1;
                   end if;
           
     when s2=>
                   if input='0' then state <=s3;
                   else state<=s2;
                   end if;
    when s3=>state<=s0;      
           end case;
     end if;
end process;
process(state,input)
begin
  case state is
   when s0=>
           if input='1' then output<=0;
     else output<=4;
     end if;
when s1=>
           if input='1' then output<=1;
     else output<=4;
     end if;
when s2=>
           if input='1' then output<=2;
     else output<=4;
     end if;
when s3=>
           if input='1' then output<=3;
     else output<=4;
     end if;
end case;
end process;
end;


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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