ALARM_SET.VHD
上传用户:dgjihui88
上传日期:2013-07-23
资源大小:43k
文件大小:2k
源码类别:

VHDL/FPGA/Verilog

开发平台:

MultiPlatform

  1. ----libray and package declaraction
  2. library IEEE;
  3. use IEEE.std_logic_1164.all;
  4. use IEEE.std_logic_arith.all;
  5. use IEEE.std_logic_unsigned.all;
  6. Entity alarm_set is
  7.   Port(rst,hz1: in std_logic;--system clock 1Hz
  8.        alarm,ok: in std_logic;--keep pushing to declare alarm set
  9.        sec_tune: in std_logic;-- keep pushing to declare second tuning
  10.        min_tune: in std_logic;-- keep pushing to declare minute tuning
  11.        hour_tune: in std_logic; --keep pushing to declare hour tuning
  12.        sec,min: out integer range 0 to 59;
  13.        hour: out integer range 0 to 23);
  14. End;
  15. ----define the signal_structure and _flow of the device 
  16. architecture arch of alarm_set is
  17.   signal sec_tmp,min_tmp:  integer range 0 to 59;
  18.   signal hour_tmp:  integer range 0 to 23;   
  19. begin
  20.   tuning:process(rst,hz1,alarm,ok)
  21.   begin
  22.   if rst='1' then sec_tmp<=0; min_tmp<=0; hour_tmp<=0;
  23.   elsif rising_edge(hz1) then
  24.       if alarm='1' and ok='0' then
  25.            if sec_tune='1' then 
  26.               if sec_tmp=59 then sec_tmp<=0;
  27.                           else sec_tmp<=sec_tmp + 1;
  28.               end if;
  29.            end if;
  30.            if min_tune='1' then 
  31.               if min_tmp=59 then min_tmp<=0;
  32.                           else min_tmp<=min_tmp + 1;
  33.               end if;
  34.            end if;
  35.            if hour_tune='1' then
  36.               if hour_tmp=23 then hour_tmp<=0;
  37.                            else hour_tmp<=hour_tmp + 1;
  38.               end if;
  39.            end if;
  40.       else
  41.           null;
  42.       end if;
  43.   end if;
  44.   end process tuning;
  45.     sec<=sec_tmp;
  46.     min<=min_tmp;
  47.     hour<=hour_tmp;
  48. end arch;