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

📄 automat.vhd

📁 设计一个自动售货机控制程序
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity Automat is
	port(
		clk,rst:in STD_LOGIC;
		din: in STD_LOGIC_VECTOR(1 downto 0);		
		choice:in STD_LOGIC_VECTOR(1 downto 0);
		commodity:out STD_LOGIC_VECTOR(1 downto 0);
		give_change:out STD_LOGIC_VECTOR(1 downto 0)
		);
end Automat ;
architecture behavior of Automat  is
type states is (st0,st1,st2,st3,st4,st5);
signal cur_state,next_state : states;
begin
	process(clk,rst)
	begin
   		if rst='1' then
	   	cur_state<=st0;
  		elsif clk'event and clk='1' then 
	  	cur_state<=next_state;
  		end if;
   	end process;	 
	process(cur_state,next_state,din,choice)
	begin
	   	case cur_state is
		when st0=>  
			if din="01" then next_state<=st1;       --投一元
			elsif din="10" then next_state<=st2;	--投二元
			elsif din="11" then next_state<=st5;	--投五元
			else next_state<=st0;
			end if;
			commodity<="00";          				--不送商品
			give_change<="00";						--不找钱
		when st1=>  
			if din="01" then next_state<=st2;		--投一元
			elsif din="10" then next_state<=st3;	--投二元
			else next_state<=st1;
			end if;
			commodity<="00";						--不送商品
			give_change<="00";						--不找钱
		when st2=> 
		 	if din="01" then next_state<=st3;		--投一元
			elsif din="10" then next_state<=st4;	--投二元
			else next_state<=st2;
			end if;
			commodity<="00";						--不送商品
			give_change<="00";						--不找钱		
		when st3=>  
			if din="01" then next_state<=st4;		--投一元
			else next_state<=st3;
			end if;	
			if choice="01" then 					--选择商品一		
			commodity<="01";						--送出商品一
			give_change<="00";						--不找钱	
			next_state<=st0;
			end if;				
		when st4=>  
			if choice="01" then 					--选择商品一	
			commodity<="01";						--送出商品一
			give_change<="01";						--找一元
			next_state<=st0;
			elsif choice="10" then 					--选择商品二
			commodity<="10";						--送出商品二
			give_change<="00";						--不找钱	
			next_state<=st0;
			end if;			
		when st5=>  
			if choice="01" then 					--选择商品一	
			commodity<="01";						--送出商品一
			give_change<="10";						--找二元
			next_state<=st0;
			elsif choice="10" then 					--选择商品二
			commodity<="10";						--送出商品二
			give_change<="01";						--找一元
			next_state<=st0;
			end if;	
		when others	=>
			commodity<="00";						
			give_change<="00";						
			next_state<=st0;	
		end case;
	end process;
end behavior;
	

⌨️ 快捷键说明

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