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
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
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
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
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
distance_reg:=distance_reg+1;
dis:=dis+1;
end if;
if dis>=100then
d:='1';
dis:=0;
else d:='0';
end if;
if distance_reg>=300 then
if money_reg<2000and d='1'then
money_reg:=money_reg+120;
elsif money_reg>=2000 and d='1'then
money_reg:=money_reg+180;
end if;
end if;
end if;
money<=money_reg;
distance<=distance_reg;
end process;
end;
程序是这样的,
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
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
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
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
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
distance_reg:=distance_reg+1;
dis:=dis+1;
end if;
if dis>=100then
d:='1';
dis:=0;
else d:='0';
end if;
if distance_reg>=300 then
if money_reg<2000and d='1'then
money_reg:=money_reg+120;
elsif money_reg>=2000 and d='1'then
money_reg:=money_reg+180;
end if;
end if;
end if;
money<=money_reg;
distance<=distance_reg;
end process;
end;
程序是这样的,