⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.vhd

📁 maxplus2变得电子钟程序/// /// /////
💻 VHD
字号:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY control IS
  port(reset: IN STD_LOGIC;     
         --system reset signal,this button will make the time at 00:00:00
       begand: IN STD_LOGIC;     --key of begin and end the adjust function
       keyup: IN STD_LOGIC;     --key for adjust time and set time value
       enter: IN STD_LOGIC;     --change the adjust function between the time units
       settime: OUT STD_LOGIC;  
       --output to inform module "clock"to adjust time according to the newly-settime
       hourhset:  out INTEGER RANGE 0 to 2;
                            --hour high set by control part 
       hourlset:  out INTEGER RANGE 0 to 9;
                            --hour low set by control part 
       minhset:  out INTEGER RANGE 0 to 5;
                            --minute high set by control part 
       minlset:  out INTEGER RANGE 0 to 9;
                            --minute low set by control part 
       sechset:  out INTEGER RANGE 0 to 5;
                            --second high set by control part 
       seclset:  out INTEGER RANGE 0 to 9);
                            --second low set by control part 
END control;
ARCHITECTURE control_archi OF control IS
    TYPE STATE IS (sethh,sethl,setmh,setml,setsh,setsl,ini);
            --define a new variable which include seven operation states in the control part
    SIGNAL adjust: STATE;    --define a new variable of STATE
    SIGNAL setmark: STD_LOGIC; --this singal show if the clock is at the state for setting time
    SIGNAL seclow,minlow,hourlow: INTEGER RANGE 0 to 9;
    SIGNAL sechigh,minhigh: INTEGER RANGE 0 to 5;
    SIGNAL hourhigh: INTEGER RANGE 0 to 2;
            --this three singal show the six time unit
BEGIN
           seclset<=seclow;
           sechset<=sechigh;
           minlset<=minlow;
           minhset<=minhigh;
           hourlset<=hourlow;
           hourhset<=hourhigh;
           settime<=setmark;

mark:
        --this process will decide the output control singal"settime" for "clock" module
    PROCESS(begand)
   begin
      if reset='1'  then 
         setmark<='0';
       elsif begand'event and begand='1'  then
          if setmark='1'  then
             setmark <='0';
          else 
             setmark <='1';
          end if;
       end if;
   END PROCESS;

normal_run :
         --this process acts as core state machine which decides
         -- which time uint is actived and can be adjusted.
PROCESS(enter)
  begin 
      if  reset='1'  then 
          adjust<=ini;
      elsif enter='1' and enter'event then
             case  adjust  is
                WHEN  ini=>adjust<=sethh;   
                WHEN  sethh=>adjust<=sethl; 
                WHEN  sethl=>adjust<=setmh; 
                WHEN  setmh=>adjust<=setml; 
                WHEN  setml=>adjust<=setsh; 
                WHEN  setsh=>adjust<=setsl; 
                WHEN  setsl=>adjust<=sethh; 
             end case;         --it's to choose which unit will be changed when enter input
       end if;
END PROCESS;
         
time_adjust:
           --the set value increase as the keyup is pushed down
 PROCESS(keyup)
    begin
         if reset='1'  then
          hourhigh<=0;
          hourlow<=0;
          minhigh<=0;
          minlow<=0;
          sechigh<=0;
          seclow<=0;

         elsif keyup='1' and keyup'event then
              case adjust is  
                   WHEN  sethh=>
                         if hourhigh<2 THEN
                           hourhigh<=hourhigh+1;
                         elsif hourhigh=2 then
                            hourhigh<=0;
                          end if;
                   WHEN  sethl=>
                         if hourhigh<2 then
                            if hourlow<9 then
                               hourlow<=hourlow+1;
                             elsif hourlow=9 then
                                hourlow<=0;
                              end if;
                          elsif hourhigh=2 then
                             if hourlow<4 then
                                hourlow<=hourlow+1;
                              elsif hourlow=4 then
                                hourlow<=0;
                              end if;
                          end if;
                   WHEN  setmh=>
                         if minhigh<5 THEN
                           minhigh<=minhigh+1;
                         elsif minhigh=5 then
                            minhigh<=0;
                          end if;
                   WHEN  setml=>
                            if minlow<9 then
                               minlow<=minlow+1;
                             elsif minlow=9 then
                                minlow<=0;
                             end if;
                   WHEN  setsh=>
                         if sechigh<5 THEN
                           sechigh<=sechigh+1;
                         elsif sechigh=5 then
                            sechigh<=0;
                          end if;
                   WHEN  setsl=>
                         if seclow<9 then
                               seclow<=seclow+1;
                             elsif seclow=9 then
                                seclow<=0;
                             end if;
                   WHEN  ini=>NULL;
               end case;
          end if;
     END PROCESS;
END control_archi;      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -