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

📄 zlgz.txt

📁 简单电子玩具的感知模块程序设计,通过外部输入信号改变内部信号.从而改变玩具的状态
💻 TXT
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

--  Uncomment the following lines to use the declarations that are
--  provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity zlgz is
    Port ( reset : in std_logic;
	       clk   : in std_logic;
           sxxu : in std_logic;
		   djxu : in std_logic;
           hlxu : in std_logic;
           jexu : in std_logic;
           gdxu : in std_logic;
           out2 : out std_logic;
           out1 : out std_logic;
           out0 : out std_logic);
end zlgz;
architecture Behavioral of zlgz is
	signal sx : std_logic_vector(2 downto 0);
	signal hl : std_logic_vector(2 downto 0);
	signal je : std_logic_vector(2 downto 0);
	signal gd : std_logic_vector(2 downto 0);	
begin	
	control:process(clk,reset,sxxu,djxu,hlxu,jexu,gdxu)     --主程序,负责需求的提出及相关判断
	variable count : std_logic_vector(3 downto 0);
	variable nums : integer range 0 to 10;
	variable numh : integer range 0 to 10;
	variable numj : integer range 0 to 10;
	variable numg : integer range 0 to 10;
	variable sxen :  std_logic;
	variable djen :  std_logic;
    variable hlen :  std_logic;
    variable jeen :  std_logic;
    variable gden :  std_logic;
		begin
          if (reset='1') then	         --复位,初始化
		  	    sx<="001";
		  	    hl<="001";
		  	    je<="001";
		  	    gd<="001";
			    nums:=0;
				numh:=0;
				numj:=0;
				numg:=0;
		  	    count:="0000";               --再计数
          elsif (clk'event and clk='1') then --clk检查一次			    
	       	count:=count+1;				     
            if (count="1111")then       
			      if(nums<10)then           
				    nums:=nums+1;   
				  else
				    nums:=0;
				  end if;
				  if(numh<10)then			
				    numh:=numh+1;   
				  else
				    numh:=0;
				  end if;
				  if(numj<10)then			
				    numj:=numj+1;   
				  else
				    numj:=0;
				  end if;
				  if(numg<10)then			
				    numg:=numg+1;   
				  else
				    numg:=0;
				  end if; 
			      if (sxen='1')then      
				    nums:=0;
         		            if (sx="100")then    
				      sx<=sx;
				    elsif(sx="010")then  
				      sx<=sx+2;
					else
					  sx<="010";
				    end if;
			      elsif(djen='1')then    
					nums:=0;
					if(sx="001")then     
					   sx<=sx;
					elsif(sx="010")then
					   sx<=sx-1;
					else
					   sx<="010";
					end if;
			     else
			             if (nums=10)then
				      if (sx="001")then
					   sx<=sx;
					  elsif(sx="010")then
					   sx<=sx-1;
					  else
					   sx<="010";
					  end if;
				    end if;
				  end if;
				  if (hlen='1')then
				    numh:=0;
				    if (hl="100")then
				      hl<=hl;
				    elsif(hl="010")then
				      hl<=hl+2;
					else
					  hl<="010";
				    end if;
				  else
				    if (numh=10)then
				      if (hl="001")then
					   hl<=hl;
					  elsif(hl="010")then
					   hl<=hl-1;
					  else
					   hl<="010";
					  end if;
				    end if;
				  end if;
				  if (jeen='1')then
				    numj:=0;
				    if (je="100")then
				      je<=je;
				    elsif(je="010")then
				      je<=je+2;
					else
					  je<="010";
				    end if;
				  else
				    if (numj=10)then
				      if (je="001")then
					   je<=je;
					  elsif(je="010")then
					   je<=je-1;
					  else
					   je<="010";
					  end if;
				    end if;
				  end if;
				  if (gden='1')then
				    numg:=0;
				    if (gd="100")then
				      gd<=gd;
				    elsif(gd="010")then
				      gd<=gd+2;
					else
					  gd<="010";
				    end if;
				  else
				    if (numg=10)then
				      if (gd="001")then
					   gd<=gd;
					  elsif(gd="010")then
					   gd<=gd-1;
					  else
					   gd<="010";
					  end if;
				    end if;
				  end if;					  
				  if((sx(2) and hl(2) and je(2) and gd(2))='1')then  
		  	  			out2<='1';    --兴奋状态
			 	 		out1<='0';
			  			out0<='0';     
		   		  elsif((sx(0) or hl(0) or je(0) or gd(0))='1')then
			  			out2<='0';
			  			out1<='0';
		      			out0<='1';	  --不适状态
		   		  else
		      			out2<='0';  
		     			out1<='1';	  --高兴状态
			  			out0<='0';
		   		  end if;
				  sxen:='0';          --一次工作完成,将相应的一些变量清零
				  djen:='0';
				  hlen:='0';
				  jeen:='0';
				  gden:='0';
				  count:="0000";
			  end if;
			  if ( sxxu='1')then      --检测到外部信号,并将其保持
				sxen:='1';
			  end if;
			  if ( djxu='1')then
				djen:='1';
			  end if;
			  if (hlxu='1')then
		        hlen:='1';
			  end if;
			  if (jexu='1')then
		   		jeen:='1';
			  end if;
			  if (gdxu='1')then
		   		gden:='1';
			  end if;
          end if;
	end process;
end Behavioral;	     

⌨️ 快捷键说明

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