這里說(shuō)得很詳細: 參考資料:
給你發(fā)一段
數碼管的掃描顯示:LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; -字模輸出模塊
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY SEL IS PORT(CLK:IN STD_LOGIC; Q:OUT STD_LOGIC_VECTOR(2 DOWNTO 0)); --輸入選通信號END SEL;ARCHITECTURE SELA OF SEL ISBEGIN PROCESS(CLK) VARIABLE CNT:STD_LOGIC_VECTOR(2 DOWNTO 0); BEGIN IF CLK'EVENT AND CLK='1' THEN CNT:=CNT+1; END IF; Q
2. 微秒模塊 采用VHDL語(yǔ)言輸入方式,以時(shí)鐘clk,清零信號clr以及暫停信號STOP為進(jìn)程敏感變量,程序如下:library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity MINSECONDb is port(clk,clrm,stop:in std_logic;----時(shí)鐘/清零信號 secm1,secm0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------輸出/進(jìn)位信號 end MINSECONDb; architecture SEC of MINSECONDb is signal clk1,DOUT2:std_logic; begin process(clk,clrm) variable cnt1,cnt0:std_logic_vector(3 downto 0);---計數 VARIABLE COUNT2 :INTEGER RANGE 0 TO 10 ; begin IF CLK'EVENT AND CLK='1'THEN IF COUNT2>=0 AND COUNT2<10 THEN COUNT2:=COUNT2+1; ELSE COUNT2:=0; DOUT2<= NOT DOUT2; END IF; END IF; if clrm='1' then----當clr為1時(shí),高低位均為0 cnt1:="0000"; cnt0:="0000"; elsif clk'event and clk='1' then if stop='1' then cnt0:=cnt0; cnt1:=cnt1; end if; if cnt1="1001" and cnt0="1000" then----當記數為98(實(shí)際是經(jīng)過(guò)59個(gè)記時(shí)脈沖) co<='1';----進(jìn)位 cnt0:="1001";----低位為9 elsif cnt0<"1001" then----小于9時(shí) cnt0:=cnt0+1;----計數--elsif cnt0="1001" then--clk1<=not clk1; else cnt0:="0000"; if cnt1<"1001" then----高位小于9時(shí) cnt1:=cnt1+1; else cnt1:="0000"; co<='0'; end if; end if; end if; secm1<=cnt1; secm0<=cnt0; end process; end SEC;3. 秒模塊程序清單 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity SECOND is port(clk,clr:in std_logic;----時(shí)鐘/清零信號 sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------輸出/進(jìn)位信號 end SECOND; architecture SEC of SECOND is begin process(clk,clr) variable cnt1,cnt0:std_logic_vector(3 downto 0);---計數 begin if clr='1' then----當ckr為1時(shí),高低位均為0 cnt1:="0000"; cnt0:="0000"; elsif clk'event and clk='1' then if cnt1="0101" and cnt0="1000" then----當記數為58(實(shí)際是經(jīng)過(guò)59個(gè)記時(shí)脈沖) co<='1';----進(jìn)位 cnt0:="1001";----低位為9 elsif cnt0<"1001" then----小于9時(shí) cnt0:=cnt0+1;----計數 else cnt0:="0000"; if cnt1<"0101" then----高位小于5時(shí) cnt1:=cnt1+1; else cnt1:="0000"; co<='0'; end if; end if; end if; sec1<=cnt1; sec0<=cnt0; end process; end SEC;4. 分模塊程序清單 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity MINUTE is port(clk,en:in std_logic; min1,min0:out std_logic_vector(3 downto 0); co:out std_logic); end MINUTE; architecture MIN of MINUTE is begin process(clk) variable cnt1,cnt0:std_logic_vector(3 downto 0); begin if clk'event and clk='1' then if en='1' then if cnt1="0101" and cnt0="1000" then co<='1'; cnt0:="1001"; elsif cnt0<"1001" then cnt0:=cnt0+1; else cnt0:="0000"; if cnt1<"0101" then cnt1:=cnt1+1; else cnt1:="0000"; co<='0'; end if; end if; end if; end if; min1<=cnt1; min0<=cnt0; end process; end MIN;5. 時(shí)模塊程序清單 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity HOUR is port(clk,en:in std_logic;----輸入時(shí)鐘/高電平有效的使能信號 h1,h0:out std_logic_vector(3 downto 0));----時(shí)高位/低位 end HOUR; architecture hour_arc of HOUR is begin process(clk) variable cnt1,cnt0:std_logic_vector(3 downto 0);----記數 begin if clk'event and clk='1' then---上升沿觸發(fā) if en='1' then---同時(shí)“使能”為1 if cnt1="0010" and cnt0="0011" then cnt1:="0000";----高位/低位同時(shí)為0時(shí) cnt0:="0000"; elsif cnt0<"1001" then----低位小于9時(shí),低位記數累加 cnt0:=cnt0+1; else cnt0:="0000"; cnt1:=cnt1+1;-----高位記數累加 end if; end if; end if; h1<=cnt1; h0<=cnt0; end process; end hour_arc; 6. 動(dòng)態(tài)掃描模塊 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity SELTIME is port( clk:in std_logic;------掃描時(shí)鐘 secm1,secm0,sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-----分別為秒個(gè)位/時(shí)位;分個(gè)位/ daout:out std_logic_vector(3 downto 0);----------------輸出 sel:out std_logic_vector(2 downto 0));-----位選信號 end SELTIME; architecture fun of SELTIME is signal count:std_logic_vector(2 downto 0);----計數信號 begin sel="111") then count<="000"; else countdaoutdaoutdaoutdaoutdaoutdaoutdaoutdaout<=h1; end case; end process; end fun;7. 報時(shí)模塊 library ieee; use ieee.std_logic_1164.all; 。
我不是學(xué)姐,答案我就不幫你做了,給你一些提示,希望你能獨立完成。
1:先選對計數器,根據需要選擇4位,8位,32位(如果沒(méi)有32位的計數器可以用2個(gè)16位的計數器級聯(lián)起來(lái),第一級的計數器的高位輸出驅動(dòng)第二級的計數器始終)2:10進(jìn)制,12進(jìn)制,60進(jìn)制的計數器怎么做?你需要一個(gè)比較器,比較器輸入端比較counter的值和一個(gè)preset value,如果兩個(gè)值相等,則輸出一,否則輸出0,用這個(gè)比較信號來(lái)控制counter的復位信號,注意有些復位是低電平有效3:有了上面的這些計數器以后怎么做時(shí)鐘?用級聯(lián)的方式把上面這些計數器串聯(lián)起來(lái),也就是說(shuō)用function generator 產(chǎn)生一個(gè)10Hz的頻率分秒的比較器輸出當作秒的時(shí)鐘輸入(enable也可以),同樣的道理,秒的計數器的比較器出入做分的計數器的十種輸入。
我不是學(xué)姐,答案我就不幫你做了,給你一些提示,希望你能獨立完成。
1:先選對計數器,根據需要選擇4位,8位,32位(如果沒(méi)有32位的計數器可以用2個(gè)16位的計數器級聯(lián)起來(lái),第一級的計數器的高位輸出驅動(dòng)第二級的計數器始終)
2:10進(jìn)制,12進(jìn)制,60進(jìn)制的計數器怎么做?
你需要一個(gè)比較器,比較器輸入端比較counter的值和一個(gè)preset value,如果兩個(gè)值相等,則輸出一,否則輸出0,用這個(gè)比較信號來(lái)控制counter的復位信號,注意有些復位是低電平有效
3:有了上面的這些計數器以后怎么做時(shí)鐘?
用級聯(lián)的方式把上面這些計數器串聯(lián)起來(lái),也就是說(shuō)
用function generator 產(chǎn)生一個(gè)10Hz的頻率分秒的比較器輸出當作秒的時(shí)鐘輸入(enable也可以),同樣的道理,秒的計數器的比較器出入做分的計數器的十種輸入。
聲明:本網(wǎng)站尊重并保護知識產(chǎn)權,根據《信息網(wǎng)絡(luò )傳播權保護條例》,如果我們轉載的作品侵犯了您的權利,請在一個(gè)月內通知我們,我們會(huì )及時(shí)刪除。
蜀ICP備2020033479號-4 Copyright ? 2016 學(xué)習?shū)B(niǎo). 頁(yè)面生成時(shí)間:2.555秒