ELSIF (clk'EVENT AND clk = '1')THEN --判断时钟信号为上升沿;
IF (en_1hz = '1') THEN --使能为1开始计时;
IF (data0(3 DOWNTO 0) ="1001") THEN --数码管0为9时下次数值加1为0;其他情况都加1
IF (data1 = "0101") THEN--数码管1为5时下次数值加1变成0;其他情况都加1
IF (data2 = "1001") THEN--数码管2为9时下次数值加1变成0;其他情况都加1
IF (data3 = "0101") THEN--数码管3为5时下次数值加1变成0;其他情况都加1
data3 <= "0000";ELSEdata3 <= data3 + "0001";
END IF;
data2 <= "0000";ELSEdata2 <= data2 + "0001";
END IF;
data1 <= "0000"; ELSEdata1 <= data1 + "0001";
END IF;
data0 <= "0000"; ELSEdata0 <= data0 + "0001"
time_total <= (data3 & data2& data1 & data0);--总时间就是data0~3连接到一起的量
ELSIF (clk'EVENT AND clk = '1')THEN --判断时钟信号为上升沿;
IF (en_1hz = '1') THEN --使能为1开始计程;
IF (data0 = "1001") THEN
data0 <= "0000"; -- 0号位为9时下次数值加1为0,其他情况都加1;
IF (data1 = "1001") THEN
data1 <= "0000"; -- 1号位为9时下次数值加1为0,其他情况都加1;
IF (data2 = "1001") THEN-- 2号位为9时下次数值加1为0,其他情况都加1;
IF (data3 = "1001") THEN-- 3号位为9时下次数值加1为0,其他情况都加1;
data3 <= "0000";ELSE data3<= data3 + "0001";
END IF;
data2 <= "0000"; ELSE data2<= data2 + "0001";
END IF;
ELSE data1 <= data1 +"0001";
END IF;
ELSE data0 <= data0 +"0001";
Mile_dec <= (data4 & data3& data2 & data1); --总里程就是data0~3连接到一起的量
cnt_2s <= (conv_integer(time_total(3 DOWNTO 0)) + conv_integer(time_total(7DOWNTO 4)) * 10) / 2;
将时间的秒数设置成cnt_2s,时间的费用是两秒一跳;
IF ((NOT(rst)) = '1') THEN --判断复位取反后是否等于1,与其他时钟错开
Q1 <= 1200;
--总费用就为12元;
ELSIF (clk'EVENT AND clk = '1')THEN
IF (Mile_in <="0000000000100000") THEN --当里程小于2KM时;
Q1 <= 1200+4 * cnt_2s+( (conv_integer(time_total(11 DOWNTO 8)) + conv_integer(time_total(15 DOWNTO 12)) * 10) * 100);
--总费用等于12加上0.04乘以总时间的秒数再加上所用多少分钟;
ELSE
Q1 <= 1200+ 4 * cnt_2s+((conv_integer(time_total(11 DOWNTO 8)) + conv_integer (time_total(15 DOWNTO 12))* 10) * 100) + 24 *(conv_integer( Mile_in(15 DOWNTO 12)) *1000+conv_integer(Mile_in(11 DOWNTO 8)) *100 +conv_integer(Mile_in(7 DOWNTO 4))*10 +conv_integer(Mile_in(3 DOWNTO 0)) - 20);
--总费用等于12加上0.04乘以总时间的秒数再加上所用多少分钟再加上计程所显示的距离
END IF;
A/B的运算结果是向0的方向取整
--将费用的每个位置分出
T10 <= (Q1 rem 10);
T20 <= (Q1 /10) rem 10;
T30 <= (Q1 / 100) rem 10;
T40 <= (Q1 /1000) rem 10;
--将每个位置的费用数值都拉长4位,方便后面转换
conv_std_logic_vector(T10,4); =
conv_std_logic_vector(T20,4); =
conv_std_logic_vector(T30,4); =
conv_std_logic_vector(T40,4); =
T_fare <= (T4 & T3 & T2& T1);
总费用的数值就用二进制替换出来
IF ((NOT(rst_n)) = '1') THEN --复位键为0则按键采样都为0
count2 <="00000000000000";
key_reg1 <= '0';
key_reg2 <= '0';
button_posedge <= '0';
ELSIF (clk'EVENT AND clk = '1')THEN --检测到时钟上升沿时
count2 <= count2 +"00000000000001";
IF (count2 ="00000011111010") THEN – 延迟时间
key_reg1 <= button_in; --键位输入
count2 <="00000000000000";
END IF;
key_reg2 <= key_reg1;
button_posedge <= (key_reg2) AND(NOT(key_reg1)); --按键状态
ax_debounce_m7 : ax_debounce --启动按键;
PORT MAP (
clk => clk,rst_n=> rst_n,button_in => btn1,button_posedge=> start_posedge
);
ax_debounce_m1 : ax_debounce --里程按键;
PORT MAP (
clk=>clk,rst_n=>rst_n,button_in=>btn2,button_posedge=>distance_posedge
);
ax_debounce_m2 : ax_debounce --计时按键;
PORT MAP (
clk=> clk,rst_n=>rst_n,button_in => btn3,button_posedge => time_posedge
);
ax_debounce_m3 : ax_debounce --暂停按键;
PORT MAP (
clk=>clk,rst_n=>rst_n,button_in=>btn5,button_posedge=>stop_posedge
);
ax_debounce_m4 : ax_debounce --费用按键;
PORT MAP (
clk=> clk,rst_n=>rst_n,button_in => btn6,button_posedge=> fare_posedge
);
--相应的端口的主要功能如下面代码所示:
IF ((NOT(rst_n)) = '1')THEN --复位键功能
stop_en <= '0';
ELSIF (clk'EVENT AND clk= '1') THEN
IF (stop_posedge = '1')THEN --暂停
stop_en <= '1';
PROCESS (clk, rst_n)
BEGIN
IF ((NOT(rst_n)) = '1')THEN --复位键按下数码管显示的时间
dist_en <='0';time_en <= '1';fare_en <= '0';
ELSIF (clk'EVENT AND clk= '1') THEN
IF (distance_posedge ='1') THEN --里程按键按下数码管显示里程
dist_en <='1';time_en <= '0';fare_en <= '0';
ELSIF (time_posedge ='1') THEN --时间按键按下数码管显示时间
dist_en <='0';time_en <= '1';fare_en <= '0';
ELSIF (fare_posedge ='1') THEN --费用按键按下数码管显示费用
dist_en <= '0';time_en<= '0';fare_en <= '1';
CASE bin_data IS
WHEN "0000"=>seg_data <= "1000000"; --0
WHEN "0001"=>seg_data <= "1111001"; --1
WHEN "0010"=>seg_data <= "0100100"; --2
WHEN "0011"=>seg_data <= "0110000"; --3
WHEN "0100"=>seg_data <= "0011001"; --4
WHEN "0101"=>seg_data <= "0010010"; --5
WHEN "0110"=>seg_data <= "0000010"; --6
WHEN "0111"=>seg_data <= "1111000"; --7
WHEN "1000"=>seg_data <= "0000000"; --8
WHEN "1001"=>seg_data <= "0010000"; --9
WHEN OTHERS=>seg_data <= "1111111"; --其他情况数码管不亮
作者:czd886, 来源:面包板社区
链接:https://mbb.eet-china.com/forum/topic/129004_1_1.html
版权声明:本文为博主原创,未经本人允许,禁止转载!
END
点击阅读原文,参加活动!