VHDL 错误 "expecting begin"
VHDL Error "expecting begin"
library ieee;
use ieee.std_logic_1164.all;
entity data_choose is
port(
A :in std_logic_vector(3 downto 0);
B: out std_logic_vector(3 downto 0);
clk : in std_logic);
end entity data_choose;
architecture select_data of data_choose is
variable count : integer range 0 to 7;
count :=0;
begin
if (rising_edge(clk)) then
count := count + 1 ;
if((count > 1)) then
if((count rem 2)=0) then
B <= A;
end if;
end if;
end if;
end architecture select_data ;
谁能告诉我这段代码有什么问题。
在计数初始化语句附近有一个编译错误。
谢谢。
这段代码有一些问题。
variable count : integer range 0 to 7;
我建议你把它设为 signal
,而不是 variable
。我还建议避免使用变量,直到您充分了解它们与信号的区别。您通常会在进程内声明一个变量,供该进程独占使用。需要被多个进程访问的东西通常会使用架构中声明的信号(您当前在其中声明变量)。
count :=0;
您在 architecture ... is
和 begin
之间的体系结构声明区域中进行了此分配。如果需要初始化计数器,可以使用:
signal count : integer range 0 to 7 := 0;
下一期,您的行 if (rising_edge(clk)) then
试图描述同步逻辑。这应该发生在一个过程中,所以你会:
process (clk)
begin
if (rising_edge(clk)) then
...
end if;
end process;
最后一个错误是因为你的count
现在是一个信号,你应该使用<=
而不是:=
分配给它,给出count <= count + 1 ;
进行这些更改后,您的代码可以编译。
library ieee;
use ieee.std_logic_1164.all;
entity data_choose is
port(
A :in std_logic_vector(3 downto 0);
B: out std_logic_vector(3 downto 0);
clk : in std_logic);
end entity data_choose;
architecture select_data of data_choose is
variable count : integer range 0 to 7;
count :=0;
begin
if (rising_edge(clk)) then
count := count + 1 ;
if((count > 1)) then
if((count rem 2)=0) then
B <= A;
end if;
end if;
end if;
end architecture select_data ;
谁能告诉我这段代码有什么问题。 在计数初始化语句附近有一个编译错误。
谢谢。
这段代码有一些问题。
variable count : integer range 0 to 7;
我建议你把它设为 signal
,而不是 variable
。我还建议避免使用变量,直到您充分了解它们与信号的区别。您通常会在进程内声明一个变量,供该进程独占使用。需要被多个进程访问的东西通常会使用架构中声明的信号(您当前在其中声明变量)。
count :=0;
您在 architecture ... is
和 begin
之间的体系结构声明区域中进行了此分配。如果需要初始化计数器,可以使用:
signal count : integer range 0 to 7 := 0;
下一期,您的行 if (rising_edge(clk)) then
试图描述同步逻辑。这应该发生在一个过程中,所以你会:
process (clk)
begin
if (rising_edge(clk)) then
...
end if;
end process;
最后一个错误是因为你的count
现在是一个信号,你应该使用<=
而不是:=
分配给它,给出count <= count + 1 ;
进行这些更改后,您的代码可以编译。