-- Program for Digital Clock with Alarm library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_UNSIGNED.all; use IEEE.NUMERIC_STD.all; entity digital_clock is port ( clk_1sec: in STD_LOGIC; reset: in STD_LOGIC; load_time: in STD_LOGIC; set_hours: in integer range 0 to 11; set_min: in integer range 0 to 59; set_sec: in integer range 0 to 59; set_am_pm: in STD_LOGIC; load_alarm: in STD_LOGIC; a_hrs_in: in integer range 0 to 11; a_min_in: in integer range 0 to 59; a_am_pm: in STD_LOGIC; alarm_en: in STD_LOGIC; hours: out integer range 0 to 11; min: out integer range 0 to 59; sec: out integer range 0 to 59; am_pm: out STD_LOGIC; flashing: out STD_LOGIC; alarm: out STD_LOGIC ); end digital_clock; architecture digital_clock_arch of digital_clock is signal hours_s: integer range 0 to 11; signal min_s,sec_s:integer range 0 to 59; signal am_pm_s:STD_LOGIC; signal flashing_s:STD_LOGIC; signal al_hrs : integer range 0 to 11; signal al_min : integer range 0 to 59; signal al_am_pm : std_logic; begin -- <> process(clk_1sec) begin if clk_1sec='1' and clk_1sec'event then if reset='1'then hours_s<=(0); min_s<=(0); sec_s<=(0); am_pm_s<='0'; flashing_s<='1'; elsif load_time='1' then hours_s<=set_hours; min_s<=set_min; sec_s<=set_sec; am_pm_s<=set_am_pm; flashing_s<='0'; else flashing_s<= not flashing_s; if sec_s = 59 then sec_s<=(0); if min_s = 59 then min_s<=(0); if hours_s = 11 then hours_s<=(0); am_pm_s<=not am_pm_s; else hours_s<=hours_s + 1; am_pm_s<= am_pm_s; end if; else min_s<=min_s+ 1 ; hours_s<=hours_s; am_pm_s<= am_pm_s; end if; else sec_s<=sec_s + 1; min_s<=min_s; hours_s<=hours_s; am_pm_s<= am_pm_s; end if; end if; end if; end process; hours<=hours_s; min<=min_s; sec<=sec_s; am_pm<=am_pm_s; flashing <= flashing_s; -- process(clk_1sec) begin if clk_1sec='1' and clk_1sec'event then if reset='1' then al_hrs <= 0; al_min <= 0; al_am_pm <= '0'; elsif load_alarm='1' then al_hrs <= a_hrs_in; al_min <= a_min_in; al_am_pm <= a_am_pm; else al_hrs <= al_hrs; al_min <= al_min; al_am_pm <= al_am_pm; end if; end if; if (min_s = al_min and hours_s=al_hrs) and (am_pm_s=al_am_pm and alarm_en='1') then alarm <= '1'; else alarm <= '0'; end if; end process; end digital_clock_arch;