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

📄 2.vhd

📁 用VHDL实现地铁售票系统
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity shoupiao is
port
( clk :in std_logic;
  cancel:in std_logic:='1';
  reset : in std_logic:='1';
  ok :in std_logic:='1';
destination:in std_logic_vector(2 downto 0);
  initial : in std_logic_vector(2 downto 0);
  number : in std_logic_vector(1 downto 0);;
  
  paper1: in std_logic;
   paper2:in std_logic;
   paper5:in std_logic;
  paper10:in std_logic;
  paper20:in std_logic;
  comeout: out std_logic;
  charge: out std_logic_vector(4 downto 0);
);
end shoupiao;

architecture behave of shoupiao is
   type state is (s0,s1,s2,s3);
   signal s : state;
   
    
   begin

      
  process(clk,reset)
    variable money: std_logic_vector(4 downto 0);
    variable cost : std_logic_vector(4 downto 0):="00000";
    variable trip : std_logic_vector(2 downto 0):="000";
   begin  
      if reset='1' then
            s<=s0;
     else
       if clk'event and clk='1' then
       case s is 
       when s0=>
        if  ok='1' then
              s<=s1;
          else
               s<=s0;
      end if;
       when s1=>
        if destination /= initial then
             if destination > initial then
                trip:=(destination-initial);
             elsif destination<initial then
                trip:=(initial-destination);
               end if; 
              s<=s2;
          else
              s<=s1;
        end if;
        when s2=>
          if cancel='1' then
             s<=s1;
          end if;      
        if number="01" then
           if trip<="100" then
           cost:="00100";---5 yuan
          else cost:="01000";---10 yuan
          end if;
            s<=s3;
        elsif number="10" then
           if trip<="100" then
           cost:="01000";  ---10 yuan
           else cost:="10000";---20 yuan
           end if;
             s<=s3;
        elsif number="11" then
           if trip<="100" then
           cost:="01100";---15 yuan
            else cost:="11000";---30 yuan
               end if;
             s<=s3;

         else s<=s2;
         end if;
        when s3=>
           if cancel='1' then
            s<=s1;
          end if;
       
             if money=cost then
            comeout<='1';
           elsif money>=cost then
             comeout<='1';
             charge<=money-cost;
          
            else s<=s3;
             end if;
                   end case;
                      end if;
    end if;
                         end process;
                           end behave;
            
         
          
            
        
        
       
   
  
  
   

⌨️ 快捷键说明

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