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

📄 taxi.vhd

📁 在quartus开发环境下
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity taxi is
port(clk:in std_logic;-------计费时钟
     start:in std_logic;-----汽车启动
     stop:in std_logic;------汽车停止
     pause:in std_logic;-----汽车暂停
     speedup:in std_logic_vector(1 downto 0);----档位
     money:out integer range 0 to 8000;---------车费
     distance:out integer range 0 to 8000);-----路程
end;
architecture one of taxi is
begin
process(clk,start,stop,pause,speedup)
	variable money_reg,distance_reg:integer range 0 to 8000;
	variable num:integer range 0 to 9;
	variable dis:integer range 0 to 100;
	variable d:std_logic;
begin
if stop='1' then-------汽车停止,计费和路程清零
    money_reg:=0;
    distance_reg:=0;
	dis:=0;
	num:=0;
elsif start='1' then---汽车启动后,起步价为6元
	money_reg:=600;
	distance_reg:=0;
	dis:=0;
	num:=0;
elsif clk'event and clk='1' then
	if start='0' and speedup="00" and pause='0'  and stop='0' then----1档
	   if num=9 then
	       num:=0;
	       distance_reg:=distance_reg+1;
	       dis:=dis+1;
	    else num:=num+1;
	    end if;
	elsif start='0' and speedup="01" and pause='0' and stop='0' then---2档
	   if num=9 then
	      num:=0;
	      distance_reg:=distance_reg+2;
	      dis:=dis+2;
	   else num:=num+1;
	   end if;
	elsif start='0' and speedup="10" and pause='0' and stop='0' then----3档
	   if num=9 then
	      num:=0;
	       distance_reg:=distance_reg+5;
	       dis:=dis+5;
	   else num:=num+1;
	   end if;
	elsif start='0' and speedup="11" and pause='0' and stop='0' then---4档
		   distance_reg:=distance_reg+1;
	       dis:=dis+1;
	end if;
	if dis>=100 then
		   d:='1';
		   dis:=0;
		else d:='0';
	end if; 
	if distance_reg>=300 then -------如果超过3km则按1.2元/km计算
		if money_reg<2000 and d='1' then
		       money_reg:=money_reg+120;
		elsif money_reg>=2000 and d='1' then----当计费器达到20元时,每公里加收50%的车费
		       money_reg:=money_reg+180;
		end if;
	end if;
end if;
	money<=money_reg;
	distance<=distance_reg;
end process;
end ;

⌨️ 快捷键说明

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