【正文】
實際里程 累計值 temp0 加 1(單位: 100m) end if。 end process p1。 p2: process(temp0,clkin) 進程 p2, temp0 大于起步里程時, temp1 計數(shù) begin if rising_edge (clkin) then 若 clkin有上升沿,則 if (temp0=licheng) then – 若 temp0=licheng(起步里程 ),則 if (temp1=conv_std_logic_vector(4,4)) then – temp1 的值為 4,則 temp1= (others=39。039。)。 temp1復 0,(即 temp1的模為 5,對應 500m) else temp1=temp1+39。139。 否則, temp1的值加 1 end if。 end if。 end if。 end process p2。 clkout=39。139。 when (temp1=conv_std_logic_vector (4,4)) else39。039。temp1 的值為 4 時進位 7 輸出 clkout為 1 length=licheng when (temp0=licheng) else temp0。當 temp0=licheng 時, length 顯示licheng,否則顯示實際計數(shù)值 temp0 end two。 仿真波形如圖 4: 圖 4 ( 4) 計數(shù)器 C 的 vhdl文件及仿真 library ieee。 use 。 use 。 use 。 此句在 Altera的 MAX+plusⅡ下,無效 use 。 entity t_c is 實體名 t_c port( hourin:in std_logic。 reset:in std_logic。 clkin:in std_logic。 500m 脈沖作為輸入的 clkin 信號 dip:in std_logic_vector(1 downto 0)。 用 dip 設(shè)置起步價格 money:out std_logic_vector(12 downto 0))。 價款( money)作為輸出信號 end t_c。 architecture behave of t_c is signal qibu:std_logic_vector(12 downto 0)。 13 位內(nèi)部信號 qibu:存 放起步價格數(shù)據(jù) signal temp0:std_logic_vector(12 downto 0)。13 位內(nèi)部信號 temp0存放 500m脈沖累計數(shù) begin with dip select 用 dip 的值選擇起步價格 qibu qibu=conv_std_logic_vector (50,13) when 00, 00 檔: 元起步價 conv_std_logic_vector (60,13) when 01, 01 檔: 元起步價 conv_std_logic_vector (80,13) when 10, 10 檔: 元起步價 conv_std_logic_vector (100,13) when others。 11 檔: 元起步價 process (clkin) 進程, 500m 脈沖加法計數(shù)器 begin if(reset=39。039。) then temp0=(others=39。039。)。 elsif rising_edge (clkin) then 若 clkin有上升沿,則 if hourin=39。039。 then 若輸入端 hourin 為 0 時,則 temp0=temp0+0110。 temp0加 6 else temp0=temp0+1000。 否則 temp0加 9 end if。 end if。 8 c lkre s ets etm inenm indaout[6..0]s ec ondin s t21end process。 money=qibu+temp0。 money顯示起步加 temp0 end behave。 仿真波形如圖 5: 圖 5 (二) 計時部分 用到的模塊 圖 6 各個模塊的作用 ( 1) Second 模塊作用 : 輸入 100m 脈沖信號 oclk 作為 “秒 ”輸入 ; 調(diào) “分 ”端口 setmin 用于設(shè)定 “分 ”; 對秒輸入進行 60 分頻,輸出 enmin 即 “分 ”信號 ; 輸出 “秒 ”數(shù)據(jù) 。 ( 2) Minute 模塊作用 : 輸入 enmin 即 “分 ”信號 ; 調(diào) “時 ”端口 sethour 用于設(shè)定 “時 ”; 對分輸入進行 60 分頻,輸出 enhour 即 “時 ”信號 ; 輸出 “分 ”數(shù)據(jù) 。 ( 3) hour 模塊作用 : 輸入 enhour 即 “時 ”信號 ; 輸出 “時 ”數(shù)據(jù) 。 各個模塊的 vhdl文件及仿真 ( 1) Second 模塊 的 vhdl文件及仿真 LIBRARY ieee。 use 。 use 。 ENTITY second IS PORT( clk, reset,setmin : IN STD_LOGIC。 enmin : OUT STD_LOGIC。 daout: out std_logic_vector (6 downto 0))。 END entity second。 ARCHITECTURE fun OF second IS SIGNAL count: STD_LOGIC_VECTOR( 6 downto 0)。 SIGNAL enmin_1,enmin_2:STD_LOGIC。 BEGIN daout = count。 enmin_2=(not setmin and clk)。 把 setmin信號取反與 clk信號相與結(jié)果送入 enmin_2 9 enmin=(enmin_1 or enmin_2)。 把 enmin_1信號與 enmin_2信號相或結(jié)果送入 enmin process ( clk , reset , setmin) begin if (reset=39。039。) then count = 0000000。 復位 elsif (clk 39。event and clk=39。139。) then 判斷上升 沿 if (count(3 downto 0)=1001) then 如果 count低四位為 9 if (count 1660) then 如果 count 小于 60 if (count=1011001) then 如果 count等于 59 enmin_1=39。139。 “分 ”信號輸出 1 個脈沖 count=0000000。 秒歸零 ELSE count=count+7。 秒數(shù)據(jù)加 7 end if。 else count=0000000。 end if。 elsif (count 1660) then count = count+1。 enmin_1=39。039。 after 100 ns。 延時 100ns后將 0送入 enmin_1 else count=0000000。 end if。 end if。 end process。 END fun。 仿真波形如圖 7: 圖 7 ( 2) Minute 模塊 的 vhdl文件及仿真 LIBRARY ieee。 use 。 use 。 ENTITY minute IS PORT( clk, clk1,reset,sethour : IN STD_LOGIC。 enhour : OUT STD_LOGIC。 daout: out std_logic_vector (6 downto 0))。 END entity minute。 ARCHITECTURE fun OF minute IS SIGNAL count: STD_LOGIC_VECTOR( 6 downto 0)。 10 SIGNAL enhour_1,enhour_2:STD_LOGIC。 BEGIN daout = count。 enhour_2=(not sethour and clk1)。 enhour=(enhour_1 or enhour_2)。 process ( clk,reset,sethour) begin if (reset=39。039。) then count = 0000000。 elsif (clk39。 event and clk=39。139。) then if (count(3 downto 0)=1001) then if (count 1660) then if (count=1011001) then enhour_1=39。139。 count=0000000。 ELSE count=count+7。 end if。 else count=0000000。 end if。 elsif(count 1660) then count = count + 1。 enhour_1=39。039。 after 100 ns。 else count=0000000。 end if。 end if。 end process。 END fun。 仿真波形如圖 8: 圖 8 ( 3) hour 模塊 的 vhdl文件及仿真 LIBRARY ieee。 use 。 use 。 ENTITY hour IS PORT( 11 clk,reset: IN STD_LOGIC。 daout: out std_logic_vector (5 downto 0))。 END entity hour。 ARCHITECTURE fun OF hour IS SIGNAL count: STD_LOGIC_VECTOR( 5 downto 0)。 BEGIN daout = count。 process ( clk,reset) begin if (reset=39。039。) then count = 000000。 elsif (clk39。 event and clk=39。139。) then if (count(3 downto 0)=1001) then if (count 1623) then count=count + 7。 else count=000000。 end if。 elsif(count 1623) then count = count + 1。 else count=000000。 end if。 end if。 end process。 END fun。 仿真波形如圖 9: 圖 9 (三) 數(shù)碼管顯示部分 1. 用到的模塊 圖 10 s ec [6. .0]m in[ 6. .0]hou r[5. .0]c lk _s c anSEG[ 7. .0]D IP[ 7. .0]hou routc 47ins t13D in1 [12. .0]D in2 [12. .