VHDL數(shù)字時鐘實驗報告_第1頁
VHDL數(shù)字時鐘實驗報告_第2頁
VHDL數(shù)字時鐘實驗報告_第3頁
VHDL數(shù)字時鐘實驗報告_第4頁
VHDL數(shù)字時鐘實驗報告_第5頁
已閱讀5頁,還剩16頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、.VHDL數(shù)字時鐘設(shè)計一、實驗目的: 進一步練習VHDL語言設(shè)計工程的建立與仿真的步驟和方法、熟悉VHDL語言基本設(shè)計實體的編寫方法。同時,在已有知識的基礎(chǔ)上,簡單綜合編寫程序,仿制簡單器械。二、實驗環(huán)境: PC個人計算機、Windows XP操作系統(tǒng)、Quartus II集成開發(fā)環(huán)境軟件。三、設(shè)計要求:運用VHDL語言編寫一個數(shù)字鐘,具體要求: 1. 具有時、分、秒計數(shù)的十進制數(shù)字顯示功能,以24小時循環(huán)計時。2. 具有手動調(diào)節(jié)小時,分鐘的功能。3. 具有鬧鐘的功能,能夠在設(shè)定的鬧鐘時間發(fā)出鬧鈴聲。四、實驗步驟:1. 定義輸入輸出信號量port( clk:in std_logic; -時鐘

2、speak:out std_logic; -鈴 dout:out std_logic_vector(7 downto 0); -晶體管顯示 setclk:in std_logic_vector(2 downto 0); -操作按鈕 d1,d2,d3,d4,d5,d6: out std_logic); -六個晶體管 2. 定義結(jié)構(gòu)體中的信號量 signal sel:std_logic_vector(2 downto 0); signal hou1:std_logic_vector(3 downto 0); -時分秒的個位和十位 signal hou2:std_logic_vector(3 dow

3、nto 0); signal min1:std_logic_vector(3 downto 0); signal min2:std_logic_vector(3 downto 0); signal seth1:std_logic_vector(3 downto 0); signal seth2:std_logic_vector(3 downto 0); signal setm1:std_logic_vector(3 downto 0); signal setm2:std_logic_vector(3 downto 0); signal sec1:std_logic_vector(3 downt

4、o 0); signal sec2:std_logic_vector(3 downto 0); signal h1:std_logic_vector(3 downto 0); signal h2:std_logic_vector(3 downto 0); signal m1:std_logic_vector(3 downto 0); signal m2:std_logic_vector(3 downto 0); signal s1:std_logic_vector(3 downto 0); signal s2:std_logic_vector(3 downto 0); signal sph1,

5、sph2,spm1,spm2,sps1,sps2:std_logic_vector(3 downto 0); signal count_sec:std_logic_vector(9 downto 0); signal sec_co:std_logic; signal co1,co2,co3,co4:std_logic; -進位 signal switch:std_logic_vector(1 downto 0); -表示狀態(tài) 3. 分頻模塊 用來定義秒count_sec用來計時鐘個數(shù),當count_sec=1111111111時,及得到1Hz信號。代碼如下: process (clk) is-

6、define a second begin if(clkevent and clk=1)then if(count_sec=1111111111)then count_sec=0000000000; sec_co=1; else count_sec=count_sec+1; sec_co=0; end if; end if; end process;4時鐘正常走時模塊該模塊使用6個進程實現(xiàn),分別為秒個位計時、秒十位計時、分個位計時、分十位計時、時個位計時、時十位計時。 process(sec_co) is-秒個位 begin if switch=00 then-正常狀態(tài) if sec_co=1

7、 then if sec2=1001 then sec2=0000; co1=1; else sec2=sec2+1; co1=0; end if; end if; elsif switch=01 then-調(diào)時狀態(tài) sec2=0000; end if; end process; - process (co1) is-秒十位 begin if switch=00 then if co1event and co1=1 then if (sec1=0101)then sec1=0000; co2=1; else sec1=sec1+1; co2=0; end if; end if; elsif s

8、witch=01 then sec1=0000; end if; end process; - process (co1,co2) is-分鐘個位 begin if switch=00 then if co2event and co2=1 then if min2=1001 then min2=0000; co3=1; else min2=min2+1; co3=0; end if; end if; elsif switch=01 then min2=setm2; end if; end process; - process (co3) is-分鐘十位 begin if switch=00 t

9、hen if co3=1 then if min1=0101 then min1=0000; co4=1; else min1=min1+1; co4=0; end if; end if; elsif switch=01 then min1=setm1; end if; end process; - process(co4)-小時 begin if switch=00 then if co4=1 then if (hou1=0010) then-小時十位為2時,個位滿3進一 if(hou2=0011)then hou2=0000; hou1=0000; else hou2=hou2+1; en

10、d if; else-小時十位為0或1,個位滿9進一 if(hou2=1001)then hou2=0000; hou1=hou1+1; else hou2=hou2+1; end if; end if; end if; elsif switch=01 then hou1=seth1; hou2=seth2; end if; end process;5調(diào)時模塊 該進程用來控制時鐘狀態(tài),switch為“00”時正常顯示時間,為“01”時是進行調(diào)時, 為“10”時是設(shè)置鬧鐘時間。代碼如下: process (setclk(0) is begin if(setclk(0)event and setc

11、lk(0)=1)then if(switch=10)then switch=00; else switch=switch+1; end if; end if; end process; process (setclk(2),switch,setclk(1) is begin-setclk(1)為1調(diào)分 if(switch=01 and setclk(1)=1)then if(setclk(2)event and setclk(2)=1)then if(setm2=1001)then setm2=0000; if(setm1=0101)then setm1=0000; else setm1=se

12、tm1+1; end if; else setm2=setm2+1; end if; end if; end if; end process; process (setclk(2),switch,setclk(1) is begin-setclk(1)為0調(diào)時 if(switch=01 and setclk(1)=0)then if(setclk(2)event and setclk(2)=1)then if(seth1=0010)then if(seth2=0011)then seth1=0000; seth2=0000; else seth2=seth2+1; end if; else i

13、f(seth2=1001)then seth1=seth1+1; seth2=0000; else seth2=seth2+1; end if; end if; end if; end if; end process;6鬧鐘模塊該模塊由3個小模塊組成,分別為設(shè)置鬧鐘時間、判斷鬧鐘時間是否到達以及鬧鈴聲音模塊。(1)設(shè)置鬧鐘時間模塊該進程用于設(shè)置鬧鐘時間。信號量switch為10時,表示設(shè)置鬧鐘時間; if(switch=10)then-調(diào)鬧鐘時,顯示鬧鐘設(shè)置時間 if sel=000 then d1doutdoutdoutdout=XXXXXXXX; end case; elsif sel=0

14、01 then d2doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX; end case; elsif sel=010 then d3doutdoutdoutdoutdoutdoutdout=XXXXXXXX; end case; elsif sel=011 then d4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX; end case; elsif sel=100 then d5doutdoutdoutdoutdoutdoutdout=XXXXXXXX; end case;

15、 elsif sel=101 then d6doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX; end case; end if;(2)鬧鈴聲音模塊通過分頻產(chǎn)生蜂鳴,即發(fā)出鬧鈴聲音。 process (switch) is-鬧鈴 begin-設(shè)置鬧鈴時秒歸零 if switch=10 then sps1=0000; sps2=0000; end if; end process; process (switch,setclk(2),setclk(1) is begin if(switch=10 and setclk(1)=1)then i

16、f(setclk(2)event and setclk(2)=1)then if(spm2=1001)then spm2=0000; if(spm1=0101)then spm1=0000; else spm1=spm1+1; end if; else spm2=spm2+1; end if; end if; end if; end process; process (switch,setclk(2),setclk(1) is begin if(switch=10 and setclk(1)=0)then if(setclk(2)event and setclk(2)=1)then if(sp

17、h1=0010)then if(sph2=0011)then sph1=0000; sph2=0000; else sph2=sph2+1; end if; else if(sph2=1001)then sph2=0000; sph1=sph1+1; else sph2=sph2+1; end if; end if; end if; end if; end process; process (clk,sph1,sph2,spm1,spm2,hou1,hou2,min1,min2) is begin if(sph1=hou1 and sph2=hou2 and spm1=min1 and spm

18、2=min2)then speak=clk; else speak=0; end if; end process;7數(shù)碼管顯示模塊(1)選擇時間顯示 process(key1,key2,change) begin if(key1=0)and(key2=0)thensec_0=sec_00; sec_1=sec_11; min_0=min_00; min_1=min_11; hour_1=hour_11;hour_0=hour_00; elsif(key1=1)and(key2=0)thensec_0=sec_000; sec_1=sec_111; min_0=min_000;min_1=min

19、_111; hour_0=hour_000;hour_1=hour_111; elsif(key1=0)and(key2=1)thensec_0=sec_0000; sec_1=sec_1111; min_0=min_0000;min_1=min_1111; hour_0=hour_0000;hour_1=hour_1111; end if; end process;(2) 數(shù)碼管時間顯示 if sel=000 then d1doutdoutdoutdout=XXXXXXXX;end case; elsif sel=001 thend2doutdoutdoutdoutdoutdoutdoutd

20、outdoutdoutdout=XXXXXXXX;end case; elsif sel=010 thend3doutdoutdoutdoutdoutdoutdout=XXXXXXXX;end case; elsif sel=011 thend4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;end case; elsif sel=100 thend5doutdoutdoutdoutdoutdoutdout=XXXXXXXX;end case; elsif sel=101 thend6doutdoutdoutdoutdoutdoutd

21、outdoutdoutdoutdout=XXXXXXXX;end case; end if;五、實驗結(jié)果分析總結(jié):該程序基本實現(xiàn)了數(shù)字時鐘的基本功能,能夠正常走時,并且可以校正時間,還可以進行鬧鐘設(shè)置。 通過這次VHDL課程設(shè)計,我學到了很多,對于原本掌握的不好的數(shù)字邏輯相關(guān)知識,在課程設(shè)計具體實踐中有了很深刻的認識,在對于Quartus II的操作上也有很大的提高,增加了操作的熟練程度,現(xiàn)在我已經(jīng)有信心做任何的設(shè)計課題。在編程中還遇到其他一些小問題,有好多都是由于不夠細心,不夠嚴謹造成的,通過編程,我會一步步養(yǎng)成一個好的編程習慣,盡量避免一些不必要的錯誤,一步步提高自己。在今后的學習中,我還

22、需要不斷學習,不斷鍛煉自己。6、 附:源代碼library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity clock isport( clk:in std_logic; -時鐘 speak:out std_logic; -鈴 dout:out std_logic_vector(7 downto 0); -晶體管顯示 setclk:in std_logic_vector(2 downto 0); -操作按鈕 d1,d2,d3,d4,d5,d6: out std_logic); -六個晶體管end e

23、ntity clock;architecture one of clock issignal sel:std_logic_vector(2 downto 0);signal hou1:std_logic_vector(3 downto 0); -時分秒的個位和十位signal hou2:std_logic_vector(3 downto 0);signal min1:std_logic_vector(3 downto 0);signal min2:std_logic_vector(3 downto 0);signal seth1:std_logic_vector(3 downto 0);sig

24、nal seth2:std_logic_vector(3 downto 0);signal setm1:std_logic_vector(3 downto 0);signal setm2:std_logic_vector(3 downto 0);signal sec1:std_logic_vector(3 downto 0);signal sec2:std_logic_vector(3 downto 0);signal h1:std_logic_vector(3 downto 0);signal h2:std_logic_vector(3 downto 0);signal m1:std_log

25、ic_vector(3 downto 0);signal m2:std_logic_vector(3 downto 0);signal s1:std_logic_vector(3 downto 0);signal s2:std_logic_vector(3 downto 0);signal sph1,sph2,spm1,spm2,sps1,sps2:std_logic_vector(3 downto 0);signal count_sec:std_logic_vector(9 downto 0);signal sec_co:std_logic;signal co1,co2,co3,co4:st

26、d_logic; -進位signal switch:std_logic_vector(1 downto 0); -表示狀態(tài)begin-process (clk) is-define a secondbeginif(clkevent and clk=1)thenif(count_sec=1111111111)thencount_sec=0000000000;sec_co=1;elsecount_sec=count_sec+1;sec_co=0;end if;end if;end process;-process(sec_co) is-秒個位beginif switch=00 then-正常狀態(tài)i

27、f sec_co=1 thenif sec2=1001 thensec2=0000;co1=1;else sec2=sec2+1;co1=0;end if;end if;elsif switch=01 then-調(diào)時狀態(tài)sec2=0000;end if;end process;-process (co1) is-秒十位beginif switch=00 thenif co1event and co1=1 thenif (sec1=0101)thensec1=0000;co2=1;elsesec1=sec1+1;co2=0;end if;end if;elsif switch=01 thense

28、c1=0000;end if;end process;-process (co1,co2) is-分鐘個位beginif switch=00 thenif co2event and co2=1 thenif min2=1001 thenmin2=0000;co3=1;elsemin2=min2+1;co3=0;end if;end if;elsif switch=01 thenmin2=setm2;end if;end process;-process (co3) is-分鐘十位beginif switch=00 thenif co3=1 thenif min1=0101 then min1=

29、0000;co4=1;elsemin1=min1+1;co4=0;end if;end if;elsif switch=01 thenmin1=setm1;end if;end process;-process(co4)-小時beginif switch=00 thenif co4=1 thenif (hou1=0010) then-小時十位為2時,個位滿3進一if(hou2=0011)thenhou2=0000;hou1=0000;elsehou2=hou2+1;end if;else-小時十位為0或1,個位滿9進一if(hou2=1001)thenhou2=0000;hou1=hou1+1

30、;elsehou2=hou2+1;end if;end if;end if;elsif switch=01 thenhou1=seth1;hou2=seth2;end if;end process;-process (setclk(0) is-控制時鐘狀態(tài),00正常,01調(diào)時,10鬧鐘beginif(setclk(0)event and setclk(0)=1)thenif(switch=10)thenswitch=00;elseswitch=switch+1;end if;end if;end process;process (setclk(2),switch,setclk(1) isbeg

31、in-setclk(1)為1調(diào)分if(switch=01 and setclk(1)=1)thenif(setclk(2)event and setclk(2)=1)thenif(setm2=1001)thensetm2=0000;if(setm1=0101)thensetm1=0000;elsesetm1=setm1+1;end if;elsesetm2=setm2+1;end if;end if;end if;end process;process (setclk(2),switch,setclk(1) isbegin-setclk(1)為0調(diào)時if(switch=01 and setcl

32、k(1)=0)thenif(setclk(2)event and setclk(2)=1)thenif(seth1=0010)thenif(seth2=0011)thenseth1=0000;seth2=0000;elseseth2=seth2+1;end if;elseif(seth2=1001)thenseth1=seth1+1;seth2=0000;elseseth2=seth2+1;end if;end if;end if;end if;end process;-process (switch) is-鬧鈴begin-設(shè)置鬧鈴時秒歸零if switch=10 thensps1=0000;sps2=0000;end

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論