40130064 发表于 2010-4-2 15:08:24

大家帮我看看这个VHDL代码,分析分析

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity jicunqi is
--generic (n : natural := 32);
port (
Din         : in std_logic_vector(0 to 7);
Qaddr         : in std_logic_vector(7 downto 0);
Clock,Enable: in std_logic;
Xdir          : out std_logic_vector(7 downto 0);
Xdata         : out std_logic_vector(23 downto 0));
end entity jicunqi;

architecture behavioural of jicunqi is
begin
process (Clock,Enable) is
begin
if rising_edge(Clock) then
        if (Enable = '1')then
                if (Qaddr = 32) then
                                Xdir   <= (others => '0');
                                Xdata    <= (others => '0');
                end if;
                -------------------------------------------
                if (Qaddr = 1) then
                        Xdir(7 downto 0) <= Din;
                end if;
                ------------------------------------
                if (Qaddr = 2) then
                Xdata(23 downto 16) <= Din;
                end if;
                if (Qaddr = 3) then
                Xdata(15 downto 8) <= Din;
                end if;
                if (Qaddr = 4) then
                Xdata(7 downto 0) <= Din;
                end if;       

        end if;       
end if;
end process ;
end;

我写的这几行代码
大概意思就是Enable=1,Clock下降沿判断Qaddr值 将数据Din 寄存并输出,
请问这样写有没有隐患?

Cliff 发表于 2010-4-2 15:25:35

可以是可以的,但是……
1、代码没有缩进,看起来麻烦
2、代码实现的,和你的意图不一样:不是Clock下降沿,而是上升沿;不是锁存,而是寄存
3、没有异步复位,导致上电后的输出状态不确定,毕竟你有一个 Enable 使能的

shiqulezhangwo 发表于 2010-4-2 16:41:54

多谢!
学习了!! 我要的是寄存,但是下降沿吧?异步复位具体是怎么个事回?

40130064 发表于 2010-4-2 16:57:38

多谢,学习了!是寄存。 但是下降沿吧?我用这个和MCU通信,上电时确实有点问题。因为上电引脚会跳变!怎么解决啊?

Cliff 发表于 2010-4-2 23:45:54

你代码中是 if rising_edge(clk) 那就是上升沿(这也是绝大部分场合使用的方式啊)

异步复位:

process(nRst, Clk)
begin
    if nRst=0 then
      dout <= '0';-- initial value
    else if rising_edge(Clk) then
      dout <= din;
    end if
end process;
页: [1]
查看完整版本: 大家帮我看看这个VHDL代码,分析分析