的个数与前相对应,不能少也不能多。在设计时还要考虑到设计引脚是否能够在试验箱上找到。最后在老师的指导下我们总算是顺利地完成了这次的课程设计。
六.参考文献
[1] 潘松,黄继业.EDA技术实用教程(第二版).科学出版社,1998。
[2] 宋万杰,罗丰,吴顺军.CPLD技术及其应用.西安:西安电子科技大学出版社,1999。 [3] 徐志军 王金明.EDA技术与PLD设计.人民邮电出版社。 [4] 康华光.电子技术基础(数字部分).高等教育出版社。 [5]百度文科4位十进制频率计设计。
七.附录
四位十进制频率计顶层文件源程序如下:
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity dc is
port(fin,clk_1hz:in std_logic;
ledout:out std_logic_vector(27 downto 0)); end dc;
architecture one of dc is
component Tct1 ---Tct1元件声明 port( clk: in std_logic;
en,rst,load :out std_logic); end component;
component x4cnt10 ----x4cnt10元件声明
port(clk,rst,en: in std_logic;
q0,q1,q2,q3 :out std_logic_vector(3 downto 0); cout:out std_logic); end component;
component reg16 ---reg16元件声明
port(load: in std_logic;
di : in std_logic_vector(15 downto 0);
dout : out std_logic_vector(15 downto 0) ); end component;
component scan_led ---scan_led元件声明 port(din: in std_logic_vector(15 downto 0); sg :out std_logic_vector(6 downto 0); bt: out std_logic_vector(1 downto 0)); end component;
signal x,z,f:std_logic;
signal h:std_logic_vector(3 downto 0);
signal g0,g1,g2,g3:std_logic_vector(3 downto 0); signal h0,h1,h2,h3:std_logic_vector(3 downto 0); signal leds:std_logic_vector(27 downto 0);
begin ---元件例化产生电路,完成设计 u1: Tct1 port map(clk=>clk_1hz, en=>x,rst=>z,load=>f);
u2: x4cnt10 port map(clk=>fin,rst=>z,en=>x,q0=>g0,q1=>g1,q2=>g2,q3=>g3); u3:reg16 port map(load=>f,di(3 downto 0)=>g0,di(7 downto 4)=>g1,di(11 downto 8)=>g2,di(15 downto 12)=>g3,dout(3 downto 0)=>h0,dout(7 downto 4)=>h1,dout(11 downto 8)=>h2,dout(15 downto 12)=>h3);
u4: scan_led port map(din(3 downto 0)=>h0(3 downto 0),sg(6 downto 0)=>leds(6 downto 0));
u5: scan_led port map(din(7 downto 4)=>h1(3 downto 0),sg(6 downto 0)=>leds(13 downto 7));
u6: scan_led port map(din(11 downto 8)=>h2(3 downto 0),sg(6 downto 0)=>leds(20 downto 14));
u7: scan_led port map(din(15 downto 12)=>h3(3 downto 0),sg(6 downto 0)=>leds(27 downto 21));
ledout<=leds; end; 计数模块x4cnt10的源代码程序:
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity x4cnt10 is
port(clk,rst,ena: in std_logic; --端口定义 q0,q1,q2,q3 : buffer std_logic_vector(3 downto 0); --分别定义四个计 cout:out std_logic); 数端口,用于4 end x4cnt10; 个cnt10的设计
architecture three of x4cnt10 is
signal en1,en2,en3 : std_logic; ---使能信号声明 begin
process(clk,rst,ena,q0) ---控制q0端的十进制计数 begin
if rst='1' then q0 <= \
elsif clk'event and clk='1' then if ena='1' then
if q0=\ end if; end if;
if q0=\ end process;
process(clk,rst,en1,q1) ---控制q1端的十进制计数 begin
if rst='1' then q1 <= \ elsif clk'event and clk='1' then if en1='1' then
if q1=\ end if; end if;
if q1=\ end process;
process(clk,rst,en2,q2) --控制q2端的十进制计数 begin
if rst='1' then q2 <= \ elsif clk'event and clk='1' then if en2='1' and en1='1'then
if q2=\ end if; end if;
if q2=\ end process;
process(clk,rst,en3,q3) ---控制q3端的十进制计数 begin
if rst='1' then q3 <= \ elsif clk'event and clk='1' then
if en3='1' and en2='1' and en1='1'then
if q3=\ end if;
end if;
if q3=\ end process; end three;
library ieee; ---将设计元x4cnt10的声明装入my_pkg程序包中 use ieee.std_logic_1164.all; package my_pkg1 is component x4cnt10
port(clk,rst,ena: in std_logic;
q0,q1,q2,q3 : buffer std_logic_vector(3 downto 0); cout:out std_logic); end component; end;
控制模块Tctl源代码程序;
Library ieee;
Use ieee.std_logic_1164.all; Use ieee.std_logic_unsigned.all; Entity Tct1 is
Port(clk:in std_logic; ---端口定义 ena,rst,load:out std_logic); End Tct1;
Architecture one of Tct1 is
Signal divclk :std_logic; ---divclk信号声明 Begin
Process(clk) Begin
if clk'event and clk='1' then divclk<=not divclk; ---clk上升沿时,divclk取反 end if ;
End process;
Process(clk,divclk) Begin
If clk='0' and divclk='0' then ---clk和divclk同时为0时,rst置1,否则rst清0 rst<='1'; Else rst<='0'; End if;
End process;
Load<=not divclk; ----将divclk取反赋值到load端,将divclk的值赋给ena ena<=divclk; end one;
Reg16锁存器源代码程序:
Library ieee;
Use ieee.std_logic_1164.all; Entity reg16 is
Port(load:in std_logic; ----端口定义
din:in std_logic_vector(15 downto 0); dout:out std_logic_vector(15 downto 0)); End reg16;
Architecture one of reg16 is Begin
Process(load,din) Begin
if(load'event and load='1') then ---load为上升沿时,把din值锁存到dout中
dout<=din; end if;
end process; End one;
led动态扫描输出scan_led源代码程序;
Library ieee;
Use ieee.std_logic_1164.all; Use ieee.std_logic_unsigned.all; Entity scan_led is
Port(clk:in std_logic; ---端口定义
din:in std_logic_vector(15 downto 0); --16位的输入端口
sg:out std_logic_vector(6 downto 0 ); --7位的输出端口(译码地址) bt:out std_logic_vector(1 downto 0)); -- 2位的输出端口(片选信号)
end;
Architecture one of scan_led is
Signal cnt8 :std_logic_vector(1 downto 0); ---信号声明 Signal q:std_logic_vector(3 downto 0); Begin
p1: Process(cnt8) ---多路选通模块 begin
case cnt8 is ---通过cnt8的值来选择片选信号bt when \ 决定某led在某时某刻的 when \ 显示数据