📄 sound.vhd
字号:
library ieee; --铃声管理
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity sound is
port(alarmtime: in std_logic_vector(23 downto 0); --闹钟预定时间
clk: in std_logic;
time:in std_logic_vector(23 downto 0); --当前时间
alarmon :in std_logic; --闹钟开关
houralarmon: in std_logic; --报时开关
sound_signal: out std_logic); --闹钟信号
end sound;
architecture s of sound is
signal alarm: std_logic;
signal houralarm: std_logic;
type state is(s0,s1,s2,s3,s4); --闹钟状态
signal pre_state:state:=s0;
signal next_state:state:=s0;
begin
process(clk) --更新
begin
if(alarmon='0')then
pre_state<=s0;
elsif rising_edge(clk)then
pre_state<=next_state;
end if;
end process;
process(pre_state,time,alarmtime)
begin
case pre_state is
when s0=>
if(alarmtime=time)then
next_state<=s1;
else
next_state<=pre_state;
end if;
when s1=>
if(time(6)='1')then
next_state<=s2;
else
next_state<=pre_state;
end if;
when s2=>
if(time(6)='0')then
next_state<=s3;
else
next_state<=pre_state;
end if;
when s3=>
if(time(6)='1')then
next_state<=s4;
else
next_state<=pre_state;
end if;
when s4=>
if(time(6)='0')then
next_state<=s0;
else
next_state<=pre_state;
end if;
when others=>
next_state<=s0;
end case;
end process;
process(pre_state) --状态译码
begin
if(pre_state=s3 or pre_state=s4)then
alarm<='1';
else
alarm<='0';
end if ;
end process;
process(houralarmon,time)
begin
if(houralarmon='1' and time(15 downto 0)="0000000000000000")then
houralarm<='1';
else
houralarm<='0';
end if;
end process;
sound_signal<=alarm or houralarm;
end s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -