📄 clk_and_modify.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clk_and_modify is
port(
clk1Mh:in std_logic;
reset:in std_logic;
choose:in std_logic;
modify_min_hour,div_choose_state:in std_logic;
alarm:out std_logic;
sec_one:out integer range 0 to 9;
sec_ten:out integer range 0 to 5;
min_one:out integer range 0 to 9;
min_ten:out integer range 0 to 5;
hour_one:out integer range 0 to 9;
hour_ten:out integer range 0 to 2;
alarm_modify:in std_logic;
ch_state:out std_logic
);
end;
architecture arch of clk_and_modify is
signal sec_l,min_l,hour_l,min_l_alarm,hour_l_alarm:integer range 0 to 9;
signal sec_h,min_h,min_h_alarm: integer range 0 to 5;
signal hour_h,hour_h_alarm: integer range 0 to 2;
signal choose_state : std_logic;
begin
p1:process(clk1Mh,reset)
begin
if reset='1' then --有复位信号就全清0
sec_l<=0;sec_h<=0;
min_l<=0;min_h<=0;
hour_l<=0;hour_h<=0;
elsif rising_edge(clk1Mh)then
if(choose='0') then --choose键未拨上去则正常计时
if sec_l<9 then
sec_l<=sec_l+1;--alarm<='0';
elsif(sec_l=9 and sec_h<5 )then
sec_l<=0;sec_h<=sec_h+1;--alarm<='0';
elsif(sec_l=9 and sec_h=5) then --秒加到60则变为0,分加1
sec_l<=0;sec_h<=0;
if min_l<9 then
min_l<=min_l+1;--alarm<='0';
elsif(min_l=9 and min_h<5 )then
min_l<=0;min_h<=min_h+1;--alarm<='0';
elsif(min_l=9 and min_h=5) then
min_l<=0;min_h<=0;--alarm<='1'; --分加到60则变为0,时加1,报时信号为1
if(hour_l=3 and hour_h=2 )then
hour_l<=0;hour_h<=0;
elsif(hour_l<3 and hour_h=2)then
hour_l<=hour_l+1;
elsif(hour_l=9 and hour_h<2) then
hour_l<=0;hour_h<=hour_h+1;
elsif(hour_l<9 and hour_h<2) then
hour_l<=hour_l+1;
else null;
end if;
else null;
end if;
else null;
end if;
elsif(modify_min_hour='1')then--choose拨上时若modify_min_hour也按下,则通过choose_state来判断时和分哪个量增加
case choose_state is
when '1' => if min_l<9 then --分钟调整
min_l<=min_l+1;
elsif(min_l=9 and min_h<5) then
min_l<=0; min_h<=min_h+1;
elsif(min_l=9 and min_h=5 )then
min_l<=0;min_h<=0;
else null;
end if;
when '0' => if(hour_l=3 and hour_h=2 )then --小时调整
hour_l<=0; hour_h<=0;
elsif(hour_l<3 and hour_h=2)then
hour_l<=hour_l+1;
elsif(hour_l=9 and hour_h<2) then
hour_l<=0;hour_h<=hour_h+1;
elsif(hour_l<9 and hour_h<2) then
hour_l<=hour_l+1;
else null;
end if;
when others=> null;
end case;
else null;
end if;
if alarm_modify='0' then --设定闹钟,选择该被输出的信号
sec_one<=sec_l;
sec_ten<=sec_h; --时钟输出
min_one<=min_l;
min_ten<=min_h;
hour_one<=hour_l;
hour_ten<=hour_h;
else
if modify_min_hour='1' then
--choose_state<='1';
case choose_state is
when '1' =>if min_l_alarm<9 then
min_l_alarm<=min_l_alarm+1;
elsif(min_l_alarm=9 and min_h_alarm<5) then
min_l_alarm<=0; min_h_alarm<=min_h_alarm+1;
elsif(min_l_alarm=9 and min_h_alarm=5 )then
min_l_alarm<=0;min_h_alarm<=0;
else null;
end if;
when '0' =>if(hour_l_alarm=3 and hour_h_alarm=2 )then
hour_l_alarm<=0; hour_h_alarm<=0;
elsif(hour_l_alarm<3 and hour_h_alarm=2)then
hour_l_alarm<=hour_l_alarm+1;
elsif(hour_l_alarm=9 and hour_h_alarm<2) then
hour_l_alarm<=0;hour_h_alarm<=hour_h_alarm+1;
elsif(hour_l_alarm<9 and hour_h_alarm<2) then
hour_l_alarm<=hour_l_alarm+1;
else null;
end if;
when others=> null;
end case;
else null;
end if;
min_one<=min_l_alarm; --闹钟输出
min_ten<=min_h_alarm;
hour_one<=hour_l_alarm;
hour_ten<=hour_h_alarm;
end if;
else null;
end if;
if( sec_l=1 and sec_h=0 and min_l=0 and min_h=0 and choose='0')
or(sec_l=2 and sec_h=0 and min_l=0 and min_h=0 and choose='0')
or(sec_l=1 and sec_h=0 and min_l=min_l_alarm and min_h=min_h_alarm and hour_l=hour_l_alarm and hour_h=hour_h_alarm)
or(sec_l=2 and sec_h=0 and min_l=min_l_alarm and min_h=min_h_alarm and hour_l=hour_l_alarm and hour_h=hour_h_alarm)
or(sec_l=3 and sec_h=0 and min_l=min_l_alarm and min_h=min_h_alarm and hour_l=hour_l_alarm and hour_h=hour_h_alarm)
or(sec_l=4 and sec_h=0 and min_l=min_l_alarm and min_h=min_h_alarm and hour_l=hour_l_alarm and hour_h=hour_h_alarm)
or(sec_l=5 and sec_h=0 and min_l=min_l_alarm and min_h=min_h_alarm and hour_l=hour_l_alarm and hour_h=hour_h_alarm) then
alarm<='1'; --整点,定点报时
else alarm<='0';
end if;
ch_state<=choose_state;
end process;
p2: process(div_choose_state) --选择时、分
begin
if(div_choose_state'event and div_choose_state='1') then
choose_state<=not choose_state;
end if;
end process;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -