首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

使用变量的状态机,应求

使用变量的状态机,应求

-- State Machine using Variable
-- dowload from: www.fpga.com.cn & www.pld.com.cn

library ieee;
use ieee.std_logic_1164.all;

ENTITY fsm2 IS

    PORT(clock,x : IN BIT; z : OUT BIT);
END fsm2;
-------------------------------------------------
ARCHITECTURE using_wait OF fsm2 IS

TYPE state_type IS (s0,s1,s2,s3);

BEGIN
   PROCESS

      VARIABLE state : state_type := s0;

   BEGIN

      WAIT UNTIL (clock'EVENT AND clock = '1');
         CASE state IS
            WHEN s0 => IF x = '0' THEN
                           state := s0;
                           z <= '0';
                       ELSE
                           state := s2;
                           z <= '1';
                       END IF;
            WHEN s2 => IF x = '0' THEN
                           state := s2;
                           z <= '1';
                       ELSE
                           state := s3;
                           z <= '0';
                       END IF;
            WHEN s3 => IF x = '0' THEN
                           state := s3;
                           z <= '0';
                       ELSE
                           state := s1;
                           z <= '1';
                       END IF;
            WHEN s1 => IF x = '0' THEN
                           state := s0;
                           z <= '0';
                       ELSE
                           state := s2;
                           z <= '0';
                       END IF;
           
         END CASE;
   END PROCESS;
END using_wait;

这个版主不太冷 =========================== 我的中电网博客:http://blog.chinaecnet.com/u/20/index.htm
返回列表