【正文】
1 基于 vhdl 的數(shù)字鐘設計 一、 設計要求 具有以二十四小時計時、顯示、整點報時、時間設置和鬧鐘的功能。 設計精度要求為 1S。 二.系統(tǒng)功能描述 1 . 系統(tǒng)輸入:系統(tǒng)狀態(tài)及校時、定時轉(zhuǎn)換的控制信號為 k、trans、 set; 時鐘信號 clk,采用 1024Hz; 系統(tǒng)復位信號為 reset。輸入信號均由按鍵產(chǎn)生。 系統(tǒng)輸出: LED 顯示輸出,蜂鳴器聲音信號輸出。 多功能數(shù)字鐘系統(tǒng)功能的具體描述如 下: 2. 計時:正常工作狀態(tài)下,每日按 24h 計時制計時并顯示,蜂鳴器無聲,逢整點報時。 3. 校時:在計時狀態(tài)顯示下,按下“ set 鍵”,進入“小時”校準狀態(tài),之后按下“ k鍵”則進入“分”校準狀態(tài),繼續(xù)按下“ k 鍵”則進入“秒復零”狀態(tài),第三次按下“ k 鍵”又恢復到正常計時顯示狀態(tài)。 1)“小時”校準狀態(tài):在“小時”校準狀態(tài)下,顯示“小時”數(shù)碼管以 1Hz 的頻率遞增計數(shù)。 2)“分”校準狀態(tài):在“分”校準狀態(tài)下,顯示“分”的數(shù)碼管以 1Hz 的頻率遞增計數(shù)。 2 3)“秒”復零狀態(tài):在“秒復零”狀態(tài)下,顯示“秒”的數(shù)碼管復零。 4. 整點報時:蜂鳴器在“ 59”分鐘的第“ 51”、“ 53”、“ 55”、“ 57‘秒發(fā)頻率為 512Hz 的低音,在“ 59”分鐘的第“ 59”秒發(fā)頻率為 1024Hz 的高音,結(jié)束時為整點。 5. 顯示:要求采用掃描顯示方式驅(qū)動 6 個 LED 數(shù)碼管顯示小時、分、秒。 鬧鐘:鬧鐘定時時間到,蜂鳴器發(fā)出周期為 1s 的“滴”、“滴”聲,持續(xù)時間為 10s;鬧鐘定時顯示。 6. 鬧鐘定時設置:在鬧鐘定時顯示狀態(tài)下,按下“ set 鍵”,進入鬧鐘的“時”設置狀態(tài),之后按下“ k 鍵”進入鬧鐘的“分”設置狀態(tài),繼續(xù)按下“ k 鍵” 則進入“秒”設置狀 態(tài),第三次按下“ k 鍵”又恢復到鬧鐘定時顯示狀態(tài)。 1) 鬧鐘“小時”設置狀態(tài):在鬧鐘“小時”設置狀態(tài)下, 顯示“小時”的數(shù)碼管 以 1Hz 的頻率遞增計數(shù)。 2) 鬧鐘:“分”設置狀態(tài):在鬧鐘“分”設置狀態(tài)下,顯示“分” 的數(shù)碼管以 1Hz 的頻率遞增計數(shù)。 三、 控制器的 MDS 圖及多功能數(shù)字系統(tǒng)結(jié)構(gòu)邏輯框圖 S0:顯示計時時間 S4:顯示鬧鈴時間 s1:調(diào)計時的時 s5:調(diào)鬧鈴的時 s2:調(diào)計時的分 s6:調(diào)鬧鈴的分 s3:調(diào)計時的秒 s7:調(diào)鬧鈴的秒 3 四、總電路圖及各分塊的電路圖、原始程序、仿真圖。共分七大模塊:主控模塊、計時校時模塊、鬧鐘設定模塊、選擇顯示模塊、整點報時及鬧鈴模塊、分頻模塊、動態(tài)顯示模塊。 S0 S4 S2 S3 S7 S1 S5 S6 Trans=1 Set=1 Set=1 Set=1 Set=1 Set=1 Set=1 Set=1 Set=1 4 5 主控模塊電路圖 主控模塊代碼: library ieee。 use 。 use 。 use 。 entity control is port(clk,k,set,reset,trans : in std_logic。 jh,jm,js,nh,nm,ns,flashh,flashm,flashs,selct :out std_logic)。 end control。 architecture behav of control is type states is(s0,s1,s2,s3,s4,s5,s6,s7)。 signal current_state,next_state :states。 begin process (reset,clk,next_state,current_state,k,set) begin if (reset=39。139。)then current_state=s0。 elsif(clk39。event and clk=39。139。)then current_state=next_state。 end if。 case current_state is when s0= flashh=39。039。flashm=39。039。flashs=39。039。jh=39。039。jm=39。039。js=39。039。 nh=39。039。nm=39。039。ns=39。039。selct=39。139。 if(trans=39。139。)then next_state=s4。 elsif(set=39。139。 ) then next_state=s1。 else 6 next_state=s0。 end if。 when s1= flashh=39。139。flashm=39。039。flashs=39。039。jh=39。139。jm=39。039。js=39。039。 nh=39。039。nm=39。039。ns=39。039。selct=39。139。 if (set=39。139。)then next_state=s2。 else next_state=s1。 end if。 when s2= flashh=39。039。flashm=39。139。flashs=39。039。jh=39。039。jm=39。139。js=39。039。 nh=39。039。nm=39。039。ns=39。039。selct=39。139。 if (set=39。139。) then next_state=s3。 else next_state=s2。 end if。 when s3= flashh=39。039。flashm=39。039。flashs=39。139。jh=39。039。jm=39。039。js=39。139。 nh=39。039。nm=39。039。ns=39。039。selct=39。139。 if ( set=39。139。 ) then next_state=s0。 else next_state=s3。 end if。 when s4= flashh=39。039。flashm=39。039。flashs=39。039。jh=39。039。jm=39。039。js=39。039。 nh=39。039。nm=39。039。ns=39。039。selct=39。039。 if ( trans=39。139。 ) then next_state=s0。 elsif ( set=39。139。 ) then next_state=s5。 else next_state=s4。 end if。 when s5= flashh=39。139。flashm=39。039。flashs=39。039。jh=39。039。jm=39。039。js=39。039。 nh=39。139。nm=39。039。ns=39。039。selct=39。039。 if (set=39。139。) then next_state=s6。 else next_state=s5。 end if。 7 when s6= flashh=39。039。flashm=39。139。flashs=39。039。jh=39。039。jm=39。039。js=39。039。 nh=39。039。nm=39。139。ns=39。039。selct=39。039。 if (set=39。139。 ) then next_state=s7。 else next_state=s6。 end if。 when s7= flashh=39。039。flashm=39。039。flashs=39。139。jh=39。039。jm=39。039。js=39。039。 nh=39。039。nm=39。039。ns=39。139。selct=39。039。 If (set=39。139。) then next_state=s4。 else next_state=s7。 end if。 end case。 end process。 end behav。 主控模塊仿真圖 計時校時模塊 8 計時校時代碼 二選一 library ieee。 use 。 entity mux2_1 is port(d0,d1,en :in std_logic。 sel :in std_logic。 y :out std_logic)。 end mux2_1。 architecture mux2_1_arch of mux2_1 is begin process(d0,d1,sel) begin if(sel=39。039。)then y=d0。 elsif(sel=39。139。and en=39。139。)then y=d1 。 end if。 end process。 end mux2_1_arch。 六十進制計數(shù) library ieee。 use 。 use 。 9 entity count_60 is port(clk :in std_logic。 qh :buffer std_logic_vector(3 downto 0)。 ql :buffer std_logic_vector(3 downto 0)。 co :buffer std_logic)。 end count_60。 architecture behav of count_60 is begin process(clk) begin if(rising_edge(clk))then if(qh=0101and ql=1001)then qh=0000。co=39。139。ql=0000。 elsif(ql=1001)then ql=0000。qh=qh+1。co=39。039。 else ql=ql+1 。co=39。039。 end if。 end if。 end process。 end behav。 二十四進制計數(shù) library ieee。 use 。 use 。 entity count_24 is port(clk :in std_logic。 hh :buffer std_logic_vector(3 downto 0)。 hl :buffer std_logic_vector(3 downto 0))。 end count_24。 architecture behav of count_24 is begin process(clk) begin if(rising_edge(clk))then if(hh=0010and hl=0011)then hh=0000。hl=0000。 elsif(hl=1001)then hl=0000。hh=hh+1。 else hl=hl+1。 end if。 end if。 end process。 10 end behav。 計時校時仿真圖如下 鬧鐘設置模塊 鬧鐘時間設 置模塊代碼 library ieee。 use 。 use 。 use 。 entity clkset is port(hh,hl,mh,ml,sh :in std_logic_vector(3 downto 0)。 nh,nm,ns,f4 ,k:in std_logic。 bhg,bhd,bmg,bmd,bsg,bsd :buffer std_logic_vector(3 downto 0)。 out :out std_logic)。 end clkset 。 architecture behav of clkset is begin 11 :process(hh,mh,sh,hl,ml) begin if(bhg=hh and bhd=hl and bmg=mh and bmd=ml and bsg=sh)then out=39。139。 else out=39。039。 end if。 end process。 set:process(f4) begin if(f439。event and f4=39。13