【正文】
end scan2。 entity scan2 is port (rst,clk : in std_logic。圖4-10 scan2組件程序代碼the ieee standard 1164 package, declares std_logic, rising_edge(), etc. library ieee。 end arch。when others = mux_out = 1011111。 pa=’0’。pb=’0’。pc=’0’。pd=’0’。 case sel is when 00 = mux_out = a。 end scan4。 entity scan4 is port (rst,clk : in std_logic。 scan4組件程序代碼 the ieee standard 1164 package, declares std_logic, rising_edge(), etc. library ieee。視覺暫留效應讓我們感覺到,相隔(1/32)s亮一次的燈似乎一直都亮著。市面上賣的4個串聯(lián)在一起的四合一七段顯示器組,有7個端口a,b,c,d,e,f,g,另外4個電源引腳分別決定哪一個七段顯示器亮,另一只引腳接Vcc。e for error display end arch。 entity bin2led is port (bin : in std_logic_vector (3 downto 0)。 bin2led 組件程序代碼library ieee。圖4-8 bin2led組件 在一般電路中,數(shù)值均以二進制的形式存儲與計算,但是要將其輸出至七段顯示器顯示時,則必須提供一個電路模塊專門將二進制轉(zhuǎn)換成十進制供輸出使用。 end process。 when 10|11|12|13|14|15|16|17|18|19 = ten=0001。 when 9|19 = one=1001。 when 5|15 = one=0101。 when 1|11|21 = one=0001。interger number ten : out std_logic_vector (3 downto 0) 。 use 。由圖47可知,當輸入整數(shù)在0~59的范圍時,個位數(shù)與十位數(shù)的值均正確;而超出范圍時,個位數(shù)與十位數(shù)的值則顯示“E”以警告錯誤。 end case。 when 30|31|32|33|34|35|36|37|38|39 = ten=0011。 end case。 when 7|17|27|37|47|57 = one=0111。 when 3|13|23|33|43|53 = one=0011。 ndividual bit end i60bcd。 use 。圖4-6 i60bcd組件 為了計算方便,前面都以整數(shù)形式來處理時間,但在一般電路中,數(shù)值均以二進制的形式存儲,所以需要設計一個查表程序來將秒數(shù)或分數(shù)的0~59共60個整數(shù)轉(zhuǎn)換成二進制編碼的十進制(BCD)表示法,以便將來轉(zhuǎn)換成七段顯示器格式輸出。 stop_hour=a_hour。 end if。 disp=’1’。 a_sec=59。 a_min=59。 disp=’1’。 if min_tune=’1’ then if a_min=59 then a_min=0。 elsif rising_edge(hz1) then if stop=’1’ and ok=’0’ then –setting if sec_tune=’1’ then if a_sec=59 then a_sec=0。 architecture arch of stop_watch is signal a_sec,a_min: integer range 0 to 59。 stop_hour: out integer range 0 to 23。keep pushing to declare stop setting sec_tune: in std_logic。 use 。當ok=’1’時,則停止設定,顯示時間為所設定的計時起始時間,并開始進行計時,直到計時器顯示00:00:00為止,則送出終止指針index=’1’。以1Hz的顯示速率來調(diào)整時分秒的顯示,可以適應視覺要求。 end arch。 end process tuning。 end if。 end if。 end if。 hour_tmp=0。 define the signal_structure and _flow of the device architecture arch of alarm_set is signal sec_tmp,min_tmp: integer range 0 to 59。 keep pushing to declare minute tuning hour_tune: in std_logic。 entity alarm_set is port( rst,hz1: in std_logic。 libray and package declaraction library ieee。以1Hz的顯示速率來調(diào)整時分秒的顯示,可以適應視覺要求。 times=time。keep counting full=’0’。 full=’0’。 full: out std_logic)。 use 。 24組件的程序代碼。 圖4-3 count24組件 count24組件的結(jié)構與count60的類似,只是將除以60改為除以24,并在接收60分進位指針carry時,檢查是否同時為23小時,再決定進位與否。 end process。carry_out signal else time= time + 1。 begin process for 60 seconds counting process (rst,carry) begin if rst=’1’ then time = 0。initialization times: out integer range 0 to 59。 use 。if_then語句與適當?shù)臈l件進位適合時鐘計時,十進制的進位歸零必須配合個位數(shù)的進位歸零,而個位數(shù)的進位歸零則不必配合十進制的進位歸零,所以在if_then語句中,十進制的計數(shù)動作應放在內(nèi)層。 信號仿真結(jié)果如圖42所示。 end if。 architecture arch of div1024 is input: clk output: f1hz signal count : integer range 0 to 1023。 use 。另外,還需要一個除以1024的分頻器,用來實現(xiàn)系統(tǒng)輸入信號產(chǎn)生一個1Hz的時鐘信號。 1Hz_generator組件 為了便于時鐘計數(shù),需要1Hz的時鐘信號。 ponent bin2ledi/o declaraction of ponent bin2led port (bin : in std_logic_vector (3 downto 0)。 a,b: in std_logic_vector(6 downto 0)。 pa,pb,pc,pd : out std_logic。decimal bit one : out std_logic_vector (3 downto 0) )。decimal bit one : out std_logic_vector (3 downto 0) )。 disp: out std_logic)。pushing button to tune minutes hour_tune: in std_logic。system clock 1hz stop: in std_logic。 keep pushing to declare hour tuning sec,min: out integer range 0 to 59。clock alarm,ok: in std_logic。initialization times: out integer range 0 to 23。 full: out std_logic)。 1hz output signal end ponent。表4-1 my_pkg組件包程序代碼library ieee。 電子鐘外觀 電子鐘的外觀示意圖如圖41所示。 電子鐘功能概述 本章將設計一個顯示時(2位)、分(2位)、秒(2位)共6個數(shù)字的多功能電子鐘。因此將其除以210=1024,即得1Hz的秒鐘信號,秒計滿60即得1分鐘,分計滿60便得1小時的信號,小時計滿24即得一天。我們將所有組件收集在同一個程序包my_pkg中。from system clock(1024hz) f1hz : out std_logic)。initialization times: out integer range 0 to 59。 from 1hz input clock or the full_index of second/minute rst: in std_logic。 ponent alarm_seti/o declaraction of ponent set port( rst,hz1: in std_logic。 keep pushing to declare minute tuning hour_tune: in std_logic。 ponent stop_watchi/o declaraction of ponent stop port(rst,hz1: in std_logic。pushing button to tune seconds min_tune: in std_logic。 index: out std_logic。interger number ten : out std_logic_vector (3 downto 0) 。interger number ten : out std_logic_vector (3 downto 0) 。 a,b,c,d: in std_logic_vector(6 downto 0)。 ponent scan2i/o declaraction of ponent scan2 port (rst,clk : i