特权同学

BJ-EPM CPLD入门套件VHDL例程1

0
阅读(3768)

BJ-EPM套件:http://item.taobao.com/item.htm?id=6733842901&


-- Filename ﹕ CLKDIV.vhd
-- Author ﹕ wuhouhang
-- Description ﹕ 分频计数器,50MHz时钟做分频后的50%占空比方波驱动蜂鸣器发声
-- 参考网址:http://wenku.baidu.com/view/fc10a00f79563c1ec5da71b5.html

libraryIEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity CLKDIV is
port (
Clk : in STD_LOGIC; --50MHz输入时钟
Rst_n : in STD_LOGIC; --低电平复位信号
Clk_div : out STD_LOGIC --分频信号,连接到蜂鸣器
);
end entity CLKDIV;
--20bit计数器循环计数
architecture COUNTER OF CLKDIV is
signal cnt20b : STD_LOGIC_VECTOR (19 downto 0); --20bit计数器
begin
process (Clk,Rst_n)
begin
if Rst_n = '0' then
cnt20b <= x"00000";
elsif Clk'event AND Clk = '1' then
cnt20b <= cnt20b+"1"; --分频计数
end if;
end process;
Clk_div <= cnt20b(19); --分频赋值
end architecture COUNTER;
Baidu
map