濰坊營銷型網(wǎng)站建設(shè)防止惡意點擊軟件管用嗎
忽如一夜春風(fēng)來,千樹萬樹梨花開
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? —— 《白雪歌誦武判官歸京》? 岑參? 【唐】
目錄
簡易數(shù)字鐘
要點剖析:?
?逐步分析:
端口說明:
代碼展示:
分部解釋:
代碼編譯結(jié)果:
提醒 :
仿真實例:
仿真結(jié)果:
?編輯?
求一個免費的贊,也可以點一點關(guān)注,十分感謝
簡易數(shù)字鐘代碼和PPT
通過網(wǎng)盤分享的文件:簡易數(shù)字鐘.zip
鏈接: https://pan.baidu.com/s/1oQ3v6up_G5D2VKsISCRmBQ?pwd=0406提取碼: 0406
為大家?guī)頂?shù)電課設(shè)(簡易數(shù)字鐘)的教程。本教程基于Quartus Ⅱ來編寫代碼,進行仿真。文章內(nèi)有代碼,仿真報告,答辯PPT,按需自取。
簡易數(shù)字鐘
大家先看一看上面的題目和其要求實現(xiàn)的功能。
要點剖析:?
- 利用quartus軟件,基于VHDL語言來編寫。
- 時,分,秒三個計數(shù)器,分別是二十四進制計數(shù)器和六十進制計數(shù)器。
- 鬧鐘功能,并且設(shè)定時間,到時間鳴叫30秒。
- 具有整點報時功能,到預(yù)定時間鳴叫10秒。
- 完成仿真,具有基本功能。
?逐步分析:
1.對于這一點大家從b站找教程或者某寶找人遠程下載,對于vhdl語言大家可以自行學(xué)習(xí),這個課設(shè)需要的代碼造詣不高,大家完全可以自學(xué)(相較于C++就十分簡單了)。
2.計時器,VHDL代碼內(nèi)有基本的語法結(jié)構(gòu),我們只需要知道二十四位計數(shù)器需要五位二進制數(shù),六十進制計數(shù)器需要六位二進制數(shù),這就ok了。
3.鬧鐘功能,這個就需要我們獨立設(shè)計邏輯。
4.整點報時基本和鬧鐘功能有著類似的代碼邏輯,大家看后續(xù)代碼。
5.仿真,大家就利用軟件內(nèi)置的來做。
端口說明:
代碼展示:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;entity Simple_Clock isport(clk : in std_logic; reset : in std_logic;set_alarm : in std_logic;alarm_time_sec : in std_logic_vector(5 downto 0);alarm_time_min : in std_logic_vector(5 downto 0);alarm_time_hour : in std_logic_vector(4 downto 0);alarm_out : out std_logic;chime_out : out std_logic;sec_out : out std_logic_vector(5 downto 0);min_out : out std_logic_vector(5 downto 0);hour_out : out std_logic_vector(4 downto 0));
end entity Simple_Clock;architecture Behavioral of Simple_Clock issignal sec_count : unsigned(5 downto 0) := (others => '0');--六位無符號數(shù),初始全為0signal min_count : unsigned(5 downto 0) := (others => '0');signal hour_count : unsigned(4 downto 0) := (others => '0');signal alarm_active : std_logic := '0';--表示鬧鐘是否激活signal chime_active : std_logic := '0';--表示整點報時是否激活signal alarm_timer : unsigned(4 downto 0) := (others => '0');--鬧鐘激活后的計時signal chime_timer : unsigned(3 downto 0) := (others => '0');signal alarm_time_sec_u : unsigned(5 downto 0);--類型轉(zhuǎn)換為無符號的數(shù)signal alarm_time_min_u : unsigned(5 downto 0);signal alarm_time_hour_u : unsigned(4 downto 0);
begin-- 轉(zhuǎn)換輸入為unsigned類型alarm_time_sec_u <= unsigned(alarm_time_sec);alarm_time_min_u <= unsigned(alarm_time_min);alarm_time_hour_u <= unsigned(alarm_time_hour);-- 秒計數(shù)器process(clk, reset)--上下限beginif reset = '1' then-- 重置所有信號sec_count <= (others => '0');min_count <= (others => '0');hour_count <= (others => '0');alarm_active <= '0';chime_active <= '0';alarm_timer <= (others => '0');chime_timer <= (others => '0');elsif rising_edge(clk) then-- 秒計數(shù)邏輯if sec_count = 59 thensec_count <= (others => '0');if min_count = 59 thenmin_count <= (others => '0');if hour_count = 23 thenhour_count <= (others => '0');elsehour_count <= hour_count + 1;end if;elsemin_count <= min_count + 1;end if;elsesec_count <= sec_count + 1;end if;-- 鬧鐘邏輯if alarm_active = '1' and alarm_timer < 30 then--如果激活鬧鐘,那么鬧鐘計時小于30秒則加一,響鈴一段時間alarm_timer <= alarm_timer + 1;elsif alarm_timer >= 30 then--大于三十則清零,便于下次計時alarm_active <= '0';alarm_timer <= (others => '0');end if;-- 整點報時邏輯if chime_active = '1' and chime_timer < 10 thenchime_timer <= chime_timer + 1;elsif chime_timer >= 10 thenchime_active <= '0';--關(guān)閉計時狀態(tài)chime_timer <= (others => '0');end if;-- 激活鬧鐘和整點報時if set_alarm = '1' and sec_count = alarm_time_sec_u and min_count = alarm_time_min_u and hour_count = alarm_time_hour_u thenalarm_active <= '1';--啟動鬧鐘alarm_timer <= (others => '0');elsif sec_count = 0 and min_count = 0 then--分,秒為零,意味著整點chime_active <= '1';chime_timer <= (others => '0');end if;end if;end process;-- 輸出信號alarm_out <= alarm_active;chime_out <= chime_active;sec_out <= std_logic_vector(sec_count);min_out <= std_logic_vector(min_count);hour_out <= std_logic_vector(hour_count);
end architecture Behavioral;
分部解釋:
-- 秒計數(shù)器process(clk, reset)--上下限beginif reset = '1' then-- 重置所有信號sec_count <= (others => '0');min_count <= (others => '0');hour_count <= (others => '0');alarm_active <= '0';chime_active <= '0';alarm_timer <= (others => '0');chime_timer <= (others => '0');elsif rising_edge(clk) then這里首先編寫了一個關(guān)于清零的功能(類似于函數(shù),但是并不調(diào)用)
是全部清零,包括鬧鐘的計時,時鐘的計時都是會清零的,類似于恢復(fù)出廠設(shè)置-- 秒計數(shù)邏輯if sec_count = 59 thensec_count <= (others => '0');if min_count = 59 thenmin_count <= (others => '0');if hour_count = 23 thenhour_count <= (others => '0');elsehour_count <= hour_count + 1;end if;elsemin_count <= min_count + 1;end if;elsesec_count <= sec_count + 1;end if;這就是計時功能的相關(guān)代碼,我們編寫了計時功能,只要秒鐘累加到59,那么下一次就會分鐘加1,只要分鐘累加到59,那么就會時鐘加1。如果時鐘累加到23,那么就會清零。-- 鬧鐘邏輯if alarm_active = '1' and alarm_timer < 30 then--如果激活鬧鐘,那么鬧鐘計時小于30秒則加一,響鈴一段時間alarm_timer <= alarm_timer + 1;elsif alarm_timer >= 30 then--大于三十則清零,便于下次計時alarm_active <= '0';alarm_timer <= (others => '0');end if;-- 整點報時邏輯if chime_active = '1' and chime_timer < 10 thenchime_timer <= chime_timer + 1;elsif chime_timer >= 10 thenchime_active <= '0';--關(guān)閉計時狀態(tài)chime_timer <= (others => '0');end if;兩個功能的邏輯十分相似,都有一個置1且相關(guān)計時小于我們要求響鈴的時長(鬧鐘 30;報時 10)那么就會響鈴一段時間,如果功能內(nèi)部的timer大于要求響鈴的時長,那么timer就會清零,便于我們下一次使用-- 激活鬧鐘和整點報時if set_alarm = '1' and sec_count = alarm_time_sec_u and min_count = alarm_time_min_u and hour_count = alarm_time_hour_u thenalarm_active <= '1';--啟動鬧鐘alarm_timer <= (others => '0');elsif sec_count = 0 and min_count = 0 then--分,秒為零,意味著整點chime_active <= '1';chime_timer <= (others => '0');end if;end if;end process;激活鬧鐘,首先要set_alarm = '1',然后給鬧鐘制定時間,到時間就會自動響鈴。
激活整點報時,我們不需要set這個邏輯(因為整點報時是一直開著的),當(dāng)分和秒為零,那么就意味著整點,即可以響鈴
代碼編譯結(jié)果:
?
提醒 :
清零之后鬧鐘會響鈴!這是因為我的代碼中設(shè)置了在清零后鬧鐘響鈴的程序(只要在鬧鐘打開的時間內(nèi)清零,鬧鐘在清零結(jié)束后就會響鈴)。我認為是有用的,也可以當(dāng)作防偽標(biāo)志。
仿真實例:
定時鬧鐘在45分時響鈴。
仿真結(jié)果:
大家可以看一看ppt從中可以找到更多細節(jié)。?