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

📄 clock_spk.vhd

📁 eda 开发数字钟的设计具体编程代码和开发流程与设计图
💻 VHD
字号:
--*************************************************************************************--

--*************************************************************************************--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity clock_spk is
  port(clkin:in std_logic; --1.5MHZ
  	   sound:in std_logic_vector(7 downto 1); --key 1-7    
       clkout:out std_logic  
       );
end entity;

architecture arc of clock_spk is
begin
 process(clkin) 
  variable count:integer range 0 to 3000;
  begin
    if (clkin'event and clkin='1') then
    	case sound is
    		when "1111110" => -- 1 : 523HZ; 1.5MHZ/523HZ = 2868
    			case count is
    				when 0 to 1433 => 
    					clkout <= '0'; count := count + 1;
		    		when 1434 to 2866 =>
    					clkout <= '1'; count := count + 1;
		    		when 2867 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "1111101" => -- 2 : 587HZ; 2555
    			case count is
    				when 0 to 1278 => 
    					clkout <= '0'; count := count + 1;
		    		when 1279 to 2553 =>
    					clkout <= '1'; count := count + 1;
		    		when 2554 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "1111011" => -- 3 : 659HZ; 2276
    			case count is
    				when 0 to 1137 => 
    					clkout <= '0'; count := count + 1;
		    		when 1138 to 2274 =>
    					clkout <= '1'; count := count + 1;
		    		when 2275 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "1110111" => -- 4 : 698HZ; 2149 
    			case count is
    				when 0 to 1074 => 
    					clkout <= '0'; count := count + 1;
		    		when 1075 to 2147 =>
    					clkout <= '1'; count := count + 1;
		    		when 2148 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "1101111" => -- 5 : 784HZ; 1913
    			case count is
    				when 0 to 955 => 
    					clkout <= '0'; count := count + 1;
		    		when 956 to 1911 =>
    					clkout <= '1'; count := count + 1;
		    		when 1912 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "1011111" => -- 6 : 880HZ; 1705
    			case count is
    				when 0 to 851 => 
    					clkout <= '0'; count := count + 1;
		    		when 852 to 1703 =>
    					clkout <= '1'; count := count + 1;
		    		when 1704 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    		
    		when "0111111" => -- 7 : 988HZ; 1518
    			case count is
    				when 0 to 758 => 
    					clkout <= '0'; count := count + 1;
		    		when 759 to 1516 =>
    					clkout <= '1'; count := count + 1;
		    		when 1517 =>
    					clkout <= '1'; count:=0;
		    		when others =>count:=0;
    			end case;    	
    		when others =>
    			clkout <= '0';
    	end case; --case sound is
    end if;
  end process;
end arc;

⌨️ 快捷键说明

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