📄 leap_judge.vhd
字号:
--闰年判断模块
--这是靠计数器实现闰年的判断
library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_arith.all;
Use ieee.std_logic_unsigned.all;
entity Leap_judge is
port(clk : in std_logic; --计数时钟,为2M
year : in std_logic_vector(7 downto 0); --输入的待判断的年份
en : in std_logic; --开始判断信号,其实就是复位信号
isLeap : out std_logic); --输出判断结果
end Leap_judge;
architecture a of Leap_judge is
signal tmp4 : std_logic_vector(7 downto 0);
begin
process(clk,en)
begin
if(en='0') then --复位
tmp4 <= "00000000";
elsif(clk'event and clk='1') then --计数,从0开始,每次加4
if(tmp4<year) then --在不小于待测年份时停止计数
if(tmp4(3 downto 0)<"0110") then
tmp4(3 downto 0) <= tmp4(3 downto 0)+4;
else
tmp4(3 downto 0) <= tmp4(3 downto 0)-"0110";
if(tmp4(7 downto 4)<"1001") then
tmp4(7 downto 4) <= tmp4(7 downto 4)+1;
else
isLeap <= '0'; --这表明不在预订范围(00-99)内
end if;
end if;
else --判断
if(tmp4=year) then --若是相等,则为闰年
isLeap <= '1';
else
isLeap <= '0'; --否则,为平年
end if;
end if;
end if;
end process;
end a;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -