這里說得很詳細(xì): 參考資料:
給你發(fā)一段
數(shù)碼管的掃描顯示: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語言輸入方式,以時鐘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;----時鐘/清零信號 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);---計數(shù) 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----當(dāng)clr為1時,高低位均為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----當(dāng)記數(shù)為98(實際是經(jīng)過59個記時脈沖) co<='1';----進(jìn)位 cnt0:="1001";----低位為9 elsif cnt0<"1001" then----小于9時 cnt0:=cnt0+1;----計數(shù)--elsif cnt0="1001" then--clk1<=not clk1; else cnt0:="0000"; if cnt1<"1001" then----高位小于9時 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;----時鐘/清零信號 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);---計數(shù) begin if clr='1' then----當(dāng)ckr為1時,高低位均為0 cnt1:="0000"; cnt0:="0000"; elsif clk'event and clk='1' then if cnt1="0101" and cnt0="1000" then----當(dāng)記數(shù)為58(實際是經(jīng)過59個記時脈沖) co<='1';----進(jìn)位 cnt0:="1001";----低位為9 elsif cnt0<"1001" then----小于9時 cnt0:=cnt0+1;----計數(shù) else cnt0:="0000"; if cnt1<"0101" then----高位小于5時 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. 時模塊程序清單 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity HOUR is port(clk,en:in std_logic;----輸入時鐘/高電平有效的使能信號 h1,h0:out std_logic_vector(3 downto 0));----時高位/低位 end HOUR; architecture hour_arc of HOUR is begin process(clk) variable cnt1,cnt0:std_logic_vector(3 downto 0);----記數(shù) begin if clk'event and clk='1' then---上升沿觸發(fā) if en='1' then---同時“使能”為1 if cnt1="0010" and cnt0="0011" then cnt1:="0000";----高位/低位同時為0時 cnt0:="0000"; elsif cnt0<"1001" then----低位小于9時,低位記數(shù)累加 cnt0:=cnt0+1; else cnt0:="0000"; cnt1:=cnt1+1;-----高位記數(shù)累加 end if; end if; end if; h1<=cnt1; h0<=cnt0; end process; end hour_arc; 6. 動態(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;------掃描時鐘 secm1,secm0,sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-----分別為秒個位/時位;分個位/ 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);----計數(shù)信號 begin sel="111") then count<="000"; else countdaoutdaoutdaoutdaoutdaoutdaoutdaoutdaout<=h1; end case; end process; end fun;7. 報時模塊 library ieee; use ieee.std_logic_1164.all; 。
我不是學(xué)姐,答案我就不幫你做了,給你一些提示,希望你能獨立完成。
1:先選對計數(shù)器,根據(jù)需要選擇4位,8位,32位(如果沒有32位的計數(shù)器可以用2個16位的計數(shù)器級聯(lián)起來,第一級的計數(shù)器的高位輸出驅(qū)動第二級的計數(shù)器始終)2:10進(jìn)制,12進(jìn)制,60進(jìn)制的計數(shù)器怎么做?你需要一個比較器,比較器輸入端比較counter的值和一個preset value,如果兩個值相等,則輸出一,否則輸出0,用這個比較信號來控制counter的復(fù)位信號,注意有些復(fù)位是低電平有效3:有了上面的這些計數(shù)器以后怎么做時鐘?用級聯(lián)的方式把上面這些計數(shù)器串聯(lián)起來,也就是說用function generator 產(chǎn)生一個10Hz的頻率分秒的比較器輸出當(dāng)作秒的時鐘輸入(enable也可以),同樣的道理,秒的計數(shù)器的比較器出入做分的計數(shù)器的十種輸入。
我不是學(xué)姐,答案我就不幫你做了,給你一些提示,希望你能獨立完成。
1:先選對計數(shù)器,根據(jù)需要選擇4位,8位,32位(如果沒有32位的計數(shù)器可以用2個16位的計數(shù)器級聯(lián)起來,第一級的計數(shù)器的高位輸出驅(qū)動第二級的計數(shù)器始終)
2:10進(jìn)制,12進(jìn)制,60進(jìn)制的計數(shù)器怎么做?
你需要一個比較器,比較器輸入端比較counter的值和一個preset value,如果兩個值相等,則輸出一,否則輸出0,用這個比較信號來控制counter的復(fù)位信號,注意有些復(fù)位是低電平有效
3:有了上面的這些計數(shù)器以后怎么做時鐘?
用級聯(lián)的方式把上面這些計數(shù)器串聯(lián)起來,也就是說
用function generator 產(chǎn)生一個10Hz的頻率分秒的比較器輸出當(dāng)作秒的時鐘輸入(enable也可以),同樣的道理,秒的計數(shù)器的比較器出入做分的計數(shù)器的十種輸入。
聲明:本網(wǎng)站尊重并保護知識產(chǎn)權(quán),根據(jù)《信息網(wǎng)絡(luò)傳播權(quán)保護條例》,如果我們轉(zhuǎn)載的作品侵犯了您的權(quán)利,請在一個月內(nèi)通知我們,我們會及時刪除。
蜀ICP備2020033479號-4 Copyright ? 2016 學(xué)習(xí)鳥. 頁面生成時間:2.555秒