STOP_WATCH.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. ----input and output pins declaraction
  7. Entity stop_watch is
  8.   Port(rst,hz1: in std_logic;--system clock 1Hz
  9.       stop: in std_logic;--keep pushing to declare stop setting
  10.       ok: in std_logic;--keep pushing to declare stop setting
  11.       sec_tune: in std_logic;--pushing button to tune seconds
  12.       min_tune: in std_logic;--pushing button to tune minutes
  13.       hour_tune: in std_logic;--pushing button to tune hours
  14.       stop_sec,stop_min: out integer range 0 to 59;
  15.       stop_hour: out integer range 0 to 23;      
  16.       index: out std_logic;      
  17.       disp: out std_logic);           
  18. End stop_watch;
  19. architecture arch of stop_watch is
  20.   signal a_sec,a_min: integer range 0 to 59;
  21.   signal a_hour: integer range 0 to 23; 
  22. begin
  23.   process(stop,ok,hz1)
  24.   begin
  25.     if rst='1' then index<='0'; disp<='0';
  26.     elsif rising_edge(hz1) then
  27.        if stop='1' and ok='0' then --setting
  28.           if sec_tune='1' then 
  29.              if a_sec=59 then a_sec<=0;
  30.                          else a_sec<=a_sec + 1;
  31.              end if;
  32.           end if;
  33.           if min_tune='1' then 
  34.              if a_min=59 then a_min<=0;
  35.                          else a_min<=a_min + 1;
  36.              end if;
  37.           end if;
  38.           if hour_tune='1' then
  39.              if a_hour=23 then a_hour<=0;
  40.                           else a_hour<=a_hour + 1;
  41.              end if;
  42.           end if;
  43.           disp<='1';
  44.        elsif stop='1' and ok='1'then --down counting
  45.              if a_sec=0 then 
  46.                 if a_min=0 then 
  47.                    if a_hour=0 then index<='1';
  48.                                     disp<='0';  
  49.                                else a_hour<=a_hour - 1;
  50.                                     a_min<=59;
  51.                                     a_sec<=59;
  52.                    end if;
  53.                            else a_min<=a_min - 1;
  54.                                 a_sec<=59;
  55.                 end if;
  56.                         else a_sec<=a_sec - 1;
  57.                              index<='0';
  58.                              disp<='1';      
  59.              end if;
  60.         else disp<='0';
  61.       end if;
  62.     end if;
  63.   end process;   
  64.   stop_sec<=a_sec;
  65.   stop_min<=a_min;
  66.   stop_hour<=a_hour;
  67. end arch;