名称:出租车计价设计VHDL代码AX301开发板Quartus
软件:Quartus
语言:VHDL
代码功能:
具体如下:
1.实现计费功能,计费标准为:按行驶里程计费,起步价为7元,并在车行3Km后按2元/Km计费,当计费器达到或超过20元时,每公里加收50%的车费,车停止不计费。
2.现场模拟功能:能模拟汽车起动、停止、暂停以及加速等状态。
3.用BCD码将车费和路程显示出来。
本代码已在AX301开发板验证,开发板如下,其他开发板可以修改管脚适配:
1. 工程文件
2. 程序文件
3. 程序编译
4. 仿真图
Testbench
4.1 整体仿真
4.2 显示模块
4.3 速度脉冲模块
4.4 计费模块
部分代码展示:
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;--启动信号,行程开始 wait_key???:?IN?STD_LOGIC;--停车等待信号? ??????bit_select?????:?OUT?STD_LOGIC_VECTOR(5?DOWNTO?0);--数码管位选 ??????seg_select?????:?OUT?STD_LOGIC_VECTOR(7?DOWNTO?0)--数码管段选 ???); END?taxi_fee; ARCHITECTURE?trans?OF?taxi_fee?IS --模块例化 ???COMPONENT?display?IS ??????PORT?( ?????????clk????????:?IN?STD_LOGIC; ?????????reset??????:?IN?STD_LOGIC; ?????????totel_money?:?IN?STD_LOGIC_VECTOR(15?DOWNTO?0); ?????????mileage????:?IN?STD_LOGIC_VECTOR(7?DOWNTO?0); ?????????Kmmoney_L??:?OUT?STD_LOGIC_VECTOR(3?DOWNTO?0); ?????????Kmmoney_M??:?OUT?STD_LOGIC_VECTOR(3?DOWNTO?0); ?????????Kmmoney_H??:?OUT?STD_LOGIC_VECTOR(3?DOWNTO?0); ?????????Kmcount_H??:?OUT?STD_LOGIC_VECTOR(3?DOWNTO?0); ?????????Kmcount_L??:?OUT?STD_LOGIC_VECTOR(3?DOWNTO?0) ??????); ???END?COMPONENT; --数码管显示模块 COMPONENT?segment_ctrl?IS ???PORT?( ??????clk????????????:?IN?STD_LOGIC;--时钟 ?????? ??????Kmmoney_L????:?IN?STD_LOGIC_VECTOR(3?DOWNTO?0);----金额十分位,合计费用?HML=xxx?(BCD码显示) ??????Kmmoney_M????:?IN?STD_LOGIC_VECTOR(3?DOWNTO?0);--金额个位 ??????Kmmoney_H????:?IN?STD_LOGIC_VECTOR(3?DOWNTO?0);--金额十位 ??????--总路程,里程范围为HL=0~99(BCD码显示) ??????Kmcount_H????:?IN?STD_LOGIC_VECTOR(3?DOWNTO?0);--里程十位 ??????Kmcount_L????:?IN?STD_LOGIC_VECTOR(3?DOWNTO?0);--里程个位 ?????? ??????bit_select?????:?OUT?STD_LOGIC_VECTOR(5?DOWNTO?0);--数码管位选 ??????seg_select?????:?OUT?STD_LOGIC_VECTOR(7?DOWNTO?0)--数码管段选 ???); END?COMPONENT; --模块例化??? ???COMPONENT?speed_pulse?IS ??????PORT?( ?????????clk????????:?IN?STD_LOGIC; ?????????reset??????:?IN?STD_LOGIC; ?????????one_kilometre?:?OUT?STD_LOGIC ??????); ???END?COMPONENT; --模块例化 COMPONENT?taxi_state?IS ???PORT?( ??????clk??????????????:?IN?STD_LOGIC; ??????reset????????????:?IN?STD_LOGIC; ?????? ??????stop?????????????:?IN?STD_LOGIC; ??????start????????????:?IN?STD_LOGIC; ??????wait_key???:?IN?STD_LOGIC;--停车等待信号? ??????one_kilometre????:?IN?STD_LOGIC; ??????mileage_out??????:?OUT?STD_LOGIC_VECTOR(7?DOWNTO?0); ??????totel_money_out??:?OUT?STD_LOGIC_VECTOR(15?DOWNTO?0) ???); ???END?COMPONENT; ??? --信号定义 ???SIGNAL?one_kilometre???:?STD_LOGIC; ???SIGNAL?totel_money?????:?STD_LOGIC_VECTOR(15?DOWNTO?0); ???SIGNAL?mileage?????????:?STD_LOGIC_VECTOR(7?DOWNTO?0); ???SIGNAL?Kmmoney_L??:?STD_LOGIC_VECTOR(3?DOWNTO?0);--合计费用?HML=xxx?(BCD码显示) ???SIGNAL?Kmmoney_M??:?STD_LOGIC_VECTOR(3?DOWNTO?0);--合计费用?HML=xxx?(BCD码显示) ???SIGNAL?Kmmoney_H??:?STD_LOGIC_VECTOR(3?DOWNTO?0);--合计费用?HML=xxx?(BCD码显示) ???SIGNAL?Kmcount_H??:?STD_LOGIC_VECTOR(3?DOWNTO?0);--总路程,里程范围为HL=0~99(BCD码显示) ???SIGNAL?Kmcount_L??:?STD_LOGIC_VECTOR(3?DOWNTO?0);--总路程,里程范围为HL=0~99(BCD码显示) BEGIN ???--速度脉冲产生模块 ???U_speed_pulse?:?speed_pulse ??????PORT?MAP?( ?????????clk?????????????=>?clk,--标准时钟 ?????????reset???????????=>?reset,--复位信号,低有效? ?????????one_kilometre???=>?one_kilometre--1公里产生一次脉冲 ??????); ??? ??? ???--计费模块 ???U_taxi_state?:?taxi_state ??????PORT?MAP?( ?????????clk??????????????=>?clk,--标准时钟 ?????????reset????????????=>?reset,--复位信号,低有效? ?????????stop?????????????=>?stop,--本次行程结束,停止计费,高有效 ?????????start????????????=>?start,--启动信号,行程开始,高有效? ?????????wait_key?????????=>?wait_key,--停车等待信号? ?????????one_kilometre????=>?one_kilometre,--1公里产生一次脉冲 ?????????mileage_out??????=>?mileage, ?????????totel_money_out??=>?totel_money--合计费用 ??????); ??? ??? ???----BCD码转换模块 ???U_display?:?display ??????PORT?MAP?( ?????????clk??????????=>?clk,--标准时钟 ?????????reset????????=>?reset,--复位信号,低有效? ?????????totel_money??=>?totel_money,--费用 ?????????mileage??????=>?mileage,--里程 ?????????Kmmoney_L????=>?Kmmoney_L,--合计费用?HML=xxx?(BCD码显示) ?????????Kmmoney_M????=>?Kmmoney_M, ?????????Kmmoney_H????=>?Kmmoney_H, ????????? ?????????Kmcount_H????=>?Kmcount_H,--总路程,里程范围为HL=0~99(BCD码显示) ?????????Kmcount_L????=>?Kmcount_L ??????); ??? --数码管显示模块 U_segment_ctrl:?segment_ctrl ???PORT?MAP( ??????clk??????????=>?clk,--时钟 ?????? ??????Kmmoney_L????=>?Kmmoney_L,----金额十分位,合计费用?HML=xxx?(BCD码显示) ??????Kmmoney_M????=>?Kmmoney_M,--金额个位 ??????Kmmoney_H????=>?Kmmoney_H,--金额十位 ??????--总路程,里程范围为HL=0~99(BCD码显示) ??????Kmcount_H????=>?Kmcount_H,--里程十位 ??????Kmcount_L????=>?Kmcount_L,--里程个位 ?????? ??????bit_select??=>?bit_select,--数码管位选 ??????seg_select??=>?seg_select--数码管段选 ???); END?trans;
?扫描文章末尾的公众号二维码