?? vhdl-ysw.txt
字號:
第一個CNT60實現秒鐘計時功能,第二個CNT60實現分鐘的計時功能,CTT3完成兩小時的計時功能。秒鐘計時模塊的進位端和開關K1相與提供分鐘的計時模塊使能,當秒種計時模塊計時到59時向分種計時模塊進位,同時自己清零。同理分種計時模塊到59時向CTT3小時計時模塊進位,到1小時59分59秒時,全部清零。同時,開關K1可以在兩小時內暫停秒鐘計時模塊,分鐘計時模塊和小時計時模塊。各模塊的VHDL語言描述如下:
(1).六十進制計數器
我們采用VHDL語言編寫,該計數器具有使能,異位復位的功能的8位加法計數器,其語言描述如下:
六十進制記數
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt60 is
port(clk:in std_logic;
rst:in std_logic;
ena:in std_logic;
qn:in std_logic_vector(7 downto 0);
out0:out std_logic_vector(3 downto 0);
out1:out std_logic_vector(3 downto 0);
cout:out std_logic);
end cnt60;
architecture behav of cnt60 is
signal cqi:std_logic_vector(7 downto 0);
begin
cout<='1' when (cqi=X"59"and ena='1') else'0';
process(clk,rst,ena)
begin
if(rst='0')then
cqi<=X"00";
elsif clk'event and clk='1' then
if(ena='0')then
cqi<=qn;
elsif (ena='1') then
if cqi(3 downto 0)=9 then
cqi(3 downto 0)<="0000";
if cqi(7 downto 4)=5 then
cqi(7 downto 4)<="0000";
else
cqi(7 downto 4)<=cqi(7 downto 4)+1;
end if;
else
cqi(3 downto 0)<=cqi(3 downto 0)+1;
end if;
end if;
end if;
end process ;
out0<=cqi(3 downto 0);
out1<=cqi(7 downto 4);
end behav;
其管腳定義為:
CLK: 時鐘;
RST: 復位;
RNA: 使能;
QN[7..0]: 預置數控制;
OUT0[3..0]:個位數據輸出;
OUT1[3..0]:十位數據輸出;
COUT: 進位輸出。
其仿真波形如下:
(2).三進制計數器:
同理,我們也用VHDL語言實現,該計數器具有使能,異位復位的功能的4位加法計數器,其語言描述如下:
三進制計數
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ctt3 is
port(cp,rd,ld,en:in std_logic;
co:out std_logic;
q:out std_logic_vector(3 downto 0));
end ctt3;
architecture god of ctt3 is
signal qn:std_logic_vector(3 downto 0);
begin
co<='1' when (qn=X"1"and en='1') else'0';
process(cp,rd)
begin
if(rd='0')then
qn<=X"0";
elsif (cp'event and cp='1') then
if(ld='0')then
qn<=X"0";
elsif (en='1') then
if qn(3 downto 0)=1 then
qn(3 downto 0)<="0000";
else
qn(3 downto 0)<=qn(3 downto 0)+1;
end if;
end if;
end if;
end process;
q(3 downto 0)<=qn(3 downto 0);
end god;
其管腳定義為:
CLK: 時鐘;
RST: 復位;
RNA: 使能;
LD: 預置數控制;
CO: 進位輸出;
Q[3..0]: 數據輸出。
其仿真波形如下:
2. 倒記時模塊
該模塊主要由三十進制減計數器和分組模塊組成,三十進制減計數器的使能信號由時鐘模塊的進位和開關K1提供。當兩小時計時結束后,啟動倒計時模塊,K1開關可以控制在三十秒內停止計時,否則向借位端借位(即啟動報警模塊)。分組模塊是為了控制顯示甲方或乙方的倒計時時鐘。
(1).三十進制減計數器的VHDL語言如下,該計數器具有使能,異位復位的功能的8位減法計數器:
倒記時30倒數
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt30 is
port(cp,ld,rd,en:in std_logic;
co:out std_logic;
q1:out std_logic_vector(3 downto 0);
q2:out std_logic_vector(3 downto 0));
end cnt30;
architecture mine of cnt30 is
signal qn:std_logic_vector(7 downto 0);
begin
co<='1' when (qn=X"00"and en='1') else '0';
process(cp,rd)
begin
if(rd='0')then
qn<=X"00";
elsif (cp'event and cp='1') then
if(ld='0')then
qn<=X"29";
elsif (en='1') then
if qn(3 downto 0)=0 then
qn(3 downto 0)<="1001";
if qn(7 downto 4)=0 then
qn(7 downto 4)<="0010";
else
qn(7 downto 4)<=qn(7 downto 4)-1;
end if;
else
qn(3 downto 0)<=qn(3 downto 0)-1;
end if;
end if;
end if;
end process;
q1<=qn(3 downto 0);
q2<=qn(7 downto 4);
end mine;
其生成的三十進制減法計數器的電路模塊如下:
其管腳定義為:
CP: 時鐘;
RD: 復位;
EN: 使能;
LD: 預置數控制;
CO: 進位輸出;
Q1[3..0]: 個位數據輸出;
Q2[3..0]: 十位數據輸出。
其仿真波形如下:
(2). 分組倒記時模塊
該模塊用于顯示甲方或乙方的倒計時時間,其VHDL語言描述如下:
brary ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cel is
port( en: in std_logic;
d0: in std_logic_vector(3 downto 0);
d1: in std_logic_vector(3 downto 0);
q: out std_logic_vector(3 downto 0));
end cel;
architecture bhv of cel is
begin
process(en,d0,d1)
begin
if en='1' then
q<=d0;
else
q<=d1;
end if;
end process;
end bhv;
3. 輸出顯示模塊
該模塊由選擇輸出顯示模塊,轉換模塊,選擇顯示管模塊以及七段顯示模塊組成。選擇輸出顯示模塊選擇顯示兩方的分鐘的各位,十位,小時的各位還是倒計時時鐘的各位,十位。轉換模塊用于預置選擇顯示管模塊的輸入初值。選擇顯示管模塊分配顯示管顯示分鐘的各位,十位,小時的各位和倒計時時鐘的各位,十位。七段顯示模塊用于驅動顯示譯碼器。
(1). 選擇輸出顯示模塊
其VHDL語言描述如下:
當輸入的SEL信號不同時,輸出顯示不同的位數。
library ieee;
use ieee.std_logic_1164.all;
entity cho is
port(fen1,fen0,sec1,sec0:in std_logic_vector(3 downto 0);
dao1,dao0,h1,h0:in std_logic_vector(3 downto 0);
sel:in std_logic_vector(2 downto 0);
q:out std_logic_vector(3 downto 0));
end cho;
architecture bbb_arc of cho is
begin
process(sel)
begin
case sel is
when "000"=>q<=ge0;
when "001"=>q<=shi0;
when "010"=>q<=h0;
when "011"=>q<=ge1;
when "100"=>q<=shi1;
when "101"=>q<=h1;
when "110"=>q<=dao0;
when "111"=>q<=dao1;
when others=>q<="1111";
end case;
end process;
end bbb_arc;
(2).轉換模塊
該模塊主要是針對我們實驗箱上八段數碼顯示管是串行輸出,而我們顯示時間時必須采用并行輸出,所以我們需要對其進行轉換,當頻率很高時,可以看到8個八段數碼顯示管動態顯示時間與倒計時時間。其輸出送入選擇輸出顯示模塊和選擇顯示管模塊實現這兩個模塊的選擇。
其VHDL描述如下:
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 sel_arc of sel is
begin
process(clk)
variable cnt:std_logic_vector(2 downto 0);
begin
if clk'event and clk='1' then
cnt:=cnt+1;
end if;
q<=cnt;
end process;
end sel_arc;
(3). 選擇顯示管模塊
該模塊對八段數碼顯示管進行分配,分別顯示甲,乙時間和倒計時時間。
其VHDL語言描述如下:
library ieee;
use ieee.std_logic_1164.all;
entity xuan is
port (sel:in std_logic_vector(2 downto 0);
cout:out std_logic_vector(7 downto 0));
end xuan;
architecture one of xuan is
begin
process(sel)
begin
case sel is
when "000"=>cout<="00000001";
when "001"=>cout<="00000010";
when "010"=>cout<="00000100";
when "011"=>cout<="00001000";
when "100"=>cout<="00010000";
when "101"=>cout<="00100000";
when "110"=>cout<="01000000";
when "111"=>cout<="10000000";
when others=>cout<="00000000";
end case;
end process;
end one;
(4). 七段顯示模塊
該模塊用于驅動八段顯示管。其VHDL語言描述如下:
library ieee;
use ieee.std_logic_1164.all;
entity dec7s is
port(d:in std_logic_vector(3 downto 0);
led7s:out std_logic_vector(6 downto 0));
end ;
architecture one of dec7s is
begin
process(d)
begin
case d is
when"0000"=>led7s<="0111111";
when"0001"=>led7s<="0000110";
when"0010"=>led7s<="1011011";
when"0011"=>led7s<="1001111";
when"0100"=>led7s<="1100110";
when"0101"=>led7s<="1101101";
when"0110"=>led7s<="1111101";
when"0111"=>led7s<="0000111";
when"1000"=>led7s<="1111111";
when"1001"=>led7s<="1101111";
when others=>null;
end case;
end process;
end ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -