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

📄 cnt_main_part.vhd.bak

📁 自己编写的8254计数器/计时器
💻 BAK
字号:


  LIBRARY IEEE;
 LIBRARY  my_lib;
USE IEEE.std_logic_1164.ALL;
USE my_lib.mode_set.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY  cnt_main_part IS
    PORT (  gate       :   in  std_logic_vector(2 downto 0);
            clk        :   in   std_logic;
            adrs   : in std_logic_vector( 1 downto 0);
            nCS    : in std_logic;
            nWR    : IN  std_logic;
            data   : IN  std_logic_vector(7 DOWNTO 0);
        
           rwmode  : IN  std_logic_vector(1 DOWNTO 0);
         mode_choice : IN  std_logic_vector(2 DOWNTO 0);
          cnt_choice : IN  std_logic_vector(1 DOWNTO 0);
          binnbcd    : IN  std_logic;
          wr_finish  : in std_logic;
          
        
           out_sgnl   : OUT std_logic_vector(2 DOWNTO 0)

  
     
    );
END;



ARCHITECTURE main OF cnt_main_part IS

-----------------------------------------------------------------
-- Internal Architecture Signal declarations
-----------------------------------------------------------------

  signal    cee: integer:=0;
  signal    CE_0     :  std_logic_vector(15  downto 0);
  signal    CE_1     :  std_logic_vector(15 downto 0);
  signal    CE_2     :  std_logic_vector(15 downto 0);
 signal     ce0      :  integer;
 signal     ce1      :  integer;
 signal     ce2      :  integer;
signal      bcd0     :  integer;
signal      bcd1       :  integer;
signal      bcd2     :  integer;
signal      bcd3     :  integer;
signal      bcd_0    :  std_logic_vector(3 downto 0);
signal      bcd_1    :  std_logic_vector(3 downto 0);
signal      bcd_2    :  std_logic_vector(3 downto 0);
signal      bcd_3    :  std_logic_vector(3 downto 0);
 signal    countmsb0  :  std_logic_vector(7 downto 0);
 signal   countlsb0  :  std_logic_vector(7 DOWNTO 0);
 signal    countmsb1 :  std_logic_vector(7 downto 0);
  signal   countlsb1  : std_logic_vector(7 DOWNTO 0);
  signal   countmsb2  : std_logic_vector(7 downto 0);
 signal     countlsb2  :  std_logic_vector(7 DOWNTO 0);

-----------------------------------------------------------------
-- Architecture body
-----------------------------------------------------------------
BEGIN   
cnt_prc: process(clk)
begin
  if(clk'event and  clk='1')  then 
 
    if ( nCS='0' and adrs="00" and nWR='0') then
       if(rwmode="01") then 
              countlsb0<=data;
              countmsb0<="00000000";
       elsif(rwmode="10") then 
              countmsb0<=data;
              countmsb0<="00000000";
       elsif(rwmode="11" )then
             countlsb0<=data; 
             countmsb0<=data;
       --   if( nWR'event and nWR='1') then  countlsb0<=data;
         -- elsif(nWR,event and nWR='1' )then countmsb0<=data;
        
      --  else 
        -- countlsb0<=countlsb0;
        -- countmsb0<=countmsb0;
         end if;
     elsif ( nCS='0' and adrs="01" and nWR='0') then
         if(rwmode="01") then 
              countlsb1<=data;
              countmsb1<="00000000";
          elsif(rwmode="10") then 
              countmsb1<=data;
              countlsb1<="00000000";
          elsif(rwmode="11" )then
              countlsb1<=data; 
             countmsb1<=data; 
           end if;
      elsif ( nCS='0' and adrs="10" and nWR='0') then
       if(rwmode="01") then 
              countlsb2<=data;
               countmsb2<="00000000";
       elsif(rwmode="10" and nWR='1') then 
              countmsb2<=data;
              countlsb2<="00000000";
      elsif(rwmode="11" )then
              countlsb2<=data; 
              countmsb2<=data;      
            end if;
  end if;


 case   cnt_choice  is 
  when "00"  =>
    case mode_choice is 
        when "000" => 
     
      if (  adrs="00"  )    
         then  CE_0(7 downto 0)<= countlsb0(7 downto 0);
            CE_0(15 downto 8) <= countmsb0(7 downto 0);
         else  CE_0<=CE_0;
        end if ;
    
  if(binnbcd='0') then 
          ce0<= conv_integer(ce_0); 
       else 
      bcd_0(3 downto 0)<=ce_0(3 downto 0);
      bcd_1(3 downto 0)<=ce_0(7 downto 4);
      bcd_2(3 downto 0)<=ce_0(11 downto 8);
      bcd_3(3 downto 0)<=ce_0(15 downto 12);
     bcd0<=conv_integer(bcd_0);
     bcd1<=conv_integer(bcd_1);
     bcd2<=conv_integer(bcd_2);
     bcd3<=conv_integer(bcd_3);
     ce0<=1000*bcd3+100*bcd2+10*bcd1+bcd0;
     end if;

        out_sgnl(1)<=wr_finish;
       if( ce0>0 )  then 
          out_sgnl(2)<='1'; -- to show the beginning of count.
         end if;
       if (cee<ce0 and gate(0)='1')  then
                   cee<=cee+1;
                   out_sgnl(0)<='0';
          elsif(cee=ce0 and gate(0)='1') then 
              cee<=ce0;
              out_sgnl(0)<='1';
          else  
                 cee<=cee;
                 out_sgnl(0)<='0';
           end if;
       
     
     
        when "001" =>  --mode1
          -- out_sgnl(0)<=mode1(clk,gate(0),mode1_start,ce0);
      null;
    when "X10"  => 
        null;--    out_sgnl(0)<=mode2(clk,gate(0),mode2_start,ce0);
       when  "X11"  =>    
           null;--  out_sgnl(0)<=mode3(clk,gate(0),mode3_start,ce0);
   when "100" =>  
         if (  adrs="00"  )    
         then  CE_0(7 downto 0)<= countlsb0(7 downto 0);
            CE_0(15 downto 8) <= countmsb0(7 downto 0);
          CE0<= conv_integer(CE_0); 
      else  CE0<=CE0;
        end if ;
       CE0<= conv_integer(CE_0); 
       
      out_sgnl(1)<=wr_finish;
         if(ce0>0) then 
            out_sgnl(2)<='1';
      -- mode4_start<='1' ;
          end if;
             if (cee<(ce0+1) and gate(0)='1')  then
                   cee<=cee+1;
                   out_sgnl(0)<='1';
              elsif( cee=(ce0+1) and gate(0)='1') then 
                   cee<=0;
                   out_sgnl(0)<='0';
              else 
                   cee<=cee;
                   out_sgnl(0)<='1';
              end if;
        
          
           -- out_sgnl(2)<=mode4_start;
    when  "101" =>  
         
    null;
          
       when others => 
       null;
     end case ;
 when "01"  =>
     case  mode_choice is 
         when "000" =>  --mode0
             if (  adrs="01"  )    
                 then  CE_1(7 downto 0)<= countlsb1(7 downto 0);
                       CE_1(15 downto 8) <= countmsb1(7 downto 0);
                       CE1<= conv_integer(CE_1); 
                     else  CE1<=CE1;
                     end if ;
        out_sgnl(0)<=wr_finish;
            if(ce1>0) then 
         out_sgnl(2)<='1'; -- to show the beginning of count.
         end if;
         if (cee<ce1 and gate(1)='1')  then
                   cee<=cee+1;
                   out_sgnl(1)<='0';
          elsif(cee=ce1 and gate(1)='1') then 
              cee<=ce1;
              out_sgnl(1)<='1';
          else  
                 cee<=cee;
                 out_sgnl(1)<='0';
           end if;
        
        when "001" => --mode1
           null;-- out_sgnl(1)<=mode1(clk,gate(1),mode1_start,ce1);
        when "X10" =>
           null;-- out_sgnl(1)<=mode2(clk,gate(1),mode2_start,ce1);
       when "X11"   =>
          null;--   out_sgnl(1)<=mode3(clk,gate(1),mode3_start,ce1);
       when "100" =>
              if (  adrs="01"  )    
                     then  CE_1(7 downto 0)<= countlsb1(7 downto 0);
                           CE_1(15 downto 8) <= countmsb1(7 downto 0);
                             CE1<= conv_integer(CE_1); 
                       else  CE1<=CE1;
                       end if ;
                
         out_sgnl(0)<=wr_finish;
      if(ce1>0) then 
         out_sgnl(2)<='1';
       end if;    -- mode4_start<='1' ;
           
             if (cee<(ce1+1) and gate(1)='1')  then
                   cee<=cee+1;
                   out_sgnl(1)<='1';
              elsif( cee=(ce1+1) and gate(1)='1') then 
                   cee<=0;
                   out_sgnl(1)<='0';
              else 
                   cee<=cee;
                                  
              end if;
        
       when "101" =>
           null;--   out_sgnl(1)<=mode5(clk,gate(1),mode5_start,ce1);
     when others => null;
   end case ;
when "10"  =>
     case  mode_choice is 
        when "000" => --mode0
  
           if (  adrs="10"  )    
                     then  CE_2(7 downto 0)<= countlsb2(7 downto 0);
                           CE_2(15 downto 8) <= countmsb2(7 downto 0);
                            CE2<= conv_integer(CE_2); 
                       else  CE2<=CE2;
                     end if ;
           out_sgnl(0)<=wr_finish;
             if(ce2>0) then 
         out_sgnl(1)<='1'; -- to show the beginning of count.
         end if;
       if (cee<ce2 and gate(2)='1')  then
                   cee<=cee+1;
                   out_sgnl(2)<='0';
          elsif(cee=ce2 and gate(2)='1') then 
              cee<=ce2;
              out_sgnl(2)<='1';
          else  
                 cee<=cee;
                 out_sgnl(2)<='0';
           end if;
       
        when "001" => --mode1
            null;--out_sgnl(2)<=mode1(clk,gate(2),mode1_start,ce2);
        when "X10" =>
            null;--out_sgnl(2)<=mode2(clk,gate(2),mode2_start,ce2);
       when "X11"   =>
             null;--out_sgnl(2)<=mode3(clk,gate(2),mode3_start,ce2);
       when "100" =>
                   if (adrs="10")        
                    then  CE_2(7 downto 0)<= countlsb2(7 downto 0);
                          CE_2(15 downto 8) <= countmsb2(7 downto 0);
                           CE2 <= conv_integer(CE_2); 
                     else  CE2<=CE2;
                      end if ;
             
       
            out_sgnl(1)<=wr_finish;
           if( ce2>0) then 
            out_sgnl(0)<='1';
      -- mode4_start<='1' ;
            end if;
             if (cee<(ce2+1) and gate(2)='1')  then
                   cee<=cee+1;
                   out_sgnl(2)<='1';
              elsif( cee=(ce2+1) and gate(2)='1') then 
                   cee<=0;
                   out_sgnl(2)<='0';
              else 
                   cee<=cee;
                   out_sgnl(2)<='1';
              end if;
        
       when "101" =>
             null;-- out_sgnl(2)<=mode5(clk,gate(2),mode5_start,ce2);
       when others => null;
        end case;
 when others =>
              null;
  end case;
    end if;
end process cnt_prc;
end main; 


























⌨️ 快捷键说明

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