shuzizhongdianlu.txt

来自「利用计数器和分频器设计一个实时的时钟。一共需要1个模24计数器、2个模6计数器、」· 文本 代码 · 共 65 行

TXT
65
字号
	library ieee; 
	use ieee.std_logic_1164.all; 
	use ieee.std_logic_unsigned.all; 
	entity counter_24 is 
	port( 
	   clk,en,clr:in std_logic; 
	   q1,q0:buffer std_logic_vector(3 downto 0)); 
	end counter_24; 
	architecture behave_counter_24 of counter_24 is 
	signal c:std_logic; 
	signal q:integer range 0 to 23; 
	begin 
	  process(clk,clr) 
	   begin 
	    if (clr='0') then 
	      q0<="0000";q1<="0000"; 
	    else 
	     if rising_edge(clk) then 
	       if en='1' then 
	         if (q1>2) or (q0>9) or ((q1=2) and (q0>=3)) then 
	            q0<="0000";q1<="0000"; 
	         elsif q0=9 then 
	             q0<="0000";q1<=q1+1; 
	         else 
	             q0<=q0+1; 
	         end if; 
	       end if; 
	     end if; 
	   end if; 
	 end process; 
	end behave_counter_24; 
语法检查,通过后直接生成符号。
另外,还需添加模为6计数器、模为10计数器、1Hz的分频器和数码管解码器的代码,
而1Hz的分频器和数码管解码器的代码在之前的实验中已经完成。下面是模为6的计数器的代码,实验步骤与模为24的计数器相同:
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
entity counter_6 is 
port( 
   clock,en,clr:in std_logic;
   cout:out std_logic; 
   q:buffer std_logic_vector(3 downto 0)); 
end counter_6; 
architecture behave_counter_6 of counter_6 is 
begin 
  process(clock,clr) 
   begin 
    if (clr='1') then 
      q<="0000"; 
    else 
     if rising_edge(clock) then 
       if en='1' then
        if q=5 then
        q<="0000";
        else 
         q<=q+1; 
       end if; 
     end if; 
   end if; 
end if;
if q=0 then
cout<='1';
else cout<='0';
end if;
end process; 

⌨️ 快捷键说明

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