多功能電子時鐘數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告_第1頁
多功能電子時鐘數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告_第2頁
多功能電子時鐘數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告_第3頁
多功能電子時鐘數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告_第4頁
多功能電子時鐘數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告_第5頁
已閱讀5頁,還剩48頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、. 數(shù)字系統(tǒng)課程設(shè)計設(shè)計實驗報告 多功能電子時鐘 .;目 錄一、電子時鐘的功能及工作介紹11、本設(shè)計電子時鐘具有的功能12、本設(shè)計電子時鐘工作介紹1二、設(shè)計思路1三、各模塊具體介紹2計數(shù)器模塊:2控制模塊:4四、仿真8五、實驗成果13六、實驗總結(jié)和感想151、實驗錯誤排查和解決152、實驗感想16七、各模塊代碼171、計數(shù)器模塊172、控制模塊320一、電子時鐘的功能及工作介紹1、本設(shè)計電子時鐘具有的功能1)具有顯示時、分、秒的功能,能準確顯示時間2)能夠手動設(shè)置時間3)具有鬧鐘功能,可以設(shè)置鬧鐘的時間,然后再實際時間與設(shè)定時間相等是鬧鐘響,并有鬧鐘開關(guān),可控制其是否響4)具有秒表功能,可以累

2、計計時2、本設(shè)計電子時鐘工作介紹此電子時鐘開機后即會顯示時間,其中后兩位數(shù)碼管顯示秒,前兩位數(shù)碼管顯示分,還可以通過撥盤開關(guān)S1來使得前兩位數(shù)碼管顯示小時。(開機后,按下按鍵1一次,會繼續(xù)顯示時間。)此后,每按下按鍵1一次,會顯示設(shè)置小時界面,按下按鍵1兩次會顯示設(shè)置分鐘界面,按下按鍵1三次會顯示鬧鐘設(shè)置小時界面,按下按鍵1四次會顯示鬧鐘設(shè)置分鐘界面,按下按鍵1五次會顯示秒表界面。而在每一個界面,按下按鍵2相應(yīng)的位會開始跳動,在按下按鍵2時,跳動停止,此時按下按鍵3,即確認鍵,則會返回時間顯示狀態(tài)。二、設(shè)計思路設(shè)計一個電子時鐘,必然要用到計時器,而需要設(shè)置時間和鬧鐘,又需要控制器來控制系統(tǒng)所處

3、的狀態(tài)。我們采用外部一個按鍵來切換系統(tǒng)的狀態(tài),用另一個按鍵來調(diào)整時間和啟動秒表,再有一個按鍵來確認操作,并返回顯示狀態(tài),繼續(xù)等待命令。在控制器中,需要接受外部信號,并給出信號給計時器,使其做出相應(yīng)的動作。三、各模塊具體介紹本設(shè)計主要分成計數(shù)器模塊和控制模塊。計數(shù)器模塊主要包括60進制計數(shù)器模塊和24進制計數(shù)器模塊,向量與整數(shù)轉(zhuǎn)換模塊,1Hz時鐘分頻模塊,整數(shù)轉(zhuǎn)換為兩個向量的模塊,動態(tài)顯示模塊和8段數(shù)碼管譯碼模塊??刂颇K主要包括。計數(shù)器模塊:1、60進制計數(shù)器模塊此模塊主要提供60進制數(shù)的計數(shù),通過連接外部1Hz時鐘信號來控制計數(shù)頻率。只要檢測時鐘上升沿到來,計數(shù)器就加1,直至計到60,又從0

4、開始計時。此外,此模塊還有復(fù)位和置數(shù)功能。復(fù)位端低電平就能將計數(shù)器清0,而置位端的高電平能將外部送來的數(shù)據(jù)加載到計算器里面,計數(shù)器從加載的值開始計數(shù)。除此之外,進位信號用于下一位計數(shù)的時鐘信號。這主要用于接收控制模塊中,通過外部設(shè)置時間來修改時鐘當(dāng)前時間的功能。60進制計數(shù)器模塊主要是秒和分位的計數(shù)。2、24進制計數(shù)器模塊此模塊和60進制計數(shù)器模塊有一樣的功能,只是這個模塊是24進制的,用于時位的計數(shù),同樣也有復(fù)位和置數(shù)的功能。3、向量與整數(shù)轉(zhuǎn)換模塊由于整數(shù)處理起來比較方便,所以添加了向量到整數(shù)的轉(zhuǎn)換模塊。其中用到了conv_integer來進行轉(zhuǎn)換。4、1Hz時鐘分頻模塊由于實驗板上的時鐘頻

5、率為50MHz,而時間顯示最低位為秒,故需要分頻。分頻器實際也是一個計數(shù)器,只是在計數(shù)的中點處,將輸出信號置為1,在終點處將其置為0,便可實現(xiàn)50%占空比的1Hz時鐘信號。5、整數(shù)轉(zhuǎn)換為兩個向量的模塊由于本設(shè)計將時分秒都作為一個整體來處理,但是在顯示時需要有兩個數(shù)碼管分別顯示,所以必須拆成兩個,且8段數(shù)碼管的譯碼的輸入為向量,故需轉(zhuǎn)換成兩個向量。主要是利用對10整除取其十位,對10取余取出個位的方法,再用conv_std_logic_vector將其轉(zhuǎn)換為向量。6、動態(tài)顯示模塊由于實驗板上將4個8段數(shù)碼管的端口連在一起,所以每一時刻4個數(shù)碼管的顯示數(shù)值應(yīng)該是一樣的,故不能分別顯示不同時間。然而

6、,動態(tài)顯示通過人眼的余暉效應(yīng),以很高的頻率來掃描數(shù)碼管,不斷的依次輪流點亮數(shù)碼管,使得看起來是4個數(shù)碼管同時顯示不同數(shù)字。這主要是通過設(shè)置數(shù)碼管的使能端,同時選擇此數(shù)碼管應(yīng)該顯示的數(shù)據(jù),進行動態(tài)顯示。此外,我們對數(shù)碼管顯示時的小數(shù)點進行控制,使其在顯示分和秒之間點亮而其他位不亮。所以我們設(shè)置了一個標志位來對譯碼電路進行控制,使其點亮或熄滅小數(shù)點。7、8段數(shù)碼管譯碼模塊此模塊主要將輸入的4位向量轉(zhuǎn)換成相應(yīng)的在8端數(shù)碼管上顯示的向量,使其顯示相應(yīng)的數(shù)字。而且,我們通過從動態(tài)顯示模塊接收到的標志位來控制譯碼的程序,使得相應(yīng)的小數(shù)點亮或滅??刂颇K:1.消抖模塊:由于每個按鍵機械觸點的閉合或斷開都會有

7、一個抖動的暫態(tài)過程,即按鍵閉合時不是立即穩(wěn)定閉合,而是處于閉合斷開交替變化的過程,持續(xù)一段時間才變?yōu)榉€(wěn)定閉合的狀態(tài),按鍵松開時有類似的效果,而由于CPU的反映速度很快,能夠檢測出抖動過程產(chǎn)生的電壓波動,如果直接檢測電平判斷按鍵是否按下或松開會造成重復(fù)識別,因此通過消抖模塊來檢測按鍵是否按下。2.按鍵模塊:此模塊利用3個按鍵來對時鐘進行操作,每個按鍵按下,輸出一個高電平信號給按鍵記錄模塊。按鍵1是切換鍵,用來切換當(dāng)前時鐘工作狀態(tài);按鍵2是啟動停止鍵,用于調(diào)整時間和設(shè)定鬧鐘時間;按鍵3是確認鍵,按下使時鐘回到原始狀態(tài),即時間顯示狀態(tài)。3.按鍵記錄模塊:此模塊用來記錄按鍵按下的數(shù)目,以切換到相應(yīng)的工

8、作模式進行進行操作。Sum記錄按鍵1的按下數(shù):1表示時間顯示狀態(tài);2表示時間的時調(diào)整狀態(tài);3表示時間的分調(diào)整狀態(tài);4表示鬧鈴的時設(shè)定狀態(tài);5表示鬧鈴的分設(shè)定狀態(tài);6表示秒表狀態(tài)。Sum1記錄按鍵2的按下數(shù):1表示啟動,時間開始變化;2表示停止,時間調(diào)整或設(shè)定完畢。Sum2記錄按鍵3的按下數(shù):按一下表示確認,時鐘回到時間顯示工作狀態(tài)。4.時分選擇模塊:此模塊用來選擇時或分,并將結(jié)果送到顯示模塊進行數(shù)碼管顯示。這是由于實驗板只有4個數(shù)碼管不夠用來完整顯示時、分、秒的限制而設(shè)計的。時分選擇通過撥盤來進行控制。撥盤撥下(關(guān)閉):選擇顯示分;撥盤撥上(開啟):選擇顯示時。5. 顯示選擇模塊:此模塊主要區(qū)

9、分秒表工作狀態(tài)下和其他工作狀態(tài)的的結(jié)果顯示。6. 主控模塊:此模塊用來控制時鐘當(dāng)前工作狀態(tài),并對各種工作狀態(tài)下的操作指令進行接受和處理。(1)輸入信號有:Clk:時鐘信號;setsnd:鬧鈴開關(guān)信號;setsnd=1時,鬧鈴開;setsnd=0時,鬧鈴關(guān)。sum:切換按鍵1的按下數(shù);sum=1時,時鐘工作在時間顯示狀態(tài);sum=2時,時鐘工作在時間的時調(diào)整狀態(tài);sum=3時,時鐘工作在時間的分調(diào)整狀態(tài);sum=4時,時鐘工作在鬧鈴的時設(shè)定狀態(tài);sum=5時,時鐘工作在鬧鈴的分設(shè)定狀態(tài);sum=6時,時鐘工作在秒表狀態(tài)。Sum1:啟動停止按鍵2的按下數(shù);sum=1表示啟動,時間開始變化;sum=

10、2表示停止,時間調(diào)整或設(shè)定完畢。Sum2:確認鍵3的按下數(shù): Sum2=1,表示操作完畢,使sum=1,時鐘回到時間顯示狀態(tài),并使sum1=0.Hour:時;Min:分;Sec:秒。(2)輸出信號:Rst:復(fù)位信號,用來消除秒表的記錄,使其變?yōu)?;Showchu:顯示選擇信號,用來切換秒表狀態(tài)和其他狀態(tài)的顯示;Begincnt:秒表啟動信號;Load:時間重置信號,用于將顯示時間改變到經(jīng)調(diào)整設(shè)置得到的新時間;Clear:按鍵記錄清除信號;Sound:鬧鈴信號,達到設(shè)定的鬧鈴時間時,該信號是蜂鳴器鳴叫;Output1:經(jīng)處理后的時;Output2:經(jīng)處理后的分;Output3:經(jīng)處理后的秒;四、

11、仿真1、計數(shù)器模塊仿真由以上仿真圖可知此計數(shù)器可以實現(xiàn)計時功能,且能夠及時進位,符合設(shè)計的目標。由以上仿真圖可知,當(dāng)load信號為1時,可以實現(xiàn)置位,即將當(dāng)前計數(shù)器的值改為外部輸入的值(圖中外部輸入為0)。2、向量整數(shù)轉(zhuǎn)換模塊仿真由以上兩幅圖可知向量與整數(shù)轉(zhuǎn)換模塊能正確地實現(xiàn)向量到整數(shù)的轉(zhuǎn)換。3、整數(shù)轉(zhuǎn)換為兩個向量的模塊仿真由以上兩幅圖可知,此模塊可以將一個整數(shù)拆分成兩個向量,以用于兩個數(shù)碼管的顯示。4、按鍵記錄模塊仿真5、時分選擇模塊仿真:6、顯示選擇模塊仿真:五、實驗成果六、實驗總結(jié)和感想1、實驗錯誤排查和解決實驗最開始是計時器,由于實驗板上只有4個數(shù)碼管,不夠同時顯示時分秒共6位數(shù),故我

12、們采用外部撥碼開關(guān)控制切換時和分的顯示。在顯示時,由于譯碼模塊將所有數(shù)碼管的小數(shù)點都點亮,所以看起來并不直觀。我們后來在動態(tài)顯示模塊加入一個標記信號,使得譯碼時,需要小數(shù)點亮的數(shù)碼管按原來的程序譯碼,不需小數(shù)點點亮的數(shù)碼管按另外的方法譯碼,便解決了這個問題。秒表顯示也是同樣的道理控制小數(shù)點亮滅。在控制模塊中,設(shè)置鬧鐘時,一開始,我們設(shè)置完鬧鐘時間后,按下確認鍵,總是會先短暫地響一聲。后來在找程序時才發(fā)現(xiàn)再確認鍵后對信號進行復(fù)制,此時信號還未來得及變化,還是原來的值,和鬧鐘設(shè)定值是一樣的,所以會有那個響聲。將其先賦給一個變量,在用變量與鬧鐘設(shè)定值比較,就可以得到正確結(jié)果,等到鬧鐘時間時響鈴。2、

13、實驗感想在這次的VHDL課程設(shè)計中,我們小組做的是多功能電子時鐘實驗,在參與之前,我以為同單片機課程設(shè)計一樣,照著老師給的要求,設(shè)計程序、再下載進去即可。而且在VHDL的學(xué)習(xí)中,由于邢老師的講課條理清晰,教授細致,我們都學(xué)得比較輕松。但是真正參與到設(shè)計的過程中時,卻比想象中的難得多,不過收獲和付出是成正比的,有挑戰(zhàn)性的實驗,才會讓人受益匪淺。一是知識一定要掌握完整,理解透徹才有可能用于實際用途。由于原先對程序設(shè)計過程掌握不熟練,導(dǎo)致經(jīng)常犯下簡單的錯誤,拖延了設(shè)計的完成時間,基礎(chǔ)不夠扎實。在此次的數(shù)字鐘設(shè)計過程中,我們更進一步地熟悉有關(guān)數(shù)字電路的知識和具體應(yīng)用。學(xué)會了利QuarterII軟件進行

14、原理圖的繪制,硬件描述語言VHDL的編寫,程序的仿真等工作。并能根據(jù)仿真結(jié)果分析設(shè)計的存在的問題和缺陷,從而進行程序的調(diào)試和完善。二是模塊化的思想,在實踐中真正的體會到了其簡便、易懂的特點。通過對模塊化思想的應(yīng)用,我們的實驗思路非常的清晰,大大提高了實驗過程的簡潔度,不僅方便基本功能的設(shè)計,還會便于擴展功能的實現(xiàn)。這些平時聽得暈乎乎,人云亦云的好處,終于在實踐過程中得到了非常好的體現(xiàn)。 以上就是我們在這次實驗中的收獲和感想,學(xué)習(xí)不能只靠書本和試卷,更重要的是類似于這樣的動手過程,這樣才能穩(wěn)扎穩(wěn)打,真正的學(xué)到有用的知識。七、各模塊代碼1、計數(shù)器模塊(1)60進制計數(shù)器模塊library ieee

15、;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity count60s is port(rst,clk,load:in std_logic; num:in std_logic_vector(5 downto 0); num1:out std_logic_vector(5 downto 0); outp:out std_logic);end entity;architecture behav of count60s isbegin process(clk,rst,load)variable cnt:std_logi

16、c_vector(5 downto 0);beginif(rst='0') thencnt:="000000"elsif(load='1') thencnt:=num;outp<='0'elsif(clk'event and clk='1') thenif(cnt="111011") thencnt:="000000"outp<='1'elsecnt:=cnt+"000001"outp<='0'

17、end if;end if;num1<=cnt;end process;end behav;(2)24進制計數(shù)器模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity count24s is port(rst,clk,load:in std_logic; num:in std_logic_vector(5 downto 0); num1:out std_logic_vector(5 downto 0); outp:out std_logic);end entity;architec

18、ture behav of count24s isbegin process(clk,rst,load)variable cnt:std_logic_vector(5 downto 0);beginif(rst='0') thencnt:="000000"elsif(load='1') thencnt:=num;outp<='0'elsif(clk'event and clk='1') thenif(cnt="010111") thencnt:="000000&quo

19、t;outp<='1'elsecnt:=cnt+"000001"outp<='0'end if;end if;num1<=cnt;end process;end behav;(3)向量與整數(shù)轉(zhuǎn)換模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity rr is port(a:in std_logic_vector(5 downto 0);b: out integ

20、er range 63 downto 0);end entity;architecture behav of rr isbeginb<=conv_integer(a);end behav;(4)1Hz時鐘分頻模塊library ieee;use ieee.std_logic_1164.all;entity clkdiv is port(clk:in std_logic; q: out std_logic);end clkdiv;architecture behav of clkdiv isbegin process(clk) variable timed:integer range 0

21、to 50000000; begin if rising_edge(clk) then timed:=timed+1; if timed=25000000 then q<='1' elsif timed=50000000 then q<='0' timed:=0 ; end if; end if; end process;end behav;(5)整數(shù)轉(zhuǎn)換為兩個向量的模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic

22、_arith.all;entity trans isport(num:in integer range 63 downto 0;num_l,num_h:out std_logic_vector(3 downto 0);end entity;architecture behav of trans is signal m,n:integer range 9 downto 0;beginm<=num/10;n<=num rem 10;num_l<=conv_std_logic_vector(n,4);num_h<=conv_std_logic_vector(m,4);end

23、behav;(6)動態(tài)顯示模塊library ieee;use ieee.std_logic_1164.all;entity show isport(secondl,secondh,minutel,minuteh:in std_logic_vector(3 downto 0); sum:in std_logic_vector(3 downto 0); clk:in std_logic; en:out std_logic_vector(3 downto 0); seg:out std_logic_vector(3 downto 0); flag:out std_logic);end entity

24、;architecture behav of show isbegin process(clk)variable counter:integer range 0 to 3;beginif(clk'event and clk='1') thenif(counter=3) thencounter:=0;elsecounter:=counter+1;end if;end if;case counter iswhen 0 =>if(sum="0110")thenflag<='1'elseflag<='0'en

25、d if;en<= "0111"seg<=minuteh;when 1 =>if(sum="0110")thenflag<='0'elseflag<='1'end if;en<= "1011"seg<=minutel;when 2 =>if(sum="0110")thenflag<='1'elseflag<='0'end if;en<= "1101"seg<=s

26、econdh;when 3 =>if(sum="0110")thenflag<='0'elseflag<='1'end if;en<= "1110"seg<=secondl;when others=>null;end case;end process;end behav;(7)8段數(shù)碼管譯碼模塊library ieee;use ieee.std_logic_1164.all;entity counter_displayer isport(flag:in std_logic;display

27、er_en:in std_logic; count:in std_logic_vector(3 downto 0); seven_seg_input:out std_logic_vector(7 downto 0);end counter_displayer;architecture behav of counter_displayer issignal seven_seg_input_reg:std_logic_vector(7 downto 0);begindisplay:process(displayer_en,count)beginif displayer_en='0'

28、 thenif(flag='1') thencase count iswhen"0000"=>seven_seg_input_reg<="00000010"when"0001"=>seven_seg_input_reg<="10011110"when"0010"=>seven_seg_input_reg<="00100100"when"0011"=>seven_seg_input_reg<=&

29、quot;00001100"when"0100"=>seven_seg_input_reg<="10011000"when"0101"=>seven_seg_input_reg<="01001000"when"0110"=>seven_seg_input_reg<="01000000"when"0111"=>seven_seg_input_reg<="00011110"when&

30、quot;1000"=>seven_seg_input_reg<="00000000"when"1001"=>seven_seg_input_reg<="00001000"when"1010"=>seven_seg_input_reg<="00010000"when"1011"=>seven_seg_input_reg<="11000000"when"1100"=>seve

31、n_seg_input_reg<="01100010"when"1101"=>seven_seg_input_reg<="10000100"when"1110"=>seven_seg_input_reg<="01100000"when"1111"=>seven_seg_input_reg<="01110000"WHEN OTHERS =>seven_seg_input_reg <="00000

32、010"end case;elsecase count iswhen"0000"=>seven_seg_input_reg<="00000011"when"0001"=>seven_seg_input_reg<="10011111"when"0010"=>seven_seg_input_reg<="00100101"when"0011"=>seven_seg_input_reg<="000

33、01101"when"0100"=>seven_seg_input_reg<="10011001"when"0101"=>seven_seg_input_reg<="01001001"when"0110"=>seven_seg_input_reg<="01000001"when"0111"=>seven_seg_input_reg<="00011111"when"100

34、0"=>seven_seg_input_reg<="00000001"when"1001"=>seven_seg_input_reg<="00001001"when"1010"=>seven_seg_input_reg<="00010001"when"1011"=>seven_seg_input_reg<="11000001"when"1100"=>seven_seg_in

35、put_reg<="01100011"when"1101"=>seven_seg_input_reg<="10000101"when"1110"=>seven_seg_input_reg<="01100001"when"1111"=>seven_seg_input_reg<="01110001"WHEN OTHERS =>seven_seg_input_reg <="00000011"

36、;end case;end if;end if;seven_seg_input<=seven_seg_input_reg;end process;end behav;(8)秒表模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cc is port(flag,rst,clk:in std_logic; fsecond:out std_logic_vector(3 downto 0); second:out integer range 63 downto 0; minute:ou

37、t std_logic_vector(3 downto 0);end entity;architecture behav of cc iscomponent count60ss is port(rst,clk:in std_logic; num1:out std_logic_vector(5 downto 0); outp:out std_logic);end component;component count10s is port(rst,clk,flag:in std_logic; num1:out std_logic_vector(3 downto 0); outp:out std_lo

38、gic);end component;component rr is port(a:in std_logic_vector(5 downto 0);b: out integer range 63 downto 0);end component;signal pp,qq,oo:std_logic;signal sec:std_logic_vector(5 downto 0);beginu0:count10s port map(rst,clk,flag,fsecond,pp);u1:count60ss port map(rst,pp,sec,qq);u2:count10s port map(rst

39、,qq,flag,minute,oo);u3:rr port map(sec,second);end behav;2、控制模塊(1)消抖模塊:library ieee ;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity key_state ISport(clk:in std_logic; sw:in std_logic; sw_out:buffer std_logic );end entity;architecture behav of key_state ISsignal key_rst : std_logi

40、c;signal key_rst_an : std_logic;signal key_rst_r : std_logic;signal low_sw: std_logic;signal low_sw_r: std_logic;signal cnt:std_logic_vector(19 downto 0);beginprocess(clk)begin if clk'event and clk='1'then key_rst<=sw; end if; end process; process(clk)begin if clk'event and clk=&#

41、39;1'then key_rst_r<=key_rst; end if;end process;key_rst_an<=key_rst_r AND NOT key_rst;process(clk)begin if clk'event and clk='1'then if key_rst_an='0' then cnt<=cnt+1; else cnt<=(others=>'0'); end if; end if;end process;process(clk)begin if clk'eve

42、nt and clk='1'then if cnt="11111111111111111111" then low_sw<=sw; else NULL; end if; end if;end process;process(clk)begin if clk'event and clk='1'then low_sw_r<=low_sw; end if;end process;sw_out<=low_sw_r AND NOT low_sw; -按鍵按下為低電平 -消抖后,若確實有按鍵按下,則輸出sw_out為1end b

43、ehav;(2)按鍵模塊:library ieee ;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity keycnt isport(clk:in std_logic; sw1:in std_logic; sw2:in std_logic; sw3:in std_logic; sw1_out:out std_logic; sw2_out:out std_logic; sw3_out:out std_logic);end entity;architecture bev of keycnt iscomponent k

44、ey_state isport(clk:in std_logic; sw:in std_logic; sw_out:buffer std_logic);end component;beginu1:key_state port map(clk,sw1,sw1_out);u2:key_state port map(clk,sw2,sw2_out);u3:key_state port map(clk,sw3,sw3_out);end bev;(3)按鍵記錄模塊:library ieee ;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.

45、all;entity numcnt isport(clk:in std_logic; clear:in std_logic; sw1_out:in std_logic; sw2_out:in std_logic; sw3_out:in std_logic; sum:out std_logic_vector(3 downto 0); sum1:out std_logic_vector(3 downto 0); sum2:out std_logic_vector(3 downto 0);end entity;architecture bev of numcnt issignal cnt1:std_

46、logic_vector(3 downto 0);signal cnt2:std_logic_vector(3 downto 0);signal cnt3:std_logic_vector(3 downto 0);beginprocess(clk)beginif(clk' event and clk='1')then if(clear='1')then cnt1<="0001"cnt2<="0000"cnt3<="0000" elseif(sw1_out='1'

47、)thenif(cnt1="0110")thencnt1<="0001"elsecnt1<=cnt1+"0001"end if;else null;end if; end if;if(sw2_out='1')thenif(cnt2="0010")thencnt2<="0000"elsecnt2<=cnt2+"0001"end if;else null;end if;if(sw3_out='1')thenif(cnt3=&

48、quot;0001")thencnt3<="0000"elsecnt3<=cnt3+"0001"end if;else null;end if;end if;sum<=cnt1;sum1<=cnt2;sum2<=cnt3;end process;end bev;(4)時分選擇模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity choice isport(cho:in std_logic; output1

49、:in integer range 63 downto 0; output2:in integer range 63 downto 0; num:out integer range 63 downto 0);end entity;architecture bev of choice isbeginprocess(cho)beginif(cho='1') thennum<=output2;else num<=output1;end if;end process;end bev;(5)顯示選擇模塊:library ieee;use ieee.std_logic_1164

50、.all;use ieee.std_logic_unsigned.all;entity show_choice isport(showchu:in std_logic; click1,click2,click3,click4:in std_logic_vector(3 downto 0); count1,count2,count3,count4:in std_logic_vector(3 downto 0); show1,show2,show3,show4:out std_logic_vector(3 downto 0);end entity;architecture bev of show_

51、choice isbeginprocess(showchu)beginif(showchu='1') thenshow1<=count1;show2<=count2;show3<=count3;show4<=count4;else show1<=click1;show2<=click2;show3<=click3;show4<=click4;end if;end process;end bev;(6)主控模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_u

52、nsigned.all;entity funtion isport(clk:in std_logic; setsnd:in std_logic; sum:in std_logic_vector(3 downto 0); sum1:in std_logic_vector(3 downto 0); sum2:in std_logic_vector(3 downto 0); hour:in integer range 63 downto 0; min:in integer range 63 downto 0; sec:in integer range 63 downto 0; rst:out std

53、_logic; showchu:out std_logic; begincnt:out std_logic; load:out std_logic; clear:out std_logic; output1:out integer range 63 downto 0; output2:out integer range 63 downto 0; output3:out integer range 63 downto 0; sound:out std_logic);end entity;architecture bev of funtion istype state_type is(s1,s2,

54、s3,s4,s5,s6);signal state:state_type:=s1;signal temp1:integer range 63 downto 0:=0;signal temp2:integer range 63 downto 0:=0;signal temp3:integer range 63 downto 0:=0;signal ring1:integer range 63 downto 0;signal ring2:integer range 63 downto 0;signal load1:std_logic;signal clear1:std_logic;beginseq

55、:process(clk,state,sum,sum1,sum2)variable tp1:integer range 63 downto 0;variable tp2:integer range 63 downto 0;variable tp3:integer range 63 downto 0;beginif(clk' event and clk='1')thenif(sum2="0001")thenstate<=s1;clear1<='1'rst<='0'elserst<='1'case sum iswhen "0001"=>state<=s1;when "0010"=>state<=s2;when "0011"=>state<=s3;when "0100"=>state<=s4;when "0101&q

溫馨提示

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

最新文檔

評論

0/150

提交評論