1、 一:设计任务与要求 秒表的逻辑结构比较简单,它主要由、显示译码器、分频 器、十进制计数器、报警器和六进制计数器组成。在整个秒表中最关 键是如何获得一个精确的 100Hz 计时脉冲, 除此之外,整个秒表还需 要一个启动信号和一个归零信号,以便能够随时启动及停止。 秒表有六个输出显示,分别为百分之一秒,十分之一秒、秒、十秒、 分、十分,所以共有 6 个计数器与之对应,6 个个计数器全为 BCD 码 输出,这样便于同时显示译码器的连接。当计时达 60 分钟后,蜂鸣 器鸣响 10 声。 二:设计原理 本系统采用自上向下的设计方案, 系统的整体设计组装原理图如 图 2-1 所示,它主要由控制模块,时基
2、分屏模块,计时模块和显示模 块四部分组成。各模块分别完成控制,分屏,计时和显示的功能 数字秒表 计时控制电路 计时电路 显示电路 分频电路 计数器 扫描电路 六进制计数器 十进制计数器 图 2-1 设计原理图 程序模块:程序模块: 1.分频器代码: 将 5MHZ 分为 100HZ library ieee; use ieee.std_logic_1164.all; entity div is port(clr,clk: in std_logic;q: buffer std_logic); end div; architecture a of div is signal counter:inte
3、ger range 0 to 49999; begin process(clr,clk) begin if (clk=1 and clkevent) then if clr=1 then counter=0; elsif counter=49999 then counter=0; q= not q; else counter=counter+1; end if; end if; end process; end a; 2.十进制计数器代码: 原理为加法计数器,计数十时由 cout 进位 library ieee; use ieee.std_logic_1164.all; use ieee.st
4、d_logic_unsigned.all; entity count10 is port(clr,start,clk: in std_logic; cout: out std_logic; daout: out std_logic_vector(3 downto 0); end count10; architecture a of count10 is signal temp:std_logic_vector(3 downto 0); begin process(clk,clr) begin if clr=1 then temp=“0000“; cout=“1001“ then temp=“0
5、000“; cout=1; else temp=temp+1; cout=0; end if; end if; end if; daout=temp; end process; end a; 3.六进制计数器代码: 原理为加法计数器,计数六时由 cout 进位。 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity c6 is port(clr,start,clk: in std_logic; daout: out std_logic_vector(3 downto 0); cout
6、: out std_logic); end c6; architecture a of c6 is signal temp:std_logic_vector(3 downto 0); begin process(clk,clr) begin if clr=1 then temp=“0000“; cout=0; elsif (clkevent and clk=1) then if start=1 then if temp=“0110“ then temp=“0000“; cout=1; else temp=temp+1; cout=0; end if; end if; end if; end process; daout=temp; end a; 4.数据选择和数码管选择模块代码: 其功能是选择个计数端口来的数据, 当相应的数据到来时数据选择器选择器数据 后输出给数码管,并由数码管显示。 library ieee; use ieee.std_logic_1164.all; USE ie