接着上一篇博文继续完成电子时钟的设计。如果把各部分连接在一起的话就能完成电子时钟的基本设计了,当然网友们可以各显神通自己添加一些其他外加设备如日历、报警、调时、定时、或者做成多用计时/数器等等。有任何问题也在回复中提问。
上一篇博文用VHDL设计的六十进制的计数器这篇博文接着是24进制的计数器设计,稍加修改的话,再连接在一起就基本上能玩成一个电子时钟的设计了。
为了方便不同设计思想网友的选择兴趣,在此添加了十进制的计数器、二选一的选择器‘四选一选择器和七段数码管显示的设计以防不备之需。
下面是24进制计数器设计VHDL语言:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ESJZ IS
PORT(
CLK :IN STD_LOGIC; --时钟
EN :IN STD_LOGIC; --使能端
CR :IN STD_LOGIC; --清零端,低电平有效
LD :IN STD_LOGIC; --数据载入控制,低电平有效
D :IN STD_LOGIC_VECTOR(5 DOWNTO 0); --载入数据端
CO : OUT STD_LOGIC; --进位
Q :OUT STD_LOGIC_VECTOR(5 DOWNTO 0) --计时输出
);
END ESJZ ;
ARCHITECTURE a OF ESJZ IS
SIGNAL QN :STD_LOGIC_VECTOR(5 DOWNTO 0);
BEGIN --进位控制
CO<='1' WHEN(QN=X"23" AND EN='1')
ELSE'0';
PROCESS(CLK,CR)
BEGIN
IF (CR='0')THEN
QN<="000000";
ELSE
IF (CLK'EVENT AND CLK='1') THEN
IF (LD='0') THEN --数据加载
QN<=D;
ELSIF(EN='1') THEN
IF (QN(3 DOWNTO 0)=3 and QN(5 DOWNTO 4)=2) or QN(3 DOWNTO 0)=9 THEN
QN(3 DOWNTO 0)<="0000"; --个位数进位
IF QN(5 DOWNTO 4)=2 THEN
QN(5 DOWNTO 4)<="00"; --十位数进位
ELSE
QN(5 DOWNTO 4)<= QN(5 DOWNTO 4)+1;
END IF;
ELSE
QN(3 DOWNTO 0)<= QN(3 DOWNTO 0)+1;
END IF ;
END IF;
END IF ;
END IF;
END PROCESS;
Q<=QN;
end a
用VHDL写的带置数功能的十进制计数器
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Library IEEE;
Architecture behav Of cnt10 Is
signal s:Std_Logic_Vector(3 downto 0);
Begin
Process(clk,rst,sdata)
variable QI:Std_Logic_Vector(3 downto 0);
Begin
If rst='1' Then
QI:=(Others=>'0');
Elsif clk'event and clk='1' Then
If EN='1' THEN
QI:=sdata;
elsif EN='0' then
If QI<9 Then
QI:=QI+1;
Else QI:=(Others=>'0');
End If;
End IF;
End If;
If QI="9" Then
cout<='1';
Else
cout<='0';
End If;
case QI is
When "0000"=>seg<="0111111";
When "0001"=>seg<="0000110";
When "0010"=>seg<="1011011";
When "0011"=>seg<="1001111";
When "0100"=>seg<="1100110";
When "0101"=>seg<="1101101";
When "0110"=>seg<="1111101";
When "0111"=>seg<="0000111";
When "1000"=>seg<="1111111";
When "1001"=>seg<="1101111";
When Others=>NULL;
end case;
End Process;
End behav;
二选一选择器
Library IEEE;
Use IEEE.std_logic_1164.all;
Entity mux21 Is
Port(a,b:In std_logic;
s:In std_logic;
y:Out std_logic);
End Entity mux21;
Architecture one Of mux21 Is
Begin
y<=a when s='0' else
b when s='1';
End Architecture one;
Library IEEE;
Use IEEE.Std_Logic_1164.All;
Entity decoder Is
Port(
A: In Std_Logic_Vector(2 downto 0);
EN:In Std_Logic;
Y: Out Std_Logic_Vector(7 downto 0)
);
End Entity decoder;
Architecture a Of decoder Is
Signal Sel:Std_Logic_Vector(3 downto 0);
Begin
Sel(0)<=EN;
Sel(1)<=A(0);
Sel(2)<=A(1);
Sel(3)<=A(2);
With Sel select
Y<="00000001" WHEN "0001",
"00000010" WHEN "0011",
"00000100" WHEN "0101",
"00001000" WHEN "0111",
"00010000" WHEN "1001",
"00100000" WHEN "1011",
"01000000" WHEN "1101",
"10000000" WHEN "1111",
"00000000" WHEN Others;
End a;
七段数码显示管
Library IEEE;
Use IEEE.Std_Logic_1164.All;
Use IEEE.Std_Logic_Unsigned.All;
Entity decoder47 Is
Port(
D:In Std_Logic_Vector(3 downto 0);
SEG:Out Std_Logic_Vector(6 downto 0)
);
End Entity decoder47;
Architecture a Of decoder47 Is
Begin
SEG<="0111111" WHEN D="0" ELSE
"0000110" WHEN D="1" ELSE
"1011011" WHEN D="2" ELSE
"1001111" WHEN D="3" ELSE
"1100110" WHEN D="4" ELSE
"1101101" WHEN D="5" ELSE
"1111101" WHEN D="6" ELSE
"0000111" WHEN D="7" ELSE
"1111111" WHEN D="8" ELSE
"1101111" WHEN D="9" ELSE
"0000000";
End a;
四选一数据选择器
Library IEEE;
Use IEEE.Std_Logic_1164.All;
Use IEEE.Std_Logic_Arith.aLL;
Use IEEE.Std_Logic_Unsigned.All;
Entity mus44 Is
Port(
D3,D2,D1,D0:In Std_Logic_Vector(3 downto 0);
A:In Std_Logic_Vector(1 downto 0);
Y:Out Std_Logic_Vector(3 downto 0)
);
End Entity mus44;
Architecture a Of mus44 Is
Begin
Y<=D0 WHEN A="00" ELSE
D1 WHEN A="01" ELSE
D2 WHEN A="10" ELSE
D3 WHEN A="11" ELSE
"0000";
End a;
文章评论(0条评论)
登录后参与讨论