【正文】
時鐘信號,二是按鍵產生的時鐘信號,由數(shù)據(jù)選擇器控制。時鐘計數(shù)器模塊原理圖如圖421所示圖421時鐘計數(shù)器模塊原理圖時鐘計數(shù)器模塊符號圖如圖422圖422時鐘計數(shù)器模塊符號圖端口說明Clk_1:1HZ計數(shù)時鐘信號輸入端。Set_hour: 時鐘時設置輸入端。S_hour:計數(shù)器計數(shù)時鐘選擇端,當S_hour=0時計數(shù)時鐘為Clk_1,當S_hour=1時計數(shù)時鐘為Set_hour。60進制計數(shù)器模塊符號圖如圖423所示圖423 60進制計數(shù)器模塊符號圖端口說明:Clk_1: 計數(shù)時鐘輸入端。Cout:計數(shù)器進位輸出端Dout_l[3..0]: 計數(shù)值低四位輸出端(秒或分低位)。60進制計數(shù)器代碼library ieee。use 。 clr : in std_logic。 dout_l : out std_logic_vector (3 downto 0)。end。signal num2 : std_logic_vector (3 downto 0)。039。 num2 = 0000。039。event and clk_1 = 39。) then cout = 39。 if num11001 then num1 = num1 + 1。 if num2 0101 then num2 = num2 +1。 cout = 39。 end if。 end if。 end process。 dout_h = num2。60進制計數(shù)器功能仿真圖如圖424所示圖62460進制計數(shù)器功能仿真圖(2)24進制計數(shù)器模塊構成時計數(shù)器,clr清零計數(shù)器。Clr: 計數(shù)器清零端。Dout_h[3..0]: 計數(shù)值高四位輸出端(時高位)。use 。entity counter_24 is port (clk_1 : in std_logic。 cout : out std_logic。 dout_h : out std_logic_vector (3 downto 0) )。architecture bhv of counter_24 issignal num1 : std_logic_vector (3 downto 0)。begin process (clk_1, clr) begin if (clr =39。 ) then num1 = 0000。 cout = 39。 else if (clk_139。139。039。 else num1 = 0000。 end if。139。 num2 = 0000。 end if。 end process。 dout_h = num2。24進制計數(shù)器功能仿真圖如圖426所示圖426 24進制計數(shù)器功能仿真圖(3)數(shù)據(jù)選擇器模塊數(shù)據(jù)選擇器符號圖如圖427所示圖427數(shù)據(jù)選擇器符號圖端口說明:A: 計數(shù)時鐘輸入。Qout: 計數(shù)脈沖輸出端。數(shù)據(jù)選擇器代碼:library ieee。entity mux21b is port (a, b : in std_logic。 qout : out std_logic)。 architecture bhv of mux21b isbegin process (s) begin if s=39。 then qout = a。 end if。end。Com_out: 當整點是_out會輸出一分鐘高電平。use 。use 。 _out : out std_logic )。architecture bhv of par_1 isbegin process (data) begin if (data = 00000000) then _out = 39。 else _out = 39。 end if。end。Clk: 數(shù)碼管掃描時鐘。Select_wei[2..0]: 動態(tài)掃描位選擇輸出。use 。use 。 顯示數(shù)據(jù)輸入 clk : in std_logic。 數(shù)碼管八段輸出 select_wei : out std_logic_vector (5 downto 0) 數(shù)碼管位選 )。architecture bhv of disp_decode issignal num : std_logic_vector(2 downto 0)。begin 數(shù)碼管位選六進制計數(shù)器循環(huán)顯示六位數(shù)碼管 process (clk) begin if (clk39。139。 end if。 end if。 控制段選數(shù)據(jù)輸入 process (num) begin case (num) is when 000 = select_wei = 111110。 when 001 = select_wei = 111101。 when 010 = select_wei = 111011。 when 011 = select_wei = 110111。 when 100 = select_wei = 101111。 when 101 = select_wei = 011111。 when others = null。 end process。 when x1 = data_out = x06。 when x3 = data_out = x4f。 when x5 = data_out = x6d。 when x7 = data_out = x07。 when x9 = data_out = x6f。 end case。end。由于晶振頻率較大,故分頻所用的計數(shù)器為約翰遜計數(shù)器。由六分頻,八分頻,十分頻模塊級聯(lián)構成,下面將以六分頻為例進行說明。use . all。use . all。 clk_out : buffer std_logic )。architecture a of john_6 issignal tQ: std_logic_vector(2 downto 0)。 tQ(0) = not tQ(2)。 end process。039。139。 end process。六分頻模塊功能仿真圖如圖443所示圖443六分頻模塊功能仿真圖 主控制電路模塊 計數(shù)器控制模塊 此模塊根據(jù)按鍵狀態(tài)來控制計數(shù)器模塊,主要功能有控制定時器計數(shù),以及按鍵計數(shù)等功能。Clk_1: 1HZ時鐘信號輸入端。Turn: 時,分設置選擇。Clk_disp: 時鐘計數(shù)器時鐘信號提供端。Hour_s: 時鐘計數(shù),按鍵計數(shù)選擇端clkout_hour_t: 按鍵計數(shù)。計數(shù)器控制模塊代碼:library ieee。use 。entity control_counter is port (reset : in std_logic。 clk_1 : in std_logic。 hour_s :out std_logic。 turn : in std_logic。 clkout_hour_t : out std_logic。end。139。 minute_s =