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

📄 stopwatch.vhd

📁 利用Quarteus II 6.0 设计一个秒表
💻 VHD
字号:
--------分---------------秒-------------毫秒------
---count6-count5---count4-count3---count2-count1---
---毫秒位count2-count1采用每10ms计数一次,计数100次即1s向高位count3进1
---秒位count4-count3每60s到向分进1
---本秒表最大计时为59分59秒99毫秒
---其中时钟信号clk为100Hz且建议clk为FPGA的默认时钟管脚PIN_17或16,clk_led为高于1000Hz的扫描频率
library ieee;
   use ieee.std_logic_1164.all;
   use ieee.std_logic_unsigned.all;
-------------------------------------------
entity stopwatch is
  port (clk  : in  std_logic;--秒表计数时钟
        clk_led : in std_logic;--LED扫描时钟 --扫描频率大于秒表计数频率,LED显示会更稳定
        start: in  bit;--秒表计数的开始
        stop : in  bit;--秒表计数的停止
        sg   : out std_logic_vector(6 downto 0);--7段控制信息号即段选
        bt   : out std_logic_vector(7 downto 0));--位控制信号即位选
end entity stopwatch;
-------------------------------------------
architecture disp_8_led of stopwatch is 
signal cnt8:std_logic_vector(2 downto 0);----3-8译码器输入端
signal a :integer range 0 to 15;--段选数据缓冲信号
signal count1,count2,count3,count5: integer range 0 to 9:=0;--对分-秒-毫秒-计数统计
signal count4,count6 : integer range 0 to 5:=0;
--signal count2 : integer range 0 to 9:=0;
--signal count3 : integer range 0 to 9:=0;
--signal count4 : integer range 0 to 5:=0;
--signal count5 : integer range 0 to 9:=0;
begin
p1:process(cnt8)
begin
case cnt8  is  
--送位选数据低电平有效,送段选数据到缓存信号a
when "000"=>bt<="11111110";a<=count6;--分位
when "001"=>bt<="11111101";a<=count5;
when "010"=>bt<="11111011";a<=10;
when "011"=>bt<="11110111";a<=count4;--秒位
when "100"=>bt<="11101111";a<=count3;
when "101"=>bt<="11011111";a<=10;
when "110"=>bt<="10111111";a<=count2;--毫秒位
when "111"=>bt<="01111111";a<=count1;
when others=>null;
end case;
end process p1;
p2:process(clk)
begin
if clk'event and clk ='1' then 
   if start='0' then             ----------------------------------------------
      count1<=0;                 ---start  stop  秒表工作状态
      count2<=0;                 ---  0     *    秒表清零不工作
      count3<=0;                 ---  1     0    秒表停止工作但保存当前计时时间
      count4<=0;                 ---  1     1    秒表处于计时状态
      count5<=0;                 ----------------------------------------------
      count6<=0;                
   elsif stop='1' then           
        if count1=9 then         ---对count1到count6计数处理
           count1<=0; 
        else
           count1<=count1+1;
        end if;
       if count1=9 then          
         if count2=9 then
            count2<=0;
         else
            count2<=count2+1;
         end if;
       else
            count2<=count2; --count1计数未到9,高位count2保持当前状态(无进位)
       end if;
       if count1=9 and count2=9 then
         if count3=9 then
            count3<=0;
         else
           count3<=count3+1;
         end if;
      else
         count3<=count3;  --count1和count2计数均未到9,高位count3保持当前状态(无进位)
      end if;
      if count1=9 and count2=9 and count3=9 then
         if count4=5 then
            count4<=0;
         else
            count4<=count4+1;
         end if;    
      else
            count4<=count4;--count1、count2和count3计数均未到9,高位count4保持当前状态(无进位)
     end if;
     if count1=9 and count2=9 and count3=9 and count4=5 then   
        if count5=9 then 
           count5<=0;
        else
           count5<=count5+1;
        end if;
    else
         count5<=count5;--count1、count2、count3未到9和count4未到5,高位count5保持高位状态(无进位)
    end if;
    if count1=9 and count2=9 and count3=9 and count4=5 and count5=9 then   
       if count6=5 then 
          count6<=0;
       else
          count6<=count6+1;
       end if;
    else
         count6<=count6;--count1、count2、count3、count5未到9和count4未到5,高位count6保持高位状态(无进位)
    end if;
  end if;
end if;
end process p2;
process(clk_led)
begin
if rising_edge(clk_led) then  --LED频率扫描处理程序
   cnt8<=cnt8+1;--cnt8快速扫描实现LED数码管的动态效果在视觉上为静态效果
end if;
end process;
p3:process(a)
begin
case a is            ---数码管显示
when 0=>sg<="0111111";  ---0
when 1=>sg<="0000110";  ---1
when 2=>sg<="1011011";  ---2
when 3=>sg<="1001111";  ---3
when 4=>sg<="1100110";  ---4
when 5=>sg<="1101101";  ---5
when 6=>sg<="1111101";  ---6
when 7=>sg<="0000111";  ---7
when 8=>sg<="1111111";  ---8
when 9=>sg<="1101111";  ---9
when 10=>sg<="1000000";---字符横杠-
--when 11=>sg<="1111100";--a
--when 12=>sg<="0111001";--b
--when 13=>sg<="1011110";--c
--when 14=>sg<="1111001";--d
--when 15=>sg<="1110001";--e
when others =>null;
  end case;
end process p3;
end architecture disp_8_led;

⌨️ 快捷键说明

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