【正文】
rm_signal:out std_logic )。 end ponent。 signal buffertime,time,alarmtime:std_logic_vector(23 downto 0)。 signal iscount,alarmload,timeload:std_logic。 begin sm1:statemachine port map(clk,keypressed,functionkey,keyvalue, iscount,alarmload,timeload,buffertime)。 sm2:statemachine2 port map(clk,keypressed,keyvalue,alarmon,houralarmon)。 t:counter port map(clk,timeload,buffertime,time)。 reg:alarmreg port map(clk,alarmload,buffertime,alarmtime)。 bl:bell port map(clk,houralarmon,alarmon,alarmtime,time,alarm_signal)。 process(iscount,time,buffertime) begin if(iscount=39。139。) then displaytime=time。 else displaytime=buffertime。 end if。 end process。 end rt。 計(jì)數(shù)器程序( 1) library ieee。 use 。 use 。 use 。 entity counter is port( clk,load:in std_logic。 buffertime:in std_logic_vector(23 downto 0)。 time:out std_logic_vector(23 downto 0) )。 end counter。 architecture rt of counter is ponent divider_1m port( clk:in std_logic。 clk1s:out std_logic )。 end ponent。 signal clk1s:std_logic。 signal time_sig:std_logic_vector(23 downto 0)。 begin u1:divider_1m port map(clk,clk1s)。 process(clk1s,clk) begin if(clk39。event and clk=39。139。)then if(load=39。139。)then time_sig=buffertime。 else if(clk1s=39。139。)then if(time_sig(3 downto 0)=1001)then time_sig(3 downto 0)=0000。 if(time_sig(7 downto 4)=0101)then time_sig(7 downto 4)=0000。 if(time_sig(11 downto 8)=1001)then time_sig(11 downto 8)=0000。 if(time_sig(15 downto 12)=0101)then time_sig(15 downto 12)=0000。 if(time_sig(23 downto 16)=00001001)then time_sig(23 downto 16)=00010000。 elsif(time_sig(23 downto 16)=00011001)then time_sig(23 downto 16)=00100000。 else time_sig(23 downto 16)=time_sig(23 downto 16)+1。 end if。 else time_sig(15 downto 12)=time_sig(15 downto 12)+1。 end if。 else time_sig(11 downto 8)=time_sig(11 downto 8)+1。 end if。 else time_sig(7 downto 4)=time_sig(7 downto 4)+1。 end if。 else time_sig(3 downto 0)=time_sig(3 downto 0)+1。 end if。 end if。 end if。 end if。 end process。 time=time_sig。 end rt。 library ieee。 use 。 use 。 entity divider_1m is port( clk:in std_logic。 clk1s:out std_logic )。 end divider_1m。 architecture rt1 of divider_1m is signal t:integer range 0 to 999999。 begin process(clk) begin if(clk39。event and clk=39。139。)then if(t=t39。high)then t=0。 clk1s=39。139。 else t=t+1。 clk1s=39。039。 end if。 end if。 end process。 end rt1。 計(jì)數(shù)器程序( 2) 鬧鐘和整點(diǎn)報(bào)時(shí) library ieee。 use 。 use 。 use 。 entity statemachine2 is port( clk,keypressed:in std_logic。 keyvalue:in std_logic_vector(3 downto 0)。 alarmon,houralarmon:out std_logic )。 end statemachine2。 architecture rt of statemachine2 is type state is(s_off,s_on)。 signal ps_alarmon,ns_alarmon,ps_houralarmon,ns_houralarmon:state:=s_off。 begin process(clk) begin if(clk39。event and clk=39。139。)then