找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3135|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

狀態(tài)機

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:262 發(fā)表于 2014-10-17 18:52 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
查看狀態(tài)機

顯示結(jié)果:


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 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表