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

📄 taxi.vhd

📁 用VHDL编写的一个出租车计费器
💻 VHD
字号:
--出租车计费器
--全部功能完成,完成仿真
--起步2两公里6¥,然后每半公里计费一次0.8¥,停止等待时每两分半计费一次
--2006.9.27
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity taxi is
	port(pulse,start,clk,sw : in  std_logic;                 	--米脉冲,起步信号,标准脉冲,选择
    	     out1,out2,out3 : out std_logic_vector(3 downto 0); --里程、时间显示
      	  char1,char2,char3 : out std_logic_vector(3 downto 0); --费用
         	      waits,led : out std_logic);
end taxi;

architecture art of taxi is
	signal o1,o2,o3 : integer range 0 to 9;			--输出
  	signal 	 pulse2 : std_logic;                    --百米脉冲
  	signal k1,k2,k3 : integer range 0 to 9;     	--公里信号
  	signal c1,c2,c3 : integer range 0 to 9;     	--费用信号
  	signal 	  temp1 : std_logic;					--未满2公里
	signal 	  temp2 : std_logic;					--500米脉冲
	signal 	  temp3 : std_logic;					--计费脉冲
  	signal 		jsq : std_logic_vector(4 downto 0); --等待计数器
  	signal 	   stop : std_logic;                    --wait
  	signal  se1,se2 : integer range 0 to 9;			--秒
  	signal 		mi1 : integer range 0 to 9;			--分
  	signal 	  jf,mc : std_logic;                    --等待计费脉冲

begin
	led<=start;
  process(pulse)                              --分频器
    variable fp:integer range 0 to 99;
  begin
    if(start='0')then
      	fp:=0;pulse2<='0';temp2<='0';
    elsif(pulse'event and pulse='1')then
      	if(fp=99)then
        	fp:=0;pulse2<='1';
      	else fp:=fp+1;pulse2<='0';
      	end if;
      	if((k1=5 or k1=0)and temp1='1')then             --判断500米计数器
        	temp2<='1'; 
      	else
        	temp2<='0';
      	end if;
    end if;
  end process;

  process(pulse2)
  begin
  	if(start='0')then
      	k1<=0;k2<=0;k3<=0;
      	temp1<='0';
    elsif(pulse2'event and pulse2='1')then
      	if(k1=9)then                      --公里计数器
        	k1<=0;k2<=k2+1;
        	if(k2=9)then
          		k2<=0;k3<=k3+1;
          			if(k3=9)then
            			k3<=0;
          			else    			                           
            			k3<=k3+1;
          			end if;
        	end if;
      	else
        	k1<=k1+1;
      	end if;      
    end if;
    if(k2<2 and k3=0)then
      	temp1<='0';
    else
      	temp1<='1';
    end if;
  end process;

  process                              --延时开始判断
  begin
    if(start='0')then
      	jf<='0';    
    elsif(mc='1' and temp1='0')then
      	jf<='1';
    end if;
  end process;
                                            
  process(start,temp3)                  --计费进程   
  begin
	temp3<=temp2 or mc;
    if(start='0')then
    	c1<=0;c2<=6;c3<=0;
    elsif(temp3'event and temp3='1')then
        case c1 is                     	--金额低位
        	when 0=> c1<=8;
          	when 2=> c1<=0;c2<=c2+1;
          	when 4=> c1<=2;c2<=c2+1;
          	when 6=> c1<=4;c2<=c2+1;
          	when 8=> c1<=6;c2<=c2+1;
          	when others=> c1<=0;
        end case;
        if(c2=9)then                   	--金额中位及高位
          	c2<=0;c3<=c3+1;
        end if;
    end if;
  end process;

  process(pulse)                         --是否等待判决
  begin
    if(start='0' or clk='0')then
      	jsq<="00000";
    elsif(pulse'event and pulse='0')then     
      	if(clk='1')then
        	if(jsq="11111")then
          		jsq<="00000";
        	else jsq<=jsq+'1';
        	end if;       
      	end if;
    end if;
  end process;

  process(clk)
  begin
    if(start='0')then
      	stop<='0';
    elsif(clk'event and clk='0')then
      	case jsq is
        	when "00000"=> stop<='1';               --等待信号输出
        	when "00001"=> stop<='1';
        	when others=> stop<='0';
      	end case;
    end if;
    waits<=stop;
  end process;

  process(clk)                                  --等待计时部分
    variable wjsq:integer range 0 to 149;
  begin
    if(start='0')then
      	se1<=0;se2<=0;mi1<=0;wjsq:=0;
    elsif(clk'event and clk='1')then             --9分59秒计数器
      	if(stop='1')then
        	if(se1=9)then
          		se1<=0;se2<=se2+1;
          		if(se2=5)then
            		se2<=0;mi1<=mi1+1;
            		if(mi1=9)then
              			mi1<=0;            
            		end if;
          		end if;
        	else se1<=se1+1;
        	end if;
        	if(wjsq=149)then                       --满2分30秒计费一次
         		 wjsq:=0;mc<='1';
        	else wjsq:=wjsq+1;mc<='0';
        	end if;
      	end if;
    end if;    
  end process;

  process(clk,sw)
  begin
	if rising_edge(clk)then
		if(sw='1')then
			o1<=k1;
			o2<=k2;
			o3<=k3;
		else
			o1<=se1;
			o2<=se2;
			o3<=mi1;
		end if;
	end if;

	case o1 is
		when 0 =>out1<= "0000";
   		when 1 =>out1<= "0001";
   		when 2 =>out1<= "0010";
   		when 3 =>out1<= "0011";
		when 4 =>out1<= "0100";
   		when 5 =>out1<= "0101";
   		when 6 =>out1<= "0110";
   		when 7 =>out1<= "0111";
   		when 8 =>out1<= "1000";
   		when 9 =>out1<= "1001";
		when others =>out1<= "0000";
	end case;
	case o2 is
		when 0 =>out2<= "0000";
   		when 1 =>out2<= "0001";
   		when 2 =>out2<= "0010";
   		when 3 =>out2<= "0011";
		when 4 =>out2<= "0100";
   		when 5 =>out2<= "0101";
   		when 6 =>out2<= "0110";
   		when 7 =>out2<= "0111";
   		when 8 =>out2<= "1000";
   		when 9 =>out2<= "1001";
		when others =>out2<= "0000";
	end case;
	case o3 is
		when 0 =>out3<= "0000";
   		when 1 =>out3<= "0001";
   		when 2 =>out3<= "0010";
   		when 3 =>out3<= "0011";
		when 4 =>out3<= "0100";
   		when 5 =>out3<= "0101";
   		when 6 =>out3<= "0110";
   		when 7 =>out3<= "0111";
   		when 8 =>out3<= "1000";
   		when 9 =>out3<= "1001";
		when others =>out3<= "0000";
	end case;
	case c1 is
		when 0 =>char1<= "0000";
   		when 1 =>char1<= "0001";
   		when 2 =>char1<= "0010";
   		when 3 =>char1<= "0011";
		when 4 =>char1<= "0100";
   		when 5 =>char1<= "0101";
   		when 6 =>char1<= "0110";
   		when 7 =>char1<= "0111";
   		when 8 =>char1<= "1000";
   		when 9 =>char1<= "1001";
		when others =>char1<= "0000";
	end case;
	case c2 is
		when 0 =>char2<= "0000";
   		when 1 =>char2<= "0001";
   		when 2 =>char2<= "0010";
   		when 3 =>char2<= "0011";
		when 4 =>char2<= "0100";
   		when 5 =>char2<= "0101";
   		when 6 =>char2<= "0110";
   		when 7 =>char2<= "0111";
   		when 8 =>char2<= "1000";
   		when 9 =>char2<= "1001";
		when others =>char2<= "0000";
	end case;
	case c3 is
		when 0 =>char3<= "0000";
   		when 1 =>char3<= "0001";
   		when 2 =>char3<= "0010";
   		when 3 =>char3<= "0011";
		when 4 =>char3<= "0100";
   		when 5 =>char3<= "0101";
   		when 6 =>char3<= "0110";
   		when 7 =>char3<= "0111";
   		when 8 =>char3<= "1000";
   		when 9 =>char3<= "1001";
		when others =>char3<= "0000";
	end case;
  end process;	

end art;



   

⌨️ 快捷键说明

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