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

📄 dynamic_display.vhd

📁 一些很好的FPGA设计实例
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--动态显示模块,主要目的实现数码管和发光二极管同时显示
entity dynamic_display is
    Port ( clk : in std_logic;  --系统时钟
		     reset: in std_logic; --复位信号
		     datain1,datain2: in std_logic_vector(3 downto 0);  --倒计时的数据输入
		     data_ledfa:in std_logic_vector(7 downto 0 );	--交通灯的亮灭信号输入
		     cs:out std_logic_vector(1 downto 0);	  --数码管和发光二极管的选通信号
	        shift: out std_logic_vector(3 downto 0);--点亮数码管的位选信号
           led : out std_logic_vector(7 downto 0)); --送去显示的数据输出
end dynamic_display;

architecture Behavioral of dynamic_display is
signal clk_shift:std_logic;
signal datain11,datain22: std_logic_vector(7 downto 0);
begin
process(clk)										 --分频器;
variable cnt : integer range 0 to 5000;
begin
   if clk'event and clk='1' then cnt:=cnt+1;
      if cnt<2500 then clk_shift<='1';
		  elsif cnt<5000 then clk_shift<='0';
		  else cnt:=0;clk_shift<='0';
		end if;
   end if;
end process;
process(clk_shift,datain1)	 --译码,把十进制数译成数码管显示的段码
begin
if clk_shift'event and clk_shift='1' then
  case datain1 is
         when"0000"=>datain11<="01000000";--0
	      when"0001"=>datain11<="01111001";--1
			when"0010"=>datain11<="00100100";--2
			when"0011"=>datain11<="00110000";--3
			when"0100"=>datain11<="00011001";--4
			when"0101"=>datain11<="00010010";--5
			when"0110"=>datain11<="00000010";--6
			when"0111"=>datain11<="01111000";--7
			when"1000"=>datain11<="00000000";--8
			when"1001"=>datain11<="00010000";--9
			when others=>datain11<="11111111";--No signal; 
    end case;
	 end if;
	 end process;
	 process(clk_shift,datain2)	--译码,把十进制数译成数码管显示的段码
	 begin
	 if clk_shift'event and clk_shift='1' then
	 case datain2 is
         when"0000"=>datain22<="01000000";--0
	      when"0001"=>datain22<="01111001";--1
			when"0010"=>datain22<="00100100";--2
			when"0011"=>datain22<="00110000";--3
			when"0100"=>datain22<="00011001";--4
			when"0101"=>datain22<="00010010";--5
			when"0110"=>datain22<="00000010";--6
			when"0111"=>datain22<="01111000";--7
			when"1000"=>datain22<="00000000";--8
			when"1001"=>datain22<="00010000";--9
			when others=>datain22<="11111111";--No signal; 
    end case;
	 end if;
 end process;
process(clk_shift,reset)		
variable cnt : std_logic_vector(2 downto 0);
begin
	 if reset='1' then
	 cnt:="000";
     elsif clk_shift'event and clk_shift='1' then 
       cnt:=cnt+1;
			if cnt="001" then
			   cs<="11";
				shift<="1111";
				led<="11111111";		--发光二极管、数码管全灭;
			elsif cnt="010" then 
				cs<="00";
				shift<="1111";
				led<="11111111";	  
			elsif cnt="011" then   --数码管显示‘0’;
				cs<="01";
				shift<="0111";
				led<="01000000";	   
			elsif cnt="100" then  --数码管显示‘0’;
				cs<="01";
				shift<="1011";
				led<="01000000";   	
			elsif cnt="101" then	 --数码管显示datain2输入的数据;
				cs<="01";
				shift<="1101";
				led<=datain22;   	
			elsif cnt="110" then	  --数码管显示datain1输入的数据;
				cs<="01"; 
				shift<="1110";
				led<=datain11;   	
			elsif cnt="111" then		--用发光二极管来代替交通灯显示
				cs<="10";
				shift<="1111";			
				led<=data_ledfa;
			end if;
   end if;
end process;
   
end Behavioral;

⌨️ 快捷键说明

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