Professional Documents
Culture Documents
图 3.4.1
99
太原理工大学 夏路易
图 3.4.2
图 3.4.3
100
太原理工大学 夏路易
图 3.4.4
十进制加法计数器的源程序:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity count10 is
port(clk,reset,en: in std_logic;
qa,qb,qc,qd: out std_logic);
end count10;
architecture behave of count10 is
signal count_4: std_logic_vector(3 downto 0);
begin
qa<=count_4(0);
qb<=count_4(1);
qc<=count_4(2);
qd<=count_4(3);
101
太原理工大学 夏路易
process(clk,reset)
begin
if (reset='0') then
count_4<="0000";
elsif(clk'event and clk='1') then
if(en='1') then
if(count_4="1001") then
count_4<="0000";
else
count_4<=count_4+'1';
end if;
end if;
end if;
end process;
end behave;
第五步:选择 Assign/Device 菜单,选定器件。
第六步:选 File/Project/Save & Comlile 菜单,编译该 VHDL 源文件
若有错误则改错,然后再编译,直至无错编译成功
第七步:选 Max+plus2\Waveform Editor 菜单,进入波形编辑窗口,编辑输入波形如图 3.4.5
所示。
102
太原理工大学 夏路易
图 3.4.5
图 3.4.6
例 3:
如下是一个六十进制计数器和一个十二进制计数器异步连接的例子,六十进制计数器的
进位输出是十二进制计数器的时钟脉冲。例中调用了六十进制计数器设计文件 cou60.vhd 和
十二进制计数器设计文件 cou12.vhd。从仿真中发现,若选用 FLEX10k 系列器件,由于设计
不尽合理会出现不该有的毛刺,致使不该输出进位时输出了进位,导致十二进制计数器误
动作,然而选用 MAX7000 系列器件就不会出现毛刺和误动现象。
六十进制计数器设计文件和十二进制计数器设计文件基本相同,只是十位数的归零条件不
同。
设计文件:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cou12 is
103
太原理工大学 夏路易
port(clk,reset,cin : in std_logic;
co : out std_logic;
bcd1p : out std_logic_vector(3 downto 0);
bcd10p : out std_logic_vector(2 downto 0));
end cou12;
kk2: process(clk)
begin
if(clk'event and clk='1') then
if (reset='0') then
bcd10n<="000";
elsif(cin='1') and (bcd1n="1001") then
if(bcd10n="001") then --归零条件
bcd10n<="000";
104
太原理工大学 夏路易
else
bcd10n<=bcd10n+'1';
end if;
end if;
end if;
end process kk2;
kk3: process(bcd10n,bcd1n,cin)
begin
if(cin='1' and bcd1n="1001" and bcd10n="001") then
co<='1';
else
co<='0';
end if;
end process kk3;
end behave;
六十进制计数器和十二进制计数器互连设计文件:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY x6012 IS
PORT (clk, reset,ena : IN std_LOGIC;
cpp : out std_logic;
a12g : out std_logic_vector(3 downto 0);
a12s : out std_logic_vector(2 downto 0);
b60g : out std_logic_vector(3 downto 0);
b60s : out std_logic_vector(2 downto 0));
END x6012;
end component;
component cou60
port(clk,reset,cin : in std_logic;
co : out std_logic;
bcd1p : out std_logic_vector(3 downto 0);
bcd10p : out std_logic_vector(2 downto 0));
end component;
begin
u1:cou60 port map(clk,reset,ena,c601,b60gp,b60sp);
u0:cou12 port map(c601,reset,ena,c12,a12g,a12s);
b60s<=b60sp;
b60g<=b60gp;
cpp<=c601;
end x12;
指定 MAX7000 系列器件的仿真结果见图 3.4.7:
106
太原理工大学 夏路易
图 3.4.7
指定 FLEX10K 系列的仿真结果见图 3.4.8。
图 3.4.8
例 4:四位十进制计数器
设计文件:
107
太原理工大学 夏路易
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cou4 is
port(
clk,reset,cin : in std_logic;
-- co : out std_logic;
bcdap : out std_logic_vector(3 downto 0);
bcdbp : out std_logic_vector(3 downto 0);
bcdcp : out std_logic_vector(3 downto 0);
bcddp : out std_logic_vector(3 downto 0)
);
end cou4;
begin
bcdap<=bcdan;
bcdbp<=bcdbn;
bcdcp<=bcdcn;
bcddp<=bcddn;
kk1: process(clk)
begin
if(clk'event and clk='1') then
if (reset='0') then
bcdan<="0000";
elsif (cin='1') then
if(bcdan="1001" ) then
108
太原理工大学 夏路易
bcdan<="0000";
else
bcdan<=bcdan+'1';
end if;
end if;
end if;
end process kk1;
kk2: process(clk)
begin
if(clk'event and clk='1') then
if (reset='0') then
bcdbn<="0000";
elsif(cin='1') and (bcdan="1001") then
if(bcdbn="1001") then
bcdbn<="0000";
else
bcdbn<=bcdbn+'1';
end if;
end if;
end if;
end process kk2;
kk3: process(clk)
begin
if(clk'event and clk='1') then
if (reset='0') then
bcdcn<="0000";
elsif(cin='1') and (bcdbn="1001") and (bcdan="1001") then
if(bcdcn="1001") then
bcdcn<="0000";
else
bcdcn<=bcdcn+'1';
end if;
end if;
109
太原理工大学 夏路易
end if;
end process kk3;
kk4: process(clk)
begin
if(clk'event and clk='1') then
if (reset='0') then
bcddn<="0000";
elsif(cin='1') and (bcdcn="1001") and (bcdbn="1001") and (bcdan="1001") then
if(bcddn="1001") then
bcddn<="0000";
else
bcddn<=bcddn+'1';
end if;
end if;
end if;
end process kk4;
end behave;
110
太原理工大学 夏路易
图 3.4.9
7 段译码的 VHDL 设计文件:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity seg7 is
port(ii :in std_logic_vector(3 downto 0);
y :out std_logic_vector(6 downto 0));
end seg7;
case indata is
when "0000"=>y<="1111110";
when "0001"=>y<="0110000";
when "0010"=>y<="1101101";
when "0011"=>y<="1111001";
when "0100"=>y<="0110011";
when "0101"=>y<="1011011";
when "0110"=>y<="1011111";
when "0111"=>y<="1110000";
when "1000"=>y<="1111111";
when "1001"=>y<="1111011";
when "1010"=>y<="1110111";
when "1011"=>y<="0011111";
when "1100"=>y<="1001110";
when "1101"=>y<="0111101";
when "1110"=>y<="1001111";
when "1111"=>y<="1000111";
when others=>y<="XXXXXXX";
end case;
111
太原理工大学 夏路易
end process;
end behave;
该 7 段译码器的仿真结果见图 3.4.10。图中数字 126,48 等是 7 段笔划的编码。
图 3.4.10
四位十进制计数七段译码电路
设计文件:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY cou47seg IS
PORT (clk, reset,ena : IN std_LOGIC;
seg1 : out std_logic_vector(6 downto 0);
seg2 : out std_logic_vector(6 downto 0);
seg3 : out std_logic_vector(6 downto 0);
seg4 : out std_logic_vector(6 downto 0));
END cou47seg;
component cou4
port(
112
太原理工大学 夏路易
clk,reset,cin : in std_logic;
bcdap : out std_logic_vector(3 downto 0);
bcdbp : out std_logic_vector(3 downto 0);
bcdcp : out std_logic_vector(3 downto 0);
bcddp : out std_logic_vector(3 downto 0)
);
end component;
signal a,b,c,d : std_logic_vector(3 downto 0);
begin
u0:cou4 port map(clk,reset,ena,a,b,c,d);
u1:seg7 port map(a,seg1);
u2:seg7 port map(b,seg2);
u3:seg7 port map(c,seg3);
u4:seg7 port map(d,seg4);
end x47;
计数译码电路的仿真结果见图 3.4.11。
113
太原理工大学 夏路易
图 3.4.11
114