專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

數(shù)字電子表VHDL程序

作者:佚名   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2013年11月08日   【字體:

       本程序?qū)崿F(xiàn)的電路是以CycloneII序列之EP2C5Q208C8芯片為例,經(jīng)過特定開發(fā)板電路實際仿真驗證并正確的,程序仿真的時鐘采用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;
 --分頻結(jié)束 --秒計時開始
     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;--秒計時結(jié)束.
    --分開始
    process(s1,min)
       begin
        clk1<=s1 or (not min);--分調(diào)整按鈕,按一下分加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;--分結(jié)束
     end process;
    --小時開始
    process(m1,hor)
       begin
        clk2<=m1 or (not hor);--時調(diào)整按鈕,按一下小時加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;--小時結(jié)束
     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;--顯示結(jié)束
 --顯示輸出
   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對應(yīng)Q0---Q6,綁定管腳依次為171,173,175,164,165,168,169,顯示控制按照從左向右依次為:小時、分、秒(各兩位顯示)的順序,由于6個數(shù)碼管采用總線控制,所以需要分時向總線傳遞顯示信號,分別由位控制腳按照小時、分、秒的順序由176,179,180,181,182和185腳分時點亮,就成了地地道道的電子表。

關(guān)閉窗口

相關(guān)文章