用VHDL语言设计一个具有清零,使能,置数的4位二进制加减法计数器的源程序,谢谢

 我来答
julong823
2012-05-07 · TA获得超过858个赞
知道小有建树答主
回答量:1238
采纳率:8%
帮助的人:313万
展开全部
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

entity counter4 is
port
(
clk : in std_logic;
load : in std_logic;
clr : in std_logic;
up_down: in std_logic;
DIN : in std_logic_vector(3 downto 0);
DOUT : out std_logic_vector(3 downto 0);
c : out std_logic
);
end counter4;

architecture rt1 of counter4 is
signal clk_1Hz:std_logic;
signal data_r:std_logic_vector(3 downto 0);
component frediv
port
(
clk :in std_logic;
clkout:out std_logic
);
end component;

begin
U1:frediv port map(clk,clk_1Hz);

DOUT <= data_r;
process(clk_1Hz,load,clr,up_down,DIN)
begin
if clr = '1' then
data_r <= "0000";
elsif load = '1' then
data_r <= DIN;
else if clk_1Hz'event and clk_1Hz = '1' then
if up_down = '1' then
if data_r = "1111" then
c <= '0';
data_r <= "0000";
else
data_r <= data_r + 1;
c<= '1';
end if;
else
if data_r = "0000" then
c <= '0';
data_r <= "1111";
else
data_r <= data_r - 1;
c<= '1';
end if;
end if;
end if;
end if;
end process;
end rt1;
追问
不对哦,有错误,看图
追答
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

entity counter4 is
port
(
clk : in std_logic;
load : in std_logic;
clr : in std_logic;
up_down: in std_logic;
DIN : in std_logic_vector(3 downto 0);
DOUT : out std_logic_vector(3 downto 0);
c : out std_logic
);
end counter4;

architecture rt1 of counter4 is

signal data_r:std_logic_vector(3 downto 0);

begin

DOUT <= data_r;
process(clk,load,clr,up_down,DIN)
begin
if clr = '1' then
data_r <= "0000";
elsif load = '1' then
data_r <= DIN;
else if clk'event and clk = '1' then
if up_down = '1' then
if data_r = "1111" then
c <= '0';
data_r <= "0000";
else
data_r <= data_r + 1;
c<= '1';
end if;
else
if data_r = "0000" then
c <= '0';
data_r <= "1111";
else
data_r <= data_r - 1;
c<= '1';
end if;
end if;
end if;
end if;
end process;
end rt1;

之前写的,中间调用了一个子程序,忘了删了,现在好了。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
a78362283
2012-05-06
知道答主
回答量:27
采纳率:0%
帮助的人:6.9万
展开全部
ffff
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式