【正文】
而成。 USE 。 ENTITY PULSE IS PORT(CLK0:IN STD_LOGIC。 END PULSE。 VARIABLE FULL :STD_LOGIC。EVENT AND CLK0=39。 THEN IF CNT=100 THEN CNT:=000 。139。 FULL:=39。 END IF。 FOUT=FULL。 END ONE。 計程模塊: 計程模塊的框圖: c lk sSSWRLC [7. .0]JCins t2SSLC [7. .0]LC J F BZLC J F BZins t4 此模塊的功能是計算出租車行駛的路程。 計程模塊的 VHDL 程序 (1) 計程程序 library ieee。 use 。 LC:BUFFER std_logic_vector(7 downto 0))。 architecture one of JC is SIGNAL Q1,Q0:std_logic_vector(3 downto 0)。 begin SW:=SSamp。 IF SW=00 OR SW=01 THEN Q1=0000。 ELSIF SW=11 THEN Q1=Q1。 ELSIF CLKS39。139。Q0=0000。Q0=0000。Q0=Q0+1。 END IF。 (2) 計程標志程序 library ieee。 use 。 SS 開始 /復位信號 , LC:IN STD_LOGIC_VECTOR(7 DOWNTO 0)。 end entity LCJFBZ。039。039。139。 END PROCESS。 計程模塊仿真結果: 從波形圖可以看出在時鐘的控制下當 SS 為低電平的時候 LC 為零,當 SS 為高電平且 WR 為高電平的時候 LC 開始計數(shù),當計到大于三的時候輸出了 LCJFBZ為高電平。在出租車行進中,如果車輛停止等待,計數(shù)器 則在信號 clk的上升沿進行加計數(shù),當累計等待時間超過 2(不包括 2分鐘 )分鐘時,輸出標志 DDJFBZ正脈沖信號。 USE 。 ENTITY DDZT IS PORT(CLK,SS:IN STD_LOGIC。 DDJFBZ:OUT STD_LOGIC。 END ENTITY DDZT。 BEGIN IF SS=39。 THEN Q1:=0000。DDJFBZ=39。 ELSIF DDBZ=39。 THEN IF CLK=39。 AND CLK39。Q0:=0000。Q0:=0000。Q0:=Q0+1。 IF(Q10 OR Q03) THEN DDJFBZ=39。 END IF。 END IF。DDSJ(3 DOWNTO 0)=Q0。 END ONE。 : : SSDNLC [7. .0]D D SJ [7. .0]LC J F BZD D J F BZF Y [7. .0]JFins t3 費用計數(shù)器模塊用于出租車啟動后,根據(jù)行駛路程和等待時間計算費用。 VHDL的程序 : library IEEE。 use 。 END。 VARIABLE SA,SB : type_bcdx4。 VARIABLE SOUT : std_logic_vector(11 downto 0)。039。 SOUT:=(others=39。)。039。 AIN(i*4+3 downto i*4))+(39。 amp。 CI(i))。139。 else SB(i) := SA(i)。 CI(i+1) := SB(i)(4)。 end loop。 END FUNCTION bcd_add8。 library IEEE。 use 。 ENTITY JF is PORT( SS:IN STD_LOGIC。 白天黑夜控制,高電平夜間,低電平白天 LC:IN std_logic_vector(7 downto 0)。 等待時間 LCJFBZ:IN STD_LOGIC。 等待計費標志,高電平時等待開始 計費,低電平不計費 FY:OUT STD_LOGIC_VECTOR(7 DOWNTO 0))。 architecture ONE of JF is BEGIN 討論白天 /黑夜?路程計費?等待計費? PROCESS(SS,DN,LC,DDSJ,DDJFBZ,LCJFBZ) VARIABLE FY1 :STD_LOGIC_VECTOR(11 DOWNTO 0)。039。 ELSIF DN=39。 THEN 白天時 IF LCJFBZ=39。 THEN 起始價 FY1(11 DOWNTO 4):=(OTHERS=39。)。 ELSE 加收路程費 FY1:=bcd_add8(LC,LC)。 多一個脈沖加收 3,則變成 LC*3 END IF。039。039。 FY1(4 DOWNTO 0):=10010。 FY1:=bcd_add8(FY1,LC)。 每一個脈沖加收 4,則變成 LC*4 END IF。039。039。 不 加收 ELSE 加收路程費 FY1:=bcd_add8(FY1,DDSJ)。 一超過等待收費時間,就立即加收等待時的每個脈沖加 2 END IF。039。 不加收 ELSE 加收路程費 FY1:=bcd_add8(FY1,DDSJ)。 FY=FY1(7 DOWNTO 0)。 END ONE。 : : din [7. .0] dout 1[ 6. .0]dout 0[ 6. .0]Y M Qins t6 VHDL程序 : library ieee。 use 。 entity YMQ is port(din:in std_logic_vector(7 downto 0)。 dout0:out std_logic_vector(6 downto 0))。 architecture one of YMQ is begin process(din) begin case din(7 downto 4) is when 0000 =dout1=1111110。 when 0010 =dout1=1101101。 when 0100 =dout1=0110011。 when 0110 =dout1=1011111。 when 1000 =dout1=1111111。 when others =dout1=0000000。 case din(3 downto 0) is when 0000 =dout0=1111110。 when 0010 =dout0=1101101。 when 0100 =dout0=0110011。 when 0110 =dout0=1011111。 when 1000 =dout0=1111111。 when others =dout0=0000000。 end process。 : 控制模塊: 控制模塊的框圖: 控制模塊用于 對數(shù)碼管里程、時間、費用顯示的選擇,起到位選的作用,實現(xiàn)了 數(shù)碼管動態(tài)顯示 ,節(jié)省了芯片的資源。 use 。 entity sel1 is port(clk1:in std_logic。 end sel1。 begin if clk139。139。 else t:=t+1。 end if。 end process。 (2)sel2模塊 library ieee。 entity sel2 is port(sel2:in std_logic_vector(1 downto 0)。 end sel2。 when 01=s2=101。 when others=s2=ZZZ。 end process。 : (1)sel1模塊 (2)sel2模塊 從波形圖可以看出 當片選信號是 00時,輸出選擇記程輸出。 當片選信號是 10時,輸出選擇等到時間輸出。頂層就是將各分模塊用 VHDL語言或者是圖形方法連接起來,便可實現(xiàn)系統(tǒng)電路。 use 。 use 。 dnpd:out std_logic。 weix:out std_logic_vector(2 downto 0))。 architecture one of czc is ponent bz PORT(AJ:IN STD_LOGIC。 end ponent。 FOUT:OUT STD_LOGIC)。 ponent ddzt PORT(CLK,SS:IN STD_LOGIC。 DDJFBZ:OUT STD_LOGIC。 end ponent。 LC:BUFFER std_logic_vector(7 downto 0))。 ponent lcjfbz port(SS:in std_logic。 LCJFBZ:OUT std_logic)。 ponent jf PORT( SS:IN STD_LOGIC。 LC:IN std_logic_vector(7 downto 0)。 LCJFBZ:IN STD_LOGI