library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity d is
port(clk: in bit;
oc: out bit;
y: out integer range 0 to 29);
end d;
architecture dh of d is
signal q: integer range 0 to 29;
begin
pl: process (clk)
begin
if(clk'event and clk='1') then
if q=29 then
q<=q-1;
elsif
q=0 then
q<=29;
end if;
end if;
if q<15 then
oc<='0';
else
oc<='1';
end if;
y<=q;
end process;
end;
这个多多有问题,我看得好头痛啊,格式杂乱无章,最好养成一个良好的编程习惯,试一下我下面这个
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity d is
port
(
clk:in bit;--时钟
oc:out bit;--15?
rst:in bit;--复位
hold:in bit;--暂停与继续
y:out integer range 0 to 29--计数器输出
);
end d;
architecture dh of d is
signal q:integer range 0 to 29;
signal c:bit;
begin
process (clk,rst)
begin
if rst = '1' then--异步复位
q <= 29;
c <= '1';
elsif clk'event and clk = '1' then--上升沿触发
if hold = '0' then--暂停计数
q <= q;
else--继续计数
q <= q - 1;
end if;
if q < 15 then--15?
c <= '0';
else c <= '1';
end if;
if q = 0 then--重新赋值
q <= 29;
end if;
end if;
end process;
y <= q;
oc <= c;
end;