VHDL 设计一个3位的十进制加法计数器。要求能够从0计数到999。
--VHDL程序如下:
LIBRARY ieee;
UsE ieee.std_logic_1164.all;
ENTITY cnt1000 Is
PORT
(
clk : IN STD_LOGIC;
clr : IN STD_LOGIC;
en : IN STD_LOGIC;
count : OUT INTEGER RANGE 0 TO 999;
co :OUT STD_LOGIC);
END cnt1000;
ARCHITECTURE a OF cnt1000 Is
SIGNAL s : INTEGER RANGE 0 TO 999;
BEGIN
PROCESS (clk, clr)
BEGIN
IF clr = '0' THEN
s <= 0;
ELSIF (clk'EVENT AND clk = '1') THEN
IF en = '1' THEN
IF s<999 THEN
s <= s + 1;
ELSE s<=0;
END IF;
ELSE
s <= s;
END IF;
IF s = 999 THEN co <='1';
ELSE co <='0';
END IF;
END IF;
END PROCESS;
count <= s;
END a;
--波形仿真如下:
2022-05-15 广告