【正文】
when 1000 = led7s = 11111111。 when 1001 = led7s = 11101111。 when others = led7s = 00000000。帶小數(shù)點的譯碼 end case。 end if。 end process COM2。end behav。architecture behav of counter_display is type states is (st0,st1,st2,st3,st4,st5,st6,st7)。八個狀態(tài)代表選通八個數(shù)碼管 signal current_state,next_state : states。 signal led7s : std_logic_vector(7 downto 0)。 signal ls0138 : std_logic_vector(2 downto 0)。 signal tmp : std_logic_vector(3 downto 0)。中間信號,用于存放待譯碼的數(shù)begin led7 = led7s。 ls138 = ls0138。REG:process(clk) begin if clk=39。139。 and clk39。event then current_state = next_state。 end if。 end process REG。 COM1:process(current_state,distance_in,fare_in)負(fù)責(zé)狀態(tài)跳變,及輸出各個狀態(tài)選通數(shù)碼管的地址和將待譯碼的數(shù)賦值給tmp begin case current_state is when st0 = ls0138 = 000。 next_state = st1。 tmp = distance_in(3 downto 0)。 when st1 = ls0138 = 001。 next_state = st2。 tmp = distance_in(7 downto 4)。 when st2 = ls0138 = 010。 next_state = st3。 tmp = distance_in(11 downto 8)。 when st3 = ls0138 = 011。 next_state = st4。 tmp = distance_in(15 downto 12)。 when st4 = ls0138 = 100。 next_state = st5。 tmp = fare_in(3 downto 0)。 when st5 = ls0138 = 101。 next_state = st6。 tmp = fare_in(7 downto 4)。 when st6 = ls0138 = 110。 next_state = st7。 tmp = fare_in(11 downto 8)。 when st7 = ls0138 = 111。 next_state = st0。 tmp = fare_in(15 downto 12)。 when others = ls0138 = 000。 next_state = st1。 tmp = distance_in(3 downto 0)。 end case。 end process COM1。 COM2:process(current_state,tmp) begin if current_state=st0 or current_state=st1 or current_state=st3 or current_state=st4 or current_state=st5 or current_state=st7 then case tmp is when 0000 = if (current_state=st7 or current_state=st3) then led7s=00000000。else led7s= 00111111。 end if。車費,路程高位消零 when 0001 = led7s = 00000110。 when 0010 = led7s = 01011011。 when 0011 = led7s = 01001111。 when 0100 = led7s = 01100110。 when 0101 = led7s = 01101101。 when 0110 = led7s = 01111101。 when 0111 = led7s = 00000111。 when 1000 = led7s = 01111111。 when 1001 = led7s = 01101111。 when others = led7s = 00000000。不帶小數(shù)點的譯碼 end case。 else case tmp is when 0000 = led7s = 10111111。 when 0001 = led7s = 10000110。 when 0010 = led7s = 11011011。 when 0011 = led7s = 11001111。 when 0100 = led7s = 11100110。 when 0101 = led7s = 11101101。 when 0110 = led7s = 11111101。 when 0111 = led7s = 10000111。 when 1000 = led7s = 11111111。 when 1001 = led7s = 11101111。 when others = led7s = 00000000。帶小數(shù)點的譯碼 end case。 end if。 end process COM2。end behav。library ieee。use 。use 。entity overflow is 路程,車費超量程處理模塊 port(distance_cout,fare_cout:in std_logic。路程,車費超量程進(jìn)位信號 light0,light1,light2,light3:out std_logic超量程指示燈,light0,light1,light2用于車費超量程指示,light3用于路程的 )。end overflow。architecture bhv of overflow isbeginC1:process(fare_cout) variable q1:std_logic_vector(1 downto 0)。 begin if fare_cout39。event and fare_cout=39。139。 then每超量程一次,狀態(tài)跳轉(zhuǎn) if q111 then q1:=q1+1。 else q1:=00。 end if。 end if。 case q1 is when 00= light0=39。039。light1=39。039。light2=39。039。車費沒超量程 when 01= light0=39。139。light1=39。039。light2=39。039。超出100元 when 10= light0=39。139。light1=39。139。light2=39。039。超出200元 when 11= light0=39。139。light1=39。139。light2=39。139。超出300元 when others=null。 end case。 end process C1。C2:process(distance_cout) variable q2:std_logic。 begin if distance_cout39。event and distance_cout=39。139。 then q2:=not q2。 end if。 case q2 is when 39。039。=light3=39。039。路程沒超量程 when 39。139。=light3=39。139。路程超出100Km when others=null。 end case。 end process C2。end bhv。library ieee。use 。use 。entity counter_of_taxi_fare is頂層模塊 port( clk_counter,clk_display : in std_logic。記路程和數(shù)碼管掃描的時鐘 stop,pause,start : in std_logic。外部控制信號,分別是中止清零,暫停,啟動信號 led : out std_logic_vector(7 downto 0)。數(shù)碼管譯碼輸出 ls138 : out std_logic_vector(2 downto 0)。數(shù)碼管選通地址 light0,light1,light2,light3 : out std_logic超量程指示燈 )。end counter_of_taxi_fare。architecture bhv of counter_of_taxi_fare isponent counter is port(clk,stop,pause,start:in std_logic。 distance_out:out std_logic_vector(15 downto 0)。 fare_out:out std_logic_vector(15 downto 0)。 distance_cout:out std_logic。 fare_cout:out std_logic )。end ponent counter。ponent counter_display is port( clk : in std_logic。 distance_in: in std_logic_vector(15 downto 0)。 fare_in : in std_logic_vector(15 downto 0)。 led7: out std_logic_vector(7 downto 0)。 ls138: out std_logic_vector(2 downto 0))。end ponent counter_display。ponent overflow is port(distance_cout,fare_cout:in std_logic。 light0,light1,light2,light3:out std_logic )。end ponent overflow。signal d,e:std_logic_vector(15 downto 0)。signal f,g:std_logic。beginu1:counter port map(clk=clk_counter,stop=stop,pause=pause,start=start,distance_out=d,fare_out=e,distance_cout=f,fare_cout=g)。u2:counter_display port map(clk=clk_display,distance_in=d,fare_in=e,led7=led,ls138=ls138)。u3:overflow port map(distance_cout=f,fare_cout=g,light0=light0,light1=light1,light2=light2,light3=light3)。end bhv。1 端口分析輸入:clk計數(shù)時鐘;en暫停(低電平有效);reset置初始值(低電平有效)。輸出:jinwei進(jìn)位輸出(每百米輸出一次高電平);d1,d2,d3,d4路程輸出,1到4分別對應(yīng)十米位,百米位,千米位,十千米位。2 功能:內(nèi)部定義計數(shù)變量s(路程),j(進(jìn)位),當(dāng)en為高電平時,每來一次時鐘上升沿s加1,當(dāng)十米位為9時下次加7,用于跳過16進(jìn)制數(shù)的a到f,同時令j置1,表示進(jìn)位;百米位,千米位,十千米位同樣處理,當(dāng)為該位10時加6。通過16位變量s計算路程,分四個4位端口輸出。3 仿真測試圖821計程器模塊仿真1 端口分析輸入:en 暫停(低電平有效);reset置初始值(低電平有效);jinwei進(jìn)位輸入,由計路程模塊產(chǎn)生,每百米計一次費d3,d4路程輸入,表示目前已行駛的公里數(shù),用于判斷單價。輸出:m1,m2,m3,m4費用輸出,1到4分別對應(yīng)分,角,元,十元。2 功能:內(nèi)部定義信號danjia用于表示每百