⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ok.vhd

📁 quartus下实现的简易人羊白菜过河问题
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ok is
  port(
    m:in std_logic;
    clk:in std_logic;
    reset:in std_logic;
    a:in std_logic_vector(3 downto 0);
    b1:out std_logic_vector(3 downto 0);
    b2:out std_logic_vector(3 downto 0);
    b:out std_logic_vector(6 downto 0);
    disp:out std_logic_vector(5 downto 0);
	level:in std_logic_vector(3 downto 0)
  );
end ok;
architecture vhdl of ok is
component kongzhi is									--kongzhi 控制器 
  port(
    clk:in std_logic;
    reset:in std_logic;
    a:out std_logic_vector(2 downto 0);
    b:out std_logic_vector(5 downto 0)
  );
end component kongzhi;
component display is									--display 显示器 
  port(
    n:in std_logic_vector(1 downto 0);
    b1_temp:in std_logic_vector(3 downto 0);
    a:in std_logic_vector(2 downto 0);
    b:out std_logic_vector(6 downto 0);
	u:in std_logic_vector(6 downto 0);
	v:in std_logic_vector(6 downto 0)
  );
end component display;
signal temp1:std_logic_vector(2 downto 0);			
signal b1_temp:std_logic_vector(3 downto 0);
signal b2_temp:std_logic_vector(3 downto 0);
signal b_temp:std_logic_vector(6 downto 0);
signal n:std_logic_vector(1 downto 0);
signal k:std_logic;
signal u:std_logic_vector(6 downto 0);
signal v:std_logic_vector(6 downto 0);
signal count2_temp:std_logic_vector(3 downto 0);
begin												
  process(m,reset,b1_temp,b2_temp,k,level)			
  variable p:std_logic_vector(3 downto 0);			
  variable q:std_logic_vector(3 downto 0);
  variable c:std_logic_vector(3 downto 0);
  variable d:std_logic_vector(3 downto 0);
  variable r:std_logic_vector(3 downto 0);
  variable count1:std_logic_vector(3 downto 0);
  variable count2:std_logic_vector(3 downto 0);
  
  begin 
  if(reset='1')then						--复位
    b1_temp<="0000";
    b2_temp<="1111";
    n<="00";							
    count1:="0000";						
    count2:="0000";
  else
    if(m'event and m='0')then
	  r:=a xor b1_temp;			--河右岸动物的情况,人在对岸则结果为1
      p:=(not a) and "1100";	--判断河的左岸 猫和狗
      q:=(not a) and "0110";	--判断河的左岸 猫和鼠
      c:=a and "1100";			--判断河的右岸 猫和狗
      d:=a and "0110";			--判断河的右岸 猫和鼠
	  
	  
	  											
	    if(r="0001" or r="1001" or r="0101" or r="0011")then--走法正确
          if(a(0)='1')then							--判断人是否在河右岸
            if(p="1100" or q="0110")then			--判断左岸
              n<="01";
            else									--选择正确 
              n<="10";
              b1_temp<=a;
              b2_temp<=not a;
              count1:=count1+1;						--计数器加1
            end if;
          else										--人在左岸
            if(c="1100" or d="0110")then			--判断右岸
              n<="01";
            else									--选择正确
              n<="10";
              b1_temp<=a;
              b2_temp<=not a;
              count1:=count1+1;                     --计数器加1
            end if;
		  end if;
		  if(count1="1010")then
            count1:="0000";							--进位
            count2:=count2+1;						
            if(count2="1010")then					--当计数超过99时,显示'fail'
              n<="01";
            end if;
          end if;
        else										--走法错误
          n<="01";									--状态为失败 
          count1:=count1;							--计数器不变
          count2:=count2;
	    end if;
	  end if;
    end if;
  
  case count1 is						--十位数字 
  when"0000"=>u<="1111110";
  when"0001"=>u<="0110000";
  when"0010"=>u<="1101101";
  when"0011"=>u<="1111001";
  when"0100"=>u<="0110011";
  when"0101"=>u<="1011011";
  when"0110"=>u<="1011111";
  when"0111"=>u<="1110000";
  when"1000"=>u<="1111111";
  when"1001"=>u<="1111011";
 when others=>u<="0000000";
  end case;
  case count2 is						--个位数字 
  when"0000"=>v<="1111110";
  when"0001"=>v<="0110000";
  when"0010"=>v<="1101101";
  when"0011"=>v<="1111001";
  when"0100"=>v<="0110011";
  when"0101"=>v<="1011011";
  when"0110"=>v<="1011111";
  when"0111"=>v<="1110000";
  when"1000"=>v<="1111111";
  when"1001"=>v<="1111011";
 when others=>v<="0000000";
  end case;
  end process;									
  b1<=b1_temp;									
  b2<=b2_temp;
  a1:kongzhi port map(clk,reset,temp1,disp);		--调用kongzhi
  a2:display port map(n,b1_temp,temp1,b,u,v);		--调用display
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -