您的位置:首页 > 其它

EDA课设-基于VHDL的简易出租车计价器设计

2017-12-19 10:26 253 查看
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
use ieee.std_logic_arith.all; 
entity taxi is 
port(clk:in std_logic; 
start:in std_logic; 
wait_signal:in std_logic; 
mile:in std_logic; 
one_way:in std_logic; 
rst:in std_logic; 
cost0,cost1,cost2,cost3:out std_logic_vector(3 downto 0); 
min0,min1:out std_logic_vector(3 downto 0); 
km0,km1:out std_logic_vector(3 downto 0)); 
end; 
architecture bhv of taxi is 
signal mile_r1,mile_r2,mile_clk,start_r,clk1hz:std_logic; 
signal count:integer range 0 to 29; 
signal sec:integer range 0 to 59; 
signal c0,c1,c2,c3:std_logic_vector(3 downto 0);
signal k0,k1,m0,m1:std_logic_vector(3 downto 0);
signal en0,en1:std_logic; 
signal wait_clk,cost_clk:std_logic; 
begin 
U1:process( rst,clk) -- 分频
begin 
if rst='0' then 
if clk'event and clk='1' then 
if count=31 then 
count<=0;clk1hz<='1'; 
else 
count<=count+1;clk1hz<='0'; 
end if;
end if; 
end if; 
end process; 
U2:process(rst,clk1hz,start,wait_signal)  --等待时间计数
    begin 
if rst='1' then 
m0<="0000";m1<="0000"; 
elsif start='0'then 
wait_clk<='0'; 
elsif clk1hz'event and clk1hz='1' then 
if wait_signal='1'then 
if sec=59 then 
sec<=0;wait_clk<='1'; 
if m0="1001"then 
m0<="0000"; 
if m1="0101"then 
m1<="0000"; 
else 
m1<=m1+'1'; 
end if; 
else 
m0<=m0+'1'; 
end if; 
else 
wait_clk<='0'; 
sec<=sec+1; 
end if; 
else 
wait_clk<='0'; 
end if; 
end if; 
end process; 
U3:process( rst,clk1hz,mile,start) --检测mile上升沿
    begin
if rst='0' then
if clk1hz'event and clk1hz='1'then 
mile_r2<=mile_r1;mile_r1<=mile;start_r<=start; 
end if; 
end if; 
end process; 
mile_clk<=mile_r1 and not(mile_r2); 
cost_clk<= wait_clk when wait_signal='1'else 
mile_clk when en0='1' or en1 ='1'else '0'; 
U4:process(rst,start,mile_clk) --里程计数
begin 
if rst='1' then 
k0<="0000"; k1<="0000"; 
elsif start='0' then 
k0<="0000"; k1<="0000"; en0<='0';en1<='0'; 
elsif mile_clk'event and mile_clk='1' then 
if k1 & k0>="00100000" and one_way='1' then 
en1<='1';en0<='0'; 
end if; 
if k1 & k0="00000011" then 
en0<='1'; 
end if; 
if k0="1001" then 
k0<="0000"; 
if k1="1001" then 
k1<="0000"; 
else 
k1<=k1+'1'; 
end if; 
else 
k0<=k0+'1'; 
end if; 
end if; 
end process; 
U5:process( rst,start,cost_clk,start_r) --计费
begin 
if rst='1' then 
c0<="0000";c1<="0000"; c2<="0000";c3<="0000"; 
elsif start='1' and start_r='0' then 
c0<="0000";c1<="1000";c2<="0000"; c3<="0000"; 
elsif cost_clk'event and cost_clk='1'then 
if en1='0' and en0='1'then 
if c1="1001"then 
c1<="0000"; 
if c2="1001"then 
c2<="0000"; 
if c3="1001"then 
c3<="0000"; 
else 
c3<=c3+'1'; 
end if; 
else 
c2<=c2+'1'; 
end if; 
else 
c1<=c1+'1'; c0<="0000"; 
end if; 
else 
if (c0="0101" and c1="1000")or c1="1001"then 
if c1="1001" and c0="0101" then 
c0<="0000"; c1<="0001"; 
elsif c1="1001" and c0="0000" then 
c0<="0101";c1<="0000"; 
elsif c1="1000" and c0="0101" then 
c0<="0000";c1<="0000"; 
end if; 
if c2="1001" then 
c2<="0000"; 
if c3="1001"then 
c3<="0000"; 
else 
c3<=c3+'1'; 
end if; 
else 
c2<=c2+'1'; 
end if; 
elsif c0="0000"then 
c0<="0101";c1<=c1+'1'; 
else 
c0<="0000";c1<=c1+"0010"; 
end if; 
end if; 
end if; 
end process; 
min0<=m0; 
min1<=m1; 
km0<=k0; 
km1<=k1; 
cost0<=c0; 
cost1<=c1; 
cost2<=c2; 
cost3<=c3; 
end; 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: