div.vhd

来自「这是CPLD原始代码程序」· VHDL 代码 · 共 34 行

VHD
34
字号
--分配器
--**************库定义、 包定义********************
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--**************实体定义********************
Entity div is
generic(duty:integer:=5);--类属参数说明语句
	--端口说明	
 port(clk	:	in	std_logic;--时钟输入
		q	:   out std_logic--分频输出	   
	);
end div;
--**************构造体定义********************
Architecture div10 of div is
  constant period : integer:=10;--常数定义,分频数
  signal count : integer range 0 to period-1;--信号定义,计数作用
 begin
process(clk)--进程,由clk这个信号启动
  begin
	if rising_edge(clk) then --上升沿驱动,还有另一种写法,见其他例程 
		if count<duty then
			q<='0';
			count<=count+1;
		elsif count<period-1 then 
			q<='1';
			count<=count+1;
		else
			count<=0;
		end if;
	end if;
end process;
end div10;

⌨️ 快捷键说明

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