📄 preset_cnt.vhd
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity preset_cnt is
Port ( clk : in std_logic; --系统时钟输入
reset : in std_logic;
preset : in std_logic; --复位预置数据的信号
hourh : in std_logic; --小时高位的数据输入
hourl : in std_logic; --小时低位的数据输入
minh : in std_logic; --分钟高位的数据输入
minl : in std_logic; --分钟低位的数据输入
secondh : in std_logic; --秒钟高位的数据输入
secondl : in std_logic; --秒钟低位的数据输入
houroh : out std_logic_vector(1 downto 0); --小时高位的数据输出
hourol : out std_logic_vector(3 downto 0); --小时低位的数据输出
minoh : out std_logic_vector(2 downto 0); --分钟高位的数据输出
minol : out std_logic_vector(3 downto 0); --分钟低位的数据输出
secondoh : out std_logic_vector(2 downto 0); --秒钟高位的数据输出
secondol : out std_logic_vector(3 downto 0)); --秒钟低位的数据输出
end preset_cnt;
architecture Behavioral of preset_cnt is
signal clkk:std_logic;
begin
process(clk,preset) --预分频,作用是延时;防止按键误触的情况发生
variable cnt:integer range 0 to 6000000; --分频系数是160000
begin
if reset='1'then
cnt:=0; clkk<='0';
elsif clk'event and clk='1' then
if cnt=5999999 then
clkk<=not clkk;
cnt:=0;
else
cnt:=cnt+1;
end if;
end if;
end process;
process(preset,clkk,hourh,hourl,minh,minl,secondh,secondl) --实现数据的预置
variable cnt1:std_logic_vector(3 downto 0):="0000";
variable cnt2,cnt3,cnt4,cnt5,cnt6:std_logic_vector(3 downto 0):="0000";
begin
if preset='1' then
if clkk'event and clkk='1'then --时钟为上升沿时,检测按键是否被按下
if cnt1="0011"then
cnt1:="0000";
elsif hourh='0' then
cnt1:=cnt1+1;
end if;
if cnt1<"0010" then
if cnt2="1010"then
cnt2:="0000";
elsif hourl='0' then
cnt2:=cnt2+1;
end if;
else
if cnt2="0100"then
cnt2:="0000";
elsif hourl='0' then
cnt2:=cnt2+1;
end if;
end if;
if cnt3="0110"then
cnt3:="0000";
elsif minh='0'then
cnt3:=cnt3+1;
end if;
if cnt4="1010"then
cnt4:="0000";
elsif minl='0'then
cnt4:=cnt4+1;
end if ;
if cnt5="0110"then
cnt5:="0000";
elsif secondh='0'then
cnt5:=cnt5+1;
end if;
if cnt6="1010"then
cnt6:="0000";
elsif secondl='0' then
cnt6:=cnt6+1;
end if;
end if;
end if;
hourol<=cnt2;
houroh<=cnt1(1 downto 0);
minol<=cnt4;
minoh<=cnt3(2 downto 0);
secondol<=cnt6;
secondoh<=cnt5(2 downto 0);
end process;
end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -