VHDL數(shù)字時(shí)鐘實(shí)驗(yàn)報(bào)告_第1頁(yè)
VHDL數(shù)字時(shí)鐘實(shí)驗(yàn)報(bào)告_第2頁(yè)
VHDL數(shù)字時(shí)鐘實(shí)驗(yàn)報(bào)告_第3頁(yè)
已閱讀5頁(yè),還剩28頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、Word VHDL數(shù)字時(shí)鐘實(shí)驗(yàn)報(bào)告 VHDL數(shù)字時(shí)鐘設(shè)計(jì) 一、試驗(yàn)?zāi)康模?進(jìn)一步練習(xí)VHDL語(yǔ)言設(shè)計(jì)工程的建立與仿真的步驟和方法、熟識(shí)VHDL語(yǔ)言基本設(shè)計(jì)實(shí)體的編寫方法。同時(shí),在已有學(xué)問(wèn)的基礎(chǔ)上,簡(jiǎn)潔綜合編寫程序,仿制簡(jiǎn)潔器械。 二、試驗(yàn)環(huán)境: PC個(gè)人計(jì)算機(jī)、Windows XP操作系統(tǒng)、Quartus II集成開(kāi)發(fā)環(huán)境軟件。 三、設(shè)計(jì)要求: 運(yùn)用VHDL語(yǔ)言編寫一個(gè)數(shù)字鐘,詳細(xì)要求: 2. 具有手動(dòng)調(diào)整小時(shí),分鐘的功能。 3. 具有鬧鐘的功能,能夠在設(shè)定的鬧鐘時(shí)間發(fā)出鬧鈴聲。 1. 具有時(shí)、分、秒計(jì)數(shù)的十進(jìn)制數(shù)字顯示功能,以24小時(shí)循環(huán)計(jì)時(shí)。 四、試驗(yàn)步驟: 1. 定義輸入輸出信號(hào)量 po

2、rt( clk:in std_logic; 時(shí)鐘 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); 六個(gè)晶體管 2. 定義結(jié)構(gòu)體中的信號(hào)量 signal sel:std_logic_vector(2 downto 0); signal hou1:std_logic_vector(3 downto 0); -時(shí)分秒的個(gè)位和十位 signal hou2:s

3、td_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); 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

4、_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_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 do

5、wnto 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:std_logic; -進(jìn)位 signal switch :std_logic_vector(1 downto 0); -表示狀態(tài) 3. 分頻模塊 用來(lái)定義秒count_sec用來(lái)計(jì)時(shí)鐘個(gè)數(shù),當(dāng)count_sec=1111111111時(shí),及得到1Hz信號(hào)。

6、代碼如下: process (clk) is -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時(shí)鐘正常走時(shí)模塊 該模塊使用6個(gè)進(jìn)程實(shí)現(xiàn),分別為秒個(gè)位計(jì)時(shí)、秒十位計(jì)時(shí)、分個(gè)位計(jì)時(shí)、分十位計(jì)時(shí)、時(shí)個(gè)位計(jì)時(shí)、時(shí)十位計(jì)時(shí)。 process(sec_co) is 秒個(gè)位 begin if switc

7、h=00 then -正常狀態(tài) if sec_co=1 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)時(shí)狀態(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=

8、0; end if; end if; elsif switch=01 then sec1=0000; end if; end process; process (co1,co2) is 分鐘個(gè)位 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 分鐘十

9、位 begin if switch=00 then 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) 小時(shí) begin if switch=00 then if co4=1 then if (hou1=0010) then -小時(shí)十位為2時(shí),個(gè)位滿3進(jìn)一 if(hou2=0011)then hou2=0000; hou1=0000;

10、 else hou2=hou2+1; end if; else -小時(shí)十位為0或1,個(gè)位滿9進(jìn)一 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)時(shí)模塊 該進(jìn)程用來(lái)掌握時(shí)鐘狀態(tài),switch為“00”時(shí)正常顯示時(shí)間,為“01”時(shí)是進(jìn)行調(diào)時(shí), 為“10”時(shí)是設(shè)置鬧鐘時(shí)間。代碼如下: process (setclk(0) is begin if(

11、setclk(0)event and setclk(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 s

12、etm1=0000; else setm1=setm1+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)時(shí) 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 seth

13、2=seth2+1; end if; else if(seth2=1001)then seth1=seth1+1; seth2=0000; else seth2=seth2+1; end if; end if; end if; end if; end process; 6鬧鐘模塊 該模塊由3個(gè)小模塊組成,分別為設(shè)置鬧鐘時(shí)間、推斷鬧鐘時(shí)間是否到達(dá)以及鬧鈴聲音模塊。 (1)設(shè)置鬧鐘時(shí)間模塊 該進(jìn)程用于設(shè)置鬧鐘時(shí)間。 信號(hào)量switch為10時(shí),表示設(shè)置鬧鐘時(shí)間; if(switch=10)then -調(diào)鬧鐘時(shí),顯示鬧鐘設(shè)置時(shí)間 if sel=000 then d1=0; case sph1 is

14、when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when others=dout=XXXXXXXX; end case; elsif sel=001 then d2=0; case sph2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010;

15、when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX; end case; elsif sel=010 then d3=0; case spm1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001;

16、when 0101=dout=10010010; when others=dout=XXXXXXXX; end case; elsif sel=011 then d4=0; case spm2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000;

17、when 1000=dout=10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX; end case; elsif sel=100 then d5=0; case sps1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when others=dout=XXXXXXXX

18、; end case; elsif sel=101 then d6=0; case sps2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000;

19、when others=dout=XXXXXXXX; end case; end if; (2)鬧鈴聲音模塊 通過(guò)分頻產(chǎn)生蜂鳴,即發(fā)出鬧鈴聲音。 process (switch) is 鬧鈴 begin -設(shè)置鬧鈴時(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 if(setclk(2)event and setclk(2)=1)then if(spm2=1

20、001)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(sph1=0010)then if(sph2=0011)then sph1=0000; sph2=

21、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 spm2=min2)then speak=clk; else speak=0; end if; en

22、d process; 7數(shù)碼管顯示模塊 (1)選擇時(shí)間顯示 process(key1,key2,change) begin if(key1=0)and(key2=0)then sec_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)then sec_0=sec_000; sec_1=sec_111; min_0=min_000; min_1=min_111; hour_0=hour_000; hour_1=hour_111; e

23、lsif(key1=0)and(key2=1)then sec_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ù)碼管時(shí)間顯示 if sel=000 then d1=0; case h1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when others=dout=XXXXXXXX; end c

24、ase; elsif sel=001 then d2=0; case h2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when othe

25、rs=dout=XXXXXXXX; end case; elsif sel=010 then d3=0; case m1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when others=dout=XXXXXXXX; end case; elsif sel=011 then d4=0; case m2 is when 0000=dou

26、t=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX; end case; elsif sel=100 then d5=0; c

27、ase s1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when others=dout=XXXXXXXX; end case; elsif sel=101 then d6=0; case s2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10

28、100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX; end case; end if; 五、試驗(yàn)結(jié)果分析總結(jié): 該程序基本實(shí)現(xiàn)了數(shù)字時(shí)鐘的基本功能,能夠正常走時(shí),并且可以校正時(shí)間,還可以進(jìn)行鬧鐘設(shè)置。 通過(guò)這次VHDL課程設(shè)計(jì),我學(xué)

29、到了許多,對(duì)于原本把握的不好的數(shù)字規(guī)律相關(guān)學(xué)問(wèn),在課程設(shè)計(jì)詳細(xì)實(shí)踐中有了很深刻的熟悉,在對(duì)于Quartus II的操作上也有很大的提高,增加了操作的嫻熟程度,現(xiàn)在我已經(jīng)有信念做任何的設(shè)計(jì)課題。 在編程中還遇到其他一些小問(wèn)題,有好多都是由于不夠細(xì)心,不夠嚴(yán)謹(jǐn)造成的,通過(guò)編程,我會(huì)一步步養(yǎng)成一個(gè)好的編程習(xí)慣,盡量避開(kāi)一些不必要的錯(cuò)誤,一步步提高自己。在今后的學(xué)習(xí)中,我還需要不斷學(xué)習(xí),不斷熬煉自己。 六、附:源代碼 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity clock is p

30、ort( clk:in std_logic; 時(shí)鐘 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); 六個(gè)晶體管 end entity clock; architecture one of clock is signal sel:std_logic_vector(2 downto 0); signal hou1:std_logic_vector(3 d

31、ownto 0); -時(shí)分秒的個(gè)位和十位 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); signal seth2:std_logic_vector(3 downto 0); signal setm1:std_logic_vector(3 downto 0); signal setm2:std_logic_v

32、ector(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_logic_vector(3 downto 0); signal m2:std_logic_vector(3 downto 0); signal s1:std_logic_vector(3 downto 0

33、); 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:std_logic; -進(jìn)位 signal switch :std_logic_vector(1 downto 0); -表示狀態(tài) begin process (clk) is -defi

34、ne 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; process(sec_co) is 秒個(gè)位 begin if switch=00 then -正常狀態(tài) if sec_co=1 then if sec2=1001 then sec2=0000; co1=1; else sec2=sec2+1; co1

35、=0; end if; end if; elsif switch=01 then -調(diào)時(shí)狀態(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 switch=01 then sec1=0000; end if; end process; process (co1,co2)

36、is 分鐘個(gè)位 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 then if co3=1 then if min1=0101 then min1=0000; co4=1; else min1=min1

37、+1; co4=0; end if; end if; elsif switch=01 then min1=setm1; end if; end process; process(co4) 小時(shí) begin if switch=00 then if co4=1 then if (hou1=0010) then -小時(shí)十位為2時(shí),個(gè)位滿3進(jìn)一 if(hou2=0011)then hou2=0000; hou1=0000; else hou2=hou2+1; end if; else -小時(shí)十位為0或1,個(gè)位滿9進(jìn)一 if(hou2=1001)then hou2=0000; hou1=hou1+1;

38、 else hou2=hou2+1; end if; end if; end if; elsif switch=01 then hou1=seth1; hou2=seth2; end if; end process; process (setclk(0) is -掌握時(shí)鐘狀態(tài),00正常,01調(diào)時(shí),10鬧鐘 begin if(setclk(0)event and setclk(0)=1)then if(switch=10)then switch=00; else switch=switch+1; end if; end if; end process; process (setclk(2),sw

39、itch,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=setm1+1; end if; else setm2=setm2+1; end if; end if; end if; end process; process (setclk(2),switch,setclk(1) is be

40、gin -setclk(1)為0調(diào)時(shí) 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 if(seth2=1001)then seth1=seth1+1; seth2=0000; else seth2=seth2+1; end if; end if; end if; end if; end process; pr

41、ocess (switch) is 鬧鈴 begin -設(shè)置鬧鈴時(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 if(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;

42、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(sph1=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

43、+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 spm2=min2)then speak=clk; else speak=0; end if; end process; process(clk) 模6計(jì)數(shù) begin 掌握晶體管顯示 if clkevent and clk=1 then if se

44、l=101 then sel=000; else sel=sel+1; end if; end if; end process; process(sel) is begin h1=hou1;h2=hou2;m1=min1;m2=min2;s1=sec1;s2=sec2; d1=1;d2=1;d3=1;d4=1;d5=1;d6=1; if(switch=10)then -調(diào)鬧鐘時(shí),顯示鬧鐘設(shè)置時(shí)間 if sel=000 then d1=0; case sph1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=

45、10100100; when others=dout=XXXXXXXX; end case; elsif sel=001 then d2=0; case sph2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=

46、10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX; end case; elsif sel=010 then d3=0; case spm1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when others=dout=XXXXXXXX; end case; els

47、if sel=011 then d4=0; case spm2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when others=dou

48、t=XXXXXXXX; end case; elsif sel=100 then d5=0; case sps1 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when others=dout=XXXXXXXX; end case; elsif sel=101 then d6=0; case sps2 is when 0000=dout=11000000; when 0001=dout=11111001; when 0010=dout=10100100; when 0011=dout=10110000; when 0100=dout=10011001; when 0101=dout=10010010; when 0110=dout=10000010; when 0111=dout=11111000; when 1000=dout=10000000; when 1001=dout=10010000; when others=dout=XXXXXXXX;

溫馨提示

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

評(píng)論

0/150

提交評(píng)論