名称:Quartus出租车计价器VHDL代码仿真(文末获取)
软件:Quartus
语言:VHDL
代码功能:
出租车
设计一个按里程收费的出租计价器,出租车的起价5元:当里程小于km时,按起个计算,当程大于3km时,按每km(公里)1.3元计算;当等特时间累计超过2分钟按每分钟1.5元计算;并能显示行驶公里数等累计时间、总费用,设计的主要技术指标如下
计价范围;0-999.9元;计价分辫率;0.1元;
1. 工程文件
2. 程序文件
3. 程序编译
4. RTL图
5. Testbench
6. 仿真图
整体仿真图
速度及判断模块
控制模块
里程计算模块
时间计算模块
显示模块
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY taxi_fee IS PORT ( clk : IN STD_LOGIC;--50MHz基准频率CLOCK0 reset : IN STD_LOGIC;--复位信号,低有效 stop : IN STD_LOGIC;--本次行程结束,停止计费,高有效 start : IN STD_LOGIC;--启动信号,行程开始,高有效 Wheel_pulse : IN STD_LOGIC;--车轮脉冲 --4位数码管显示费用 Kmmoney_L_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--合计费用 HML=xxx (BCD码显示) Kmmoney_M_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); Kmmoney_H_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); Kmmoney_K_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); --里程显示 Kmcount_H_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--总路程 Kmcount_L_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); --时间显示 time_H_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--总时间 time_L_HEX : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END taxi_fee; ARCHITECTURE trans OF taxi_fee IS --速度计算及判断模块 COMPONENT speed_pulse IS PORT ( clk : IN STD_LOGIC;--标准时钟,10hz reset : IN STD_LOGIC;--复位信号,低有效 Wheel_pulse : IN STD_LOGIC;--车轮脉冲 Speed : OUT STD_LOGIC;--0:暂停等待;1:行驶 kilometre_01 : OUT STD_LOGIC;--1公里产生一次 minute_en : OUT STD_LOGIC--暂停等待,1min产生一次脉冲 ); END COMPONENT; --模块例化 COMPONENT display IS PORT ( clk : IN STD_LOGIC; reset : IN STD_LOGIC; Speed : IN STD_LOGIC;--0:暂停等待;1:行驶 wait_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); totel_money : IN STD_LOGIC_VECTOR(15 DOWNTO 0); mileage : IN STD_LOGIC_VECTOR(7 DOWNTO 0); --4位数码管显示费用 Kmmoney_L_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--合计费用 HML=xxx (BCD码显示) Kmmoney_M_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); Kmmoney_H_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); Kmmoney_K_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); --里程显示6 Kmcount_H_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--总路程 Kmcount_L_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); --时间显示 time_H_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--总时间 time_L_HEX : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ); END COMPONENT; --模块例化 --计费模块 COMPONENT taxi_state IS PORT ( clk : IN STD_LOGIC;--标准时钟,10hz reset : IN STD_LOGIC;--复位信号,低有效 stop : IN STD_LOGIC;--本次行程结束,停止计费,高有效 start : IN STD_LOGIC;--启动信号,行程开始,高有效 Speed : IN STD_LOGIC;--0:暂停等待;1:行驶 kilometre_01 : IN STD_LOGIC;--1公里产生一次脉冲 minute_en : IN STD_LOGIC;--暂停等待,1min产生一次脉冲 state_out : OUT STD_LOGIC_VECTOR(2 DOWNTO 0); wait_time : IN STD_LOGIC_VECTOR(7 DOWNTO 0); mileage : IN STD_LOGIC_VECTOR(7 DOWNTO 0);--里程 totel_money_out : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)--合计费用 ); END COMPONENT; --计费模块 COMPONENT mileage_ctrl IS PORT ( clk : IN STD_LOGIC;--标准时钟,10hz reset : IN STD_LOGIC;--复位信号,低有效 kilometre_01 : IN STD_LOGIC;--1公里产生一次脉冲 state : IN STD_LOGIC_VECTOR(2 DOWNTO 0); mileage_out : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); END COMPONENT; --计时模块 COMPONENT time_ctrl IS PORT ( clk : IN STD_LOGIC;--标准时钟,10hz reset : IN STD_LOGIC;--复位信号,低有效 minute_en : IN STD_LOGIC;--暂停等待,1min产生一次脉冲 state : IN STD_LOGIC_VECTOR(2 DOWNTO 0); wait_time_out : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--计时 ); END COMPONENT; --信号定义 SIGNAL Speed : STD_LOGIC;--0:暂停等待;1:行驶 SIGNAL kilometre_01 : STD_LOGIC; SIGNAL minute_en : STD_LOGIC; SIGNAL totel_money : STD_LOGIC_VECTOR(15 DOWNTO 0); SIGNAL mileage : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL wait_time : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL state : STD_LOGIC_VECTOR(2 DOWNTO 0); BEGIN --3位数码管显示费用 Kmmoney_L_HEX(7)<='1';--合计费用 HML=xxx (BCD码显示) Kmmoney_M_HEX(7)<='0';--显示小数点 Kmmoney_H_HEX(7)<='1'; Kmmoney_K_HEX(7)<='1'; --里程显示 Kmcount_H_HEX(7)<='1'; Kmcount_L_HEX(7)<='1'; --时间显示 time_H_HEX(7)<='1'; time_L_HEX(7)<='1'; --速度计算及判断模块 U_speed_pulse : speed_pulse PORT MAP ( clk => clk,--标准时钟,256hz reset => reset,--复位信号,低有效 Wheel_pulse =>Wheel_pulse, Speed => Speed,----0:暂停等待;1:行驶 kilometre_01 => kilometre_01,--1公里产生一次脉冲 minute_en => minute_en--暂停等待,1min产生一次脉冲 ); --控制模块 U_taxi_state : taxi_state PORT MAP ( clk => clk,--标准时钟,256hz reset => reset,--复位信号,低有效 stop => stop,--本次行程结束,停止计费,高有效 start => start,--启动信号,行程开始,高有效 speed => Speed,----0:暂停等待;1:行驶 kilometre_01 => kilometre_01,----1公里产生一次脉冲 minute_en => minute_en,--暂停等待,1mins产生一次脉冲 state_out=>state, wait_time => wait_time, mileage => mileage, totel_money_out => totel_money--合计费用 ); --计里程模块 U_mileage_ctrl: mileage_ctrl PORT MAP( clk => clk,--标准时钟 reset => reset,--复位信号,低有效 kilometre_01 => kilometre_01,----1公里产生一次脉冲 state =>state, mileage_out => mileage ); --计时模块 U_time_ctrl : time_ctrl PORT MAP( clk => clk,--标准时钟 reset => reset,--复位信号,低有效 minute_en => minute_en,--暂停等待,1min产生一次脉冲 state =>state, wait_time_out =>wait_time ); --显示模块 U_display : display PORT MAP ( clk => clk,--标准时钟 reset => reset,--复位信号,低有效 speed => Speed,----0:暂停等待;1:行驶 totel_money => totel_money,--费用 mileage => mileage,--里程 wait_time => wait_time,--累计等待时间 --4位数码管显示费用 Kmmoney_L_HEX => Kmmoney_L_HEX(6 DOWNTO 0),--合计费用 HML=xxx (BCD码显示) Kmmoney_M_HEX => Kmmoney_M_HEX(6 DOWNTO 0), Kmmoney_H_HEX => Kmmoney_H_HEX(6 DOWNTO 0), Kmmoney_K_HEX => Kmmoney_K_HEX(6 DOWNTO 0), --里程显示 Kmcount_H_HEX => Kmcount_H_HEX(6 DOWNTO 0),--总路程 Kmcount_L_HEX => Kmcount_L_HEX(6 DOWNTO 0), --时间显示 time_H_HEX => time_H_HEX(6 DOWNTO 0),--总时间 time_L_HEX => time_L_HEX(6 DOWNTO 0) ); END trans;
完整代码
扫描文章末尾的公众号二维码