电子设计自动化 EDA 课程设计——电子钟源程序
else mod1<="0000";
end if;
end if;
end if;
end process;
end one;
(3)hour 模块:采用 24 进制计数器用来对小时进行计时,以分模块产生的进位信号作为触发计时脉冲。
Hour 模块源程序如下:
library ieee; --24 进制计数器
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt24 is
port( clk,add,en : in std_logic; --en 接键 8
choice : in std_logic; --选择按键 接按键 7
q : out std_logic_vector(7 downto 0); --3-0 个位 7-4 十位
cout : out std_logic;
mod_out : out std_logic_vector(3 downto 0));
end entity cnt24;
architecture one of cnt24 is
signal q1,q2 : std_logic_vector (7 downto 0);
signal mod1 : std_logic_vector(3 downto 0);
begin
p1: process (clk,add,en)
begin
case en is
when '0'=> q2<=q1; --检测是否允许计数
if clk'event and clk= '1' then --检测时钟上升沿
if q1(7 downto 4)<2 then
if q1(3 downto 0)<9 then q1(3 downto 0)<=q1(3 downto 0)+1;
--小于九则加一
else
q1(3 downto 0)<=(others=>'0');
q1(7 downto 4)<=q1(7 downto 4)+1;
end if;
else
if q1(3 downto 0)<3 then
q1(3 downto 0)<=q1(3 downto 0)+1; --小于四则加一
else
q1(7 downto 0)<=(others=>'0');
end if;
end if;
end if;
if q1=0 then cout<='1'; --q1=0, 产生进位
else cout<='0';
end if;
q<=q1;