?? taxi.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 + -