专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

数字电子表VHDL程序

作者:佚名   来源:本站原创   点击数:  更新时间:2013年11月08日   【字体:

       本程序实现的电路是以CycloneII序列之EP2C5Q208C8芯片为例,经过特定开发板电路实际仿真验证并正确的,程序仿真的时钟采用12M晶振:

library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
entity DZB1 is
   port(cr,min,hor,cp:in std_logic;
        q:out std_logic_vector(6 downto 0);
        w0,w1,w2,w3,w4,w5:out std_logic);
end DZB1;
architecture dianzi of DZB1 is
 signal display,t0,t1,t2:std_logic_vector(8 downto 0);
 signal c0,c1,c2,s0,s1,m0,m1,h0,h1,clk1,clk2:std_logic;
 signal sq0,sq1,mq0,mq1,hq0,hq1,xs:std_logic_vector(3 downto 0);
begin
    process(cr,cp) --分频开始
        begin
          if cp'event and cp='1' then
                if t0=499 then t0<="000000000";c0<='1';
                    else t0<=t0+1; c0<='0';
                end if;              
          end if;
          if c0'event and c0='1' then
                if t1=199 then t1<="000000000";c1<='1';
                     else t1<=t1+1;c1<='0';
                end if;              
          end if;
          if c1'event and c1='1' then
                if t2=199 then t2<="000000000";c2<='1';
                   else t2<=t2+1;c2<='0';
                 end if;              
          end if;
      end process;
 --分频结束 --秒计时开始
     process(c2,cr,min)
         begin
            if c2'event and c2='1' then
                   if sq0=9 then sq0<="0000";s0<='1';
                       else sq0<=sq0+1;s0<='0';
                    end if;                
             end if;
             if s0'event and s0='1' then
                    if sq1=5 then sq1<="0000"; s1<='1';
                        else sq1<=sq1+1;s1<='0';
                    end if;                  
             end if;
             if cr='0' then sq0<="0000";sq1<="0000";
             end if;
             if min='0' then sq0<="0000";sq1<="0000";
             end if;
    end process;--秒计时结束.
    --分开始
    process(s1,min)
       begin
        clk1<=s1 or (not min);--分调整按钮,按一下分加1同时将秒清0.     
        if  clk1'event and clk1='1' then
              if mq0=9 then mq0<="0000";m0<='1';
                 else mq0<=mq0+1; m0<='0';
               end if;             
         end if;
         if m0'event and m0='1' then
               if mq1=5 then mq1<="0000";m1<='1';
                   else mq1<=mq1+1;m1<='0';
               end if;            
          end if;
           if cr='0' then mq1<="0000";mq0<="0000";
            end if;--分结束
     end process;
    --小时开始
    process(m1,hor)
       begin
        clk2<=m1 or (not hor);--时调整按钮,按一下小时加1.
        if clk2'event and clk2='1' then
              if hq0=9 then hq0<="0000";h0<='1';
                 else hq0<=hq0+1;h0<='0';
              end if;            
         end if;
         if h0'event and h0='1' then
               if hq1=5 then hq1<="0000";h1<='1';
                   else hq1<=hq1+1;h1<='0';
               end if;             
          end if;
         if hq1=2 and hq0=4 then
             hq0<="0000";hq1<="0000";
         end if;
          if cr='0' then hq0<="0000";hq1<="0000";
            end if;--小时结束
     end process;         
  --显示开始
    process(xs)
      begin
         case xs is
              when "0000"=>q<="0000001";
              when "0001"=>q<="1001111";
              when "0010"=>q<="0010010";
              when "0011"=>q<="0000110";
              when "0100"=>q<="1001100";
              when "0101"=>q<="0100100";
              when "0110"=>q<="0100000";
              when "0111"=>q<="0001111";
              when "1000"=>q<="0000000";
              when "1001"=>q<="0000100";
              when others=>q<="0000001";
          end case;
      end process;--显示结束
 --显示输出
   process(cp)
     begin
  --显示计时
      if cp'event and cp='1' then
           if display<496 then display<=display+1;
              else display<="000000000";
           end if;
       end if;
   --秒显示
       if display>0 and display<82 then xs<=sq0;w0<='0';
                 else w0<='1';
       end if;
       if display>83 and display<164 then xs<=sq1;w1<='0';
                 else w1<='1';
       end if;
   --分显示
       if display>165 and display<247 then xs<=mq0;w2<='0';
                 else w2<='1';
       end if;
       if display>248 and display<320 then xs<=mq1;w3<='0';
                 else w3<='1';
       end if;
  --时显示
       if display>321 and display<403 then xs<=hq0;w4<='0';
                 else w4<='1';
       end if;
       if display>405 and display<496 then xs<=hq1;w5<='0';
                 else w5<='1';
       end if;
   end process;
end ;

     其中12M时钟从24脚输入,七段显示a,b,c,d,e,f,g对应Q0---Q6,绑定管脚依次为171,173,175,164,165,168,169,显示控制按照从左向右依次为:小时、分、秒(各两位显示)的顺序,由于6个数码管采用总线控制,所以需要分时向总线传递显示信号,分别由位控制脚按照小时、分、秒的顺序由176,179,180,181,182和185脚分时点亮,就成了地地道道的电子表。

关闭窗口

相关文章