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

📄 myled4.vhd

📁 四位动态数码管显示数字时钟的分位和秒位。工具:Quartus ii 6.0 语言:VHDL
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------------------------------
entity myled4 is
       port(clk:in std_logic;                     --工作时钟 
              p:out std_logic_vector(3 downto 0); --四个动态数码管
            key:in std_logic_vector(3 downto 1);  --4*4键盘s1,s2,s3三个按键
              y:out std_logic_vector(6 downto 0));
end myled4;
--------------------------------------------------------------------------
architecture bhv of myled4 is
signal a,b,c,d:integer range 0 to 9;     --秒个位,秒十位,分个位,分十位
signal count_en,stop_en,clear_en:bit;    --计数使能对应按键s2,停止使能对应按键s1,清零使能对应按键s3
begin
---------------------------------------------------------------------------
a1:process(clk,count_en)
   variable t:integer range 0 to 4000;  --1秒计数一次
   begin    
  if clk'event and clk='1' then
       if count_en='1' then
           if t<4000 then
               t:=t+1;
             else t:=0; 
               if a<9 then a<=a+1;
                  else     a<=0;
                   if b<5 then b<=b+1;
                      else     b<=0;                     
                        if c<9 then   c<=c+1;                          
                           else       c<=0;                           
                             if d<5 then  d<=d+1;                               
                                   else   d<=0;                                 
                                  if a=9 and b=5 and c=9 and d=5 then
                                      a<=0;b<=0;c<=0;d<=0;
                                  end if;
                              end if;
                         end if;
                    end if;
                 end if;
           end if;
       end if;
   end if;
end process;
------------------------------------------------------------------------------------
a2:process(clk,a,b,c,d,count_en,stop_en)
variable n:integer range 0 to 100;
begin
 if clk'event and clk='1' then
   if count_en='1' or stop_en='1' then
          n:=n+1;
        if n=1 then
          p<="1110";
            if      a=0 then y<="0111111"; --7段数码管显示数字
             elsif  a=1 then y<="0000110";
              elsif a=2 then y<="1011011";
              elsif a=3 then y<="1001111";
              elsif a=4 then y<="1100110";
              elsif a=5 then y<="1101101";
              elsif a=6 then y<="1111101";
              elsif a=7 then y<="0000111";
              elsif a=8 then y<="1111111";
              elsif a=9 then y<="1101111";
             end if;           
         elsif  n=2 then
               p<="1101";     
                 if     b=0 then    y<="0111111";
                  elsif b=1 then    y<="0000110";
                  elsif b=2 then    y<="1011011";
                  elsif b=3 then    y<="1001111";
                  elsif b=4 then    y<="1100110";
                  elsif b=5 then    y<="1101101";
                 end if;              
         elsif n=3 then
           p<="1011";
              if       c=0 then   y<="0111111";
                 elsif c=1 then   y<="0000110";
                 elsif c=2 then   y<="1011011";
                 elsif c=3 then   y<="1001111";
                 elsif c=4 then   y<="1100110";
                 elsif c=5 then   y<="1101101";
                 elsif c=6 then   y<="1111101";
                 elsif c=7 then   y<="0000111";
                 elsif c=8 then   y<="1111111";
                 elsif c=9 then   y<="1101111";
               end if;            
         elsif n=4 then
             p<="0111";
                 if     d=0 then    y<="0111111";
                  elsif d=1 then    y<="0000110";
                  elsif d=2 then    y<="1011011";
                  elsif d=3 then    y<="1001111";
                  elsif d=4 then    y<="1100110";
                  elsif d=5 then    y<="1101101";               
                 end if;             
         elsif n=5 then
              n:=0;
         else
             null;
       end if;
     elsif clear_en='1' then
            p<="0000";
            y<="0111111";
   end if;
end if;      
end process;
-----------------------------------------------------------------------------------
p3:process(key,clk)
variable c:integer range 0 to 12;                
begin
if key="1111" then
   c:=12;                                      
elsif clk'event and clk='1' and clk'last_value='0' then
      if c/=0 then 
         c:=c-1;
      end if;
end if;       
if c=0 then
  if clk'event and clk='1' and clk'last_value='0' then                                        
   if    key ="011" then 
           count_en<='0';
           stop_en<='0';
           clear_en<='1'; 
   elsif key="110"  then
           count_en<='0';
           stop_en<='1';
           clear_en<='0';
   elsif key="101"  then
           count_en<='1';
           stop_en<='0';
            clear_en<='0';                 
     else  null;
   end if;
  end if;
end if;
end process;  
-------------------------------------------------------------------------------------
end bhv;

⌨️ 快捷键说明

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