【正文】
u7: count10 PORT MAP( rst = rst_ctrl, clk = clk_1, ena = ena_ctrl, count_out = datain_2, carry_out = clk_2 )。 u5: count10 PORT MAP( rst = rst_ctrl, clk = clk_100hz, ena = ena_ctrl, count_out = datain_1, carry_out = clk_1 )。 u3: key_debounce PORT MAP( clk = clk_1khz, key_in = key_2, key_out = keyde_2 )。 u1: fenpinclk PORT MAP( clkin = clk_48mhz, clkout1k = clk_1khz, clkout100 = clk_100hz )。 f=led_sum(1)。 d=led_sum(3)。 b=led_sum(5)。 sel_c=sel_sum(2)。 begin sel_a=sel_sum(0)。 signal sel_sum:std_logic_vector(2 downto 0)。 signal datain_1,datain_2,datain_3,datain_4,datain_5,datain_6:std_logic_vector(3 downto 0)。 signal clk_1khz,clk_100hz,keyde_1,keyde_2,rst_ctrl,ena_ctrl,l_ena_ctrl:std_logic。 en : OUT std_logic )。 sel : OUT std_logic_vector(2 downto 0)。 t4 : IN std_logic_vector(3 downto 0)。 t2 : IN std_logic_vector(3 downto 0)。 t0 : IN std_logic_vector(3 downto 0)。 END COMPONENT。 l_ena : IN std_logic。 END COMPONENT。 count_out : OUT std_logic_vector(3 downto 0)。 clk : IN std_logic。 END COMPONENT。 count_out : OUT std_logic_vector(3 downto 0)。 clk : IN std_logic。 END COMPONENT。 ena : OUT std_logic。 clk : IN std_logic。 COMPONENT control PORT( key_stsp : IN std_logic。 37 key_out : OUT std_logic )。 COMPONENT key_debounce PORT( clk : IN std_logic。 clkout100 : OUT std_logic )。 architecture Behavioral of miaobiao is COMPONENT fenpinclk PORT( clkin : IN std_logic。 ncs : out STD_LOGIC)。 a,b,c,d,e,f,g : out STD_LOGIC。 key_2 : in STD_LOGIC。 use 。 use 。 end Behavioral。 end if。 end if。 elsif ctrl = 011 then ctrl = 010。139。 end if。 when others = ctrl = ctrl。 when 001 = ctrl = 011。 elsif ctrl = 011 then ctrl = 001。 then if ctrl = 111 then ctrl = 011。 then if key_stsp = 39。event and clk = 39。 l_ena=ctrl(0)。 begin rst=ctrl(2)。 end control。 ena : out STD_LOGIC。 clk : in STD_LOGIC。 35 entity control is Port ( key_stsp : in STD_LOGIC。 use 。 程序如下: library IEEE。在秒表暫停計時的情況下,按下“ Split/Reset”鍵,秒表復(fù)位歸零。在秒表正常運行的情況下,如果按下“ Start/Stop”鍵,則秒表暫停計時;再次按下該鍵,秒表繼續(xù)計時。 7. 控制電路 控制電路起到的是一個狀態(tài)機的作用,事先設(shè)定好的狀態(tài)再根據(jù)按鍵的輸入進行狀態(tài)轉(zhuǎn)換來實現(xiàn)所需的功能。 key_out = (not k1) and k2。 end if。039。 34 end if。 end if。039。139。039。 begin process(clk,key_in) begin if clk39。 architecture Behavioral of key_debounce is signal t :STD_LOGIC_VECTOR(1 downto 0)。 key_out : out STD_LOGIC)。 entity key_debounce is Port ( clk : in STD_LOGIC。 use 。 6. 按鍵消抖 出于對實際電路操作時的考慮 :電路板上的鍵按下后不一定只能產(chǎn)生一個脈沖信號,可能按下的一瞬間就會產(chǎn)生多個脈沖導致輸出信號改變了多次,所以需要按鍵 消抖來避免這種情況的發(fā)生。 sel= t。 33 en = 39。 end case。 when 1001=led=0000100。 when 0111=led=0001111。 when 0101=led=0100100。 when 0011=led=0000110。 when 0001=led=1001111。 end process。 when others = data = 1111。 when 110 = data = t4。 when 011 = data = t2。 process(t,t0,t1,t2,t3,t4,t5) begin case t is when 000 = data = t0。 end if。139。 begin PROCESS(clk) begin if clk39。 architecture Behavioral of show is SIGNAL t:STD_LOGIC_VECTOR (2 downto 0):= 000。 en : out STD_LOGIC)。 sel : out STD_LOGIC_VECTOR (2 downto 0)。 entity show is Port ( clk : in STD_LOGIC。 use 。 程序如下: library IEEE。 5. 顯示電路 顯示電路相關(guān)的電路示意圖如下: 31 由此可見,顯示電路由多個部分組成, 分別是:三八譯碼器、數(shù)據(jù)選擇器 并且要實現(xiàn)段選和位選的功能。 end process。 then data_out = data_in。 architecture Behavioral of locker is begin process(data_in,l_ena) begin if l_ena = 39。 data_out : out std_logic_vector(3 downto 0))。 entity locker is Port ( data_in : in std_logic_vector(3 downto 0)。 use 。 程序如下: library IEEE。首先它只有三個端口,使能端 l_ena、數(shù)據(jù)輸入端 data_in、數(shù)據(jù)輸出端 data_out。 end Behavioral。 end if。 end if。139。 if tmp=5 then tmp = 0000。 then c = 39。 elsif rising_edge(clk) then if ena=39。139。 carry_out = c。039。)。 architecture Behavioral of count6 is signal tmp : std_logic_vector (3 downto 0) := (others=39。 carry_out : out STD_LOGIC)。 ena : in STD_LOGIC。 entity count6 is Port ( rst : in STD_LOGIC。 use 。 程序如下: library IEEE。 3. 六進制計數(shù)器 29 六進制計數(shù)器 ,設(shè)計原理和十進制計數(shù)器基本相同 : rst 清零端, clk 記數(shù)信號輸入端, ena使能端, count_out 記數(shù)結(jié)果輸出, carry_out 進位端。 end process。 end if。 else tmp = tmp + 1。 c = 39。039。139。 then tmp=0000。 process(clk,ena,rst) begin if rst=39。 begin count_out= tmp。 signal c : std_logic := 39。039。 end count10。 count_out : out STD_LOGIC_VECTOR (3 downto 0)。 clk : in STD_LOGIC。 use 。 use 。 如十進制’ 09‘記數(shù)用二進制表示“ 0000”“ 0001”“ 0010”“ 0011”“ 0100” 28 “ 0101”“ 0110”“ 0111”“ 1000”“ 1001”四位輸出當最高位為 1 且最低位為1 時滿足條件,進位端 carry_out 就為’ 1‘表示進一位其他情況取’ 0‘,從而滿足要求。 end Behavioral。 end process。 end if。 clkout100_tmp = not clkout100_tmp。139。 process(clkout1k_tmp)is begin if clkout1k_tmp39。 end process。 end if。 clkout1k_tmp = not clkout1k_tmp。139。 begin process(clkin)is begin if clkin39。 signal clkout1k_tmp,clkout100_tmp:STD_LOGIC:= 39。 architecture Behavioral of fenpinclk is signal ter0 : integer range 0 to 23999 := 0。 clkout100 : out STD_LOGIC)。 27 entity fenpinclk is Port ( clkin : in STD_LOGIC。 use 。 程序如下: library IEEE。所以應(yīng)該先設(shè)計一個 24000 進制的計數(shù)器,當計數(shù)器 24000 個時鐘,分頻輸出信號 clkout1k 取反,這樣,可以對輸出信號 48000 次分頻,從而得到 1khz 的信號。根據(jù)顯示部分的要求,我們還需要 1khz 的掃描控制信號,因此在分頻器部分還要產(chǎn)生1khz 的信 號。 模塊設(shè)計: 1. 分頻器 分頻器的功能是提供計數(shù)器的時鐘信號以及數(shù)碼管動態(tài)掃描顯示部分的時鐘信號。從上面的設(shè)計思 路我們可以確定電路由分頻器、控制器、計數(shù)器、鎖存器和顯示電路組成,考慮到實際操作的效果,還加上了按鍵消抖電路。 接下來,就是對整體電路