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

📄 seg.vhd

📁 一个时钟程序
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity seg is
    Port (
	           seg :out std_logic_vector(7 downto 0);	    --输出到数码管
			 seg_sel: out std_logic_vector(7 downto 0); --选通数码管
			 clk:in std_logic					    --时钟信号输入			  
		  );
end seg;

architecture Behavioral of seg is
signal count: std_logic_vector(18 downto 0);		           --用于时钟分频
signal scan_clk: std_logic_vector(2 downto 0);		      --扫描信号
signal MsecCount1, MsecCount2: std_logic_vector(3 downto 0); --积存器
signal SecCount1,MinCount1,Hourcount1: std_logic_vector(3 downto 0);
signal SecCount2,MinCount2,Hourcount2: std_logic_vector(2 downto 0);
signal msecond,second,minute,hour: std_logic;	            --进位信号
signal msecond10,second10,minute10,hour10:std_logic;
signal MsecSeg1,MsecSeg2,SecSeg1,MinSeg1: std_logic_vector(7 downto 0); 
signal SecSeg2,MinSeg2,HourSeg1,HourSeg2: std_logic_vector(7 downto 0); 
component count10 is		                                --10计数器
  port(
         clk:in std_logic;
	      q:out std_logic_vector(3 downto 0)
   	 );
end component;

component count6 is                                        --6计数器
  port(
         clk:in std_logic;
	      q:out std_logic_vector(2 downto 0)		
   	 );
end component;

begin
				                 	   --时钟分频
aa: process(clk)
begin
 	if (clk'event and clk='1') then
		if	count="1111010000100100000" then
	      count<="0000000000000000000";
		else
		count<=count+1;
		end if;
	end if;	
end process;
msecond<=count(18);					  --产生10毫秒信号
--产生数码管扫描信号                                         
scan_clk<=count(18 downto 16);
--跑表记数				      
u1: count10 port map(second,SecCount1);
u2: count6  port map(second10,SecCount2);
u3: count10 port map(minute,MinCount1);
u4: count6  port map(minute10,MinCount2);
u5: count10 port map(hour,HourCount1);
u6: count6  port map(hour10,HourCount2);
u7: count10 port map(msecond,MsecCount1);
u8: count10 port map(msecond10,MsecCount2);
--产生进位信号
process(SecCount1)
begin
	if SecCount1="0000" then
		second10<='1';
	else
	   second10<='0';
	end if;
end process;

process(SecCount2)
begin
	if SecCount2="000" then
		minute<='1';
	else
		minute<='0';
	end if;
end process;

process(MinCount1)
begin
	if MinCount1="0000" then
		minute10<='1';
	else
		minute10<='0';
	end if;
end process;
process(MinCount2)
begin 
 if MinCount2="000" then
     hour<='1';
 else 
     hour<='0';
 end if;
end process;
 
process(HourCount1)
begin
    if HourCount1="0000" then
       hour10<='1';
    else 
       hour10<='0';
    end if ;
end process;

process(MsecCount1)
begin
    if MsecCount1="0000" then
       msecond10<='1';
    else
       msecond10<='0';
    end if;
end process;

process(MsecCount2)
begin
    if MsecCount2="0000" then
       second<='1';
    else 
       second<='0';
    end if;
end process;
--译码
process(SecCount1)
begin
  case SecCount1 is
    when "0000" =>SecSeg1<="11000000";--0
	 when "0001" =>SecSeg1<="11111001";--1
    when "0010" =>SecSeg1<="10100100";--2
    when "0011" =>SecSeg1<="10110000";--3
    when "0100" =>SecSeg1<="10011001";--4
    when "0101" =>SecSeg1<="10010010";--5
    when "0110" =>SecSeg1<="10000010";--6
    when "0111" =>SecSeg1<="11111000";--7
    when "1000" =>SecSeg1<="10000000";--8
    when "1001" =>SecSeg1<="10010000";--9
	 when others =>SecSeg1<="11111111";
  end case;
end process;

process(SecCount2)
begin
  case SecCount2 is
    when "000" =>SecSeg2<="11000000";--0
	 when "001" =>SecSeg2<="11111001";--1
    when "010" =>SecSeg2<="10100100";--2
    when "011" =>SecSeg2<="10110000";--3
    when "100" =>SecSeg2<="10011001";--4
    when "101" =>SecSeg2<="10010010";--5
	 when others =>SecSeg2<="11111111";
  end case;
end process;

process(MinCount1)
begin
  case MinCount1 is
    when "0000" =>MinSeg1(7 downto 0)<="11000000";--0
	 when "0001" =>MinSeg1(7 downto 0)<="11111001" ;
    when "0010" =>MinSeg1(7 downto 0)<="10100100";--2
    when "0011" =>MinSeg1(7 downto 0)<="10110000";--3
    when "0100" =>MinSeg1(7 downto 0)<="10011001";--4
    when "0101" =>MinSeg1(7 downto 0)<="10010010";--5
    when "0110" =>MinSeg1(7 downto 0)<="10000010";--6
    when "0111" =>MinSeg1(7 downto 0)<="11111000";--7
    when "1000" =>MinSeg1(7 downto 0)<="10000000";--8
    when "1001" =>MinSeg1(7 downto 0)<="10010000";--9
	 when others =>MinSeg1(7 downto 1)<="1111111";
  end case;
end process; 

process(MinCount2)
begin
  case MinCount2 is
    when "000" =>MinSeg2<="11000000";--0
	 when "001" =>MinSeg2<="11111001";--1
    when "010" =>MinSeg2<="10100100";--2
    when "011" =>MinSeg2<="10110000";--3
    when "100" =>MinSeg2<="10011001";--4
    when "101" =>MinSeg2<="10010010";--5
	 when others =>MinSeg2<="11111111";
  end case;
end process;

process(HourCount1)
begin
  case HourCount1 is
    when "0000" =>HourSeg1(7 downto 0)<="11000000";--0            
    when "0001" =>HourSeg1(7 downto 0)<="11111001" ;	--1	             
    when "0010" =>HourSeg1(7 downto 0)<="10100100";--2			
    when "0011" =>HourSeg1(7 downto 0)<="10110000";--3             
    when "0100" =>HourSeg1(7 downto 0)<="10011001";--4          
    when "0101" =>HourSeg1(7 downto 0)<="10010010";--5                
    when "0110" =>HourSeg1(7 downto 0)<="10000010";--6	             
    when "0111" =>HourSeg1(7 downto 0)<="11111000";--7                 
    when "1000" =>HourSeg1(7 downto 0)<="10000000";--8                  
    when "1001" =>HourSeg1(7 downto 0)<="10010000";--9         
    when others =>HourSeg1(7 downto 1)<="1111111";
  end case;
end process; 
process(HourCount2)
begin
  case HourCount2 is
    when "000" =>HourSeg2<="11000000";--0
    when "001" =>HourSeg2<="11111001";--1
    when "010" =>HourSeg2<="10100100";--2
    when "011" =>HourSeg2<="10110000";--3
    when "100" =>HourSeg2<="10011001";--4
    when "101" =>HourSeg2<="10010010";--5
	 when others =>HourSeg2<="11111111";
  end case;
end process;
process(MsecCount1)
begin
  case MsecCount1 is
    when "0000" =>MsecSeg1(7 downto 0)<="11000000";--0          
    when "0001" =>MsecSeg1(7 downto 0)<="11111001" ;           
    when "0010" =>MsecSeg1(7 downto 0)<="10100100";--2		  
    when "0011" =>MsecSeg1(7 downto 0)<="10110000";--3           
    when "0100" =>MsecSeg1(7 downto 0)<="10011001";--4           
    when "0101" =>MsecSeg1(7 downto 0)<="10010010";--5          
    when "0110" =>MsecSeg1(7 downto 0)<="10000010";--6            
    when "0111" =>MsecSeg1(7 downto 0)<="11111000";--7                
    when "1000" =>MsecSeg1(7 downto 0)<="10000000";--8            
    when "1001" =>MsecSeg1(7 downto 0)<="10010000";--9          
    when others =>MsecSeg1(7 downto 0)<="11111111";
  end case;
end process; 
process(MsecCount2)
begin
  case MsecCount2 is
    when "0000" =>MsecSeg2(7 downto 0)<="11000000";--0            
    when "0001" =>MsecSeg2(7 downto 0)<="11111001" ;	           
    when "0010" =>MsecSeg2(7 downto 0)<="10100100";--2			  
    when "0011" =>MsecSeg2(7 downto 0)<="10110000";--3             
    when "0100" =>MsecSeg2(7 downto 0)<="10011001";--4           
    when "0101" =>MsecSeg2(7 downto 0)<="10010010";--5
    when "0110" =>MsecSeg2(7 downto 0)<="10000010";--6           
    when "0111" =>MsecSeg2(7 downto 0)<="11111000";--7             
    when "1000" =>MsecSeg2(7 downto 0)<="10000000";--8            
    when "1001" =>MsecSeg2(7 downto 0)<="10010000";--9           
    when others =>MsecSeg2(7 downto 0)<="11111111";
  end case;
end process; 
--锁存信号
--扫描输出
process(scan_clk)
  begin
	   case scan_clk is
	 	when "000"=>
		  seg<= MsecSeg1;
		  seg_sel<="00000001";
          when "001"=>
		  seg<= MsecSeg2;
		  seg_sel<="00000010";
		when "010"=>
		  seg<= SecSeg1;
		  seg_sel<="00000100";
		when "011"=>
		  seg<= SecSeg2;
		  seg_sel<="00001000";
	     when "100"=>
		  seg<= MinSeg1;
		  seg_sel<="00010000";
     	when "101"=>
		  seg<= MinSeg2;
		  seg_sel<="00100000";
	     when "110"=>
		  seg<= HourSeg1;
		  seg_sel<="01000000";
	     when "111"=>
		  seg<= HourSeg2;
		  seg_sel<="10000000";
          when others=>
		  seg<="11111111";
		  seg_sel<="00000000";
		end case;
end process;
end Behavioral;


-------------------------------------------------------
-------------------------------------------------------
--10计数器
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity count10 is
     port(
         clk: in std_logic;
	      q: buffer std_logic_vector(3 downto 0)
		 	 );
end count10;

architecture Behavioral of count10 is
  
begin

process(clk)
begin
	if (clk'event and clk='1') then
		if q="1001" then
			q<="0000";
		else
		   q<=q+1;
		end if;
	end if;
end process;
end Behavioral;

-------------------------------------------------------
-------------------------------------------------------
--6计数器
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity count6 is
     port(
         clk:in std_logic;
	      q:buffer std_logic_vector(2 downto 0)		
   	 );
end count6;

architecture Behavioral of count6 is
  
begin

process(clk)
begin
	if (clk'event and clk='1') then
		if q="101" then
			q<="000";
		else
		   q<=q+1;
		end if;
	end if;
end process;
end Behavioral;

⌨️ 快捷键说明

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