【正文】
hour_tune: in std_logic。 display seconds and minutes p1,p2,p3,p4:out std_logic。 architecture模塊 此處,我們定義一些功能模塊(blocks)間整體共享的傳遞信號,以整合所有塊的功能。 architecture模塊的VHDL碼 architecture arch of clock is global signals flowing among different circuit blocks signal hz1:std_logic。 signal a_hour: integer range 0 to 23。 signal hour :integer range 0 to 23。 signal hour7_one,hour7_ten: std_logic_vector(6 downto 0)。首先將1024Hz的系統(tǒng)輸入脈沖除以1024得到1Hz的基本秒輸入,然后除以60得分數,再除以60得小時數,再除以24得一個滿日指針,節(jié)。 index of 60 minutes fully counted signal full_hour:std_logic。 to count from 0 to 24 hours and get full_hour u3:count24 port map(rst=rst,carry=full_min,times=n_hour,full=full_hour)。 stop_watch block的VHDL碼 stop watch setting and down_counting stop_w: block input:rst,hz1,stop,ok,sec_tune,min_tune,hour_tune output:s_sec,s_min,s_hour,stop_index begin u4:stop_watch port map(rst=rst,hz1=hz1,stop=stop,ok=ok,sec_tune= sec_tune,min_tune=min_tune,hour_tune=hour_tune,stop_sec= s_sec,stop_min=s_min,stop_hour=s_hour,index= stop_index,disp=stop_disp)。 end process p1。 alarm_setting block的VHDL碼 alarm_setting:block input : rst,sec_tune,min_tune,hour_tune,alarm,ok output: a_sec,a_min,a_hour,alarm_index,led_alarm begin u5:alarm_set port map(rst=rst,hz1=hz1,alarm=alarm,ok=ok,sec_tune= sec_tune,min_tune=min_tune,hour_tune= hour_tune,sec=a_sec,min=a_min,hour=a_hour)。 end if。 p2:process(rst,alarm_index) begin if rst=’1’ then led_alarm=’0’。 end block alarm_setting。轉換成BCD形式。 hour=s_hour。 else second=n_sec。 end if。 u8:i24bcd port map(interg=hour,ten=hour_ten,one=hour_one)。 block模塊的程序代碼。 u14:bin2led port map(bin=min_ten,led=min7_ten)。 u18: scan2 port map(rst=rst,clk=clk,a=hour7_one, b=hour7_ten,mux_out=seg2,pa=p5,pb=p6)。信號仿真結果如圖412所示。 圖4-13。直到鬧鈴設定時間到達,則警示燈led_alarm亮,此信號可用來觸發(fā)鬧鈴。 當時間進行到7s時,設定stop=’1’,sec_tune=’1’,因此輸出時間second變成定時器設定時間s_sec,直到5s時ok=’1’,仍然顯示定時器時間,直到s_sec為0,此時led_stop=’1’,而時間顯示則還原為n_sec=18s。 u16:bin2led port map(bin=hour_ten,led=hour7_ten)。 u12:bin2led port map(bin=sec_ten,led=sec7_ten)。 掃描多路輸出功能模塊 為了節(jié)省IC的輸出引腳及耗電量,可以將4組數字輸出或2組數字輸出作為多路輸出,故所需引腳數由28降至7個,14降至7個;另外使用四合一型七段顯示器與視覺暫留效應可降低顯示耗電量3/4。tranformed to bcd format u6:i60bcd port map(interg=second,ten=sec_ten,one=sec_one)。 hour=n_hour。 minute=a_min。 輸出時間的顯示條件 output block的VHDL碼 to decide which time displayed and transformed to bcd format output:block input:clk,stop_disp,alarm_disp input:s_sec,s_min,s_hour,a_sec,a_min,a_hour,n_sec, n_min, n_hour output:second,minute,hour begin process(clk,stop_disp,alarm_disp) begin if rising_edge(clk) then if stop_disp=’1’ then second=s_sec。另外,在定時器計時過程中,為了觀察進行時間,必須顯示正在計時的剩余時間。 end if。 alarm_disp=(alarm and not ok) and not alarm_index。 elsif alarm=’1’ and ok=’1’ then if (a_sec=n_sec and a_min=n_min and a_hour=n_hour) then alarm_index=’1’。 鬧鐘設定與時間對比功能模塊 在此模塊中,然后確認指針開關ok處于on(’1’)時,開始進行目前正常時間與鬧鐘設定時間的對比動作,對比完成即設定alarm_index為1,然后再進一步標示出鬧鐘設定狀態(tài)led_alarm = ’1’。 elsif rising_edge(stop_index) then led_stop=’1’。 定時器設定與計時功能模塊 在此模塊中,并執(zhí)行計時動作,取得計時終止指針,然后由計時終止指針標示出計時終止狀態(tài)led_stop =’1’。 to count from 0 to 60 seconds and get full_sec u1:count60 port map(rst=rst,carry=hz1,times=n_sec,full=full_sec)。 normal_counting block的VHDL碼 normal counting from 00:00:00 to 23:59:59 normal_counting:block input : rst,clk output: hz1, n_sec,n_min,n_hour signal full_sec:std_logic。 signal alarm_disp,stop_disp : std_logic。 signal hour_one,hour_ten: std_logic_vector(3 downto 0)。 signal s_hour: integer range 0 to 23。 signal n_hour: integer range 0 to 23。諸如: hz1: 表示1s的時鐘; n_sec, n_min: 表示正常持續(xù)不斷的計數時間——分與秒,整數形式; n_hour: 表示正常持續(xù)不斷的計數時間——小時,整數形式; a_sec, a_min: 表示鬧鐘的計數時間——分與秒,整數形式; a_hour: 表示鬧鐘的計數時間——時,整數形式; s_sec, s_min: 表示定時器的計數時間——分與秒,整數形式; s_hour: 表示定時器的計數時間——小時,整數形式; second, minute: 表示被選擇輸出的計數時間——分與秒,整數形式; hour: 表示被選擇輸出的計數時間——時,整數形式; sec_one,sec_ten,min_one,min_ten:表示被選擇輸出的計數時間——分與秒的個位數與十位數,BCD形式; hour_one, hour_ten:表示被選擇輸出的計數時間——小時的個位數與十位數,BCD形式; sec7_one, sec7_ten, min7_one, min7_ten:表示被選擇輸出的計數時間——分與秒的個位數與十位數,七段顯示器形式;hour7_one,hour7_ten:表示被選擇輸出的計數時間——分與秒的個位數與十位數,七段顯示器形式; stop_index: 表示定時器計時終了的指針; alarm_index:表示鬧鐘的設定時間結束的指針。display hours p5,p6: out std_logic)。 led to show alarm time reached led_stop: out std_logic。 push button to confirrn any setting operation sec_tune: in std_logic。power reset to initialize clk: in std_logic。 use 。 另外還有許多組件放在my_pkg程序包中,故應加上一行: use 。 library ieee。 reset: 系統(tǒng)內部重置信號; clock: 由外接信號發(fā)生器提供1Hz的系統(tǒng)時鐘信號; alarm: 鬧鐘設定按鍵信號; stop: 定時器設定動作按鍵; ok: 任何設定動作的確認鍵; sec_tune: 秒數調整的按鍵信號; min_tune: 分數調整的按鍵信號; hour_tune: 時數調整的按鍵信號。顯示耗電量節(jié)省了3/4。 end if。 when 11 = pa=’0’。pb=’0’。 case sel is when 00 = mux_out = a。