1、out std_logic);end Taxi_part1;architecture behavior of Taxi_part1 isbegin process(clk,reset,stop,start,sp) type state_type is(s0,s1); variable s_state:state_type; variable cnt:integer range 0 to 1400; variable kinside: case sp is when 000= kinside:=0;001=1400;010=1200;011=1000;100=800;101=600;110=40
2、0;111=200; end case; if(reset=1) then s_state:=s0; elsif(clkevent and clk=) then case s_state is when s0= cnt:clkout clkout if(stop= -相当于无客户上车 elsif(sp= -有客户上车,但车速位0,即客户刚上车还未起步 elsif(cnt=kinside) then cnt: s_state: else cnt:=cnt+1; end process;end behavior;2.计程模块:由于一个clkout信号代表行进100m,故通过对clkout计数,可以
3、获得共行进的距离kmcount。entity Taxi_part2 is port(clkout,reset: kmcnt1:out std_logic_vector(3 downto 0); kmcnt2: kmcnt3:out std_logic_vector(3 downto 0);end Taxi_part2;architecture behavior of Taxi_part2 is process(clkout,reset) variable km_reg:std_logic_vector(11 downto 0);) then km_reg:=0 elsif(clkouteven
4、t and clkout=) then -km_reg(3 downto 0)对应里程十分位 if(km_reg(3 downto 0)=1001)then km_reg:=km_reg+0111 -十分位向个位的进位处理 else km_reg(3 downto 0):=km_reg(3 downto 0)+0001 if(km_reg(7 downto 4)=101001100000 -个位向十位的进位处理end if;kmcnt1=km_reg(3 downto 0);kmcnt2=km_reg(7 downto 4);kmcnt3 waittime:timecount if(sp=t2
5、; else waittime:t_state: when t2 =waittime+1; timecount if(waittime=1000) then -20s,即1000个clk,产生一个时间计费脉冲 elsif(stop= else timecount) then price0100 else Price0011)or(kmcnt3) then Enable else Enablekmmoney2:process(reset,clkout,clk,Enable,Price,kmcnt2)variable reg2:variable clkout_cnt:integer range 0
6、 to 10;) then cash reg2(7 downto 0):=reg2(7 downto 0)+00000111 if(reg2(7 downto 4) cash =reg2+ else cash0000100100000110+price; cash=reg2+price; else clkout_cnt:=clkout_cnt+1;count1=cash(3 downto 0); -总费用的个位count2=cash(7 downto 4); -总费用的十位count3=cash(11 downto 8); -总费用的百位5.显示模块:时间的显示需要用到全部8个数码管,由于实验
7、板上的所有数码管均对应同一组7段码,因此,需要采用动态扫描的方式实现时间显示。entity display isport(clk: kmcount1: kmcount2: kmcount3: clkout:out std_logic_vector(6 downto 0); sel:buffer std_logic_vector(2 downto 0);end display;architecture dtsm of display is signal key: process(clk) variable dount:std_logic_vector(2 downto 0): if rising_edge(clk) then if dount= then dount: else =dount+1; sel=dount; process(sel) case sel iskeynull; process(key) case key is01111110000110101101110011111100110010111011010110111110100001111000111111111011111000000end dtsm;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1