我刚刚将这段代码合成并在一小时前工作。我正在使用双重dabble方法来显示我的FPGA板上7 seg显示的数字。我添加了seven.seg.display函数,将其注释掉,现在它不会合成。我正在努力弄清楚这个语法错误是什么,但我不能再这样做了。我实际上没有改变什么,它将无法工作。请帮帮我。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity main is
Port ( reset : in STD_LOGIC;
clock : in STD_LOGIC;
LED : out STD_LOGIC_VECTOR(7 downto 0)
);
end main;
function to.bcd(bin: std_logic_vector(7 downto 0));
variable i: integer:= 0;
variable bcd: std_logic_vector(11 downto 0):= (others => '0');
variable bint: std_logic_vector(7 downto 0):= bin;
begin
for i in 0 to 7 loop
bcd(11 downto 1):= bcd(10 downto 0);
bcd(0):= bint(7);
bint(7 downto 0):= bint(6 downto 0);
bint(0):= '0';
if(i < 7 and bcd(3 downto 0) > "0100") then
bcd(3 downto 0):= bcd(3 downto 0) + "0011";
end if;
if(i < 7 and bcd(7 downto 4) > "0100") then
bcd(7 downto 4):= bcd(7 downto 4) + "0011";
end if;
if(i < 7 and bcd(11 downto 8) > "0100") then
bcd(11 downto 8):= bcd(11 downto 8) + "0011";
end if;
end loop;
return bcd;
end to.bcd;
--function seven.seg.display(bin: std_logic_vector(6 downto 0));
-- variable bcd: std_logic_vector(11 downto 0):= (others => '0');
-- variable segment: std_logic_vector(6 downto 0):= bin;
--
--begin
-- case bcd(11 downto 8) is
-- when "0000"=> segment <="0000001"; -- 0
-- when "0001"=> segment <="1001111"; -- 1
-- when "0010"=> segment <="0010010"; -- 2
-- when "0011"=> segment <="0000110"; -- 3
-- when "0100"=> segment <="1001100"; -- 4
-- when "0101"=> segment <="0100100"; -- 5
-- when "0110"=> segment <="0100000"; -- 6
-- when "0111"=> segment <="0001111"; -- 7
-- when "1000"=> segment <="0000000"; -- 8
-- when "1001"=> segment <="0000100"; -- 9
-- when others=> segment <="1111111"; -- -
-- end case;
-- case bcd(7 downto 4) is
-- when "0000"=> segment <="0000001"; -- 0
-- when "0001"=> segment <="1001111"; -- 1
-- when "0010"=> segment <="0010010"; -- 2
-- when "0011"=> segment <="0000110"; -- 3
-- when "0100"=> segment <="1001100"; -- 4
-- when "0101"=> segment <="0100100"; -- 5
-- when "0110"=> segment <="0100000"; -- 6
-- when "0111"=> segment <="0001111"; -- 7
-- when "1000"=> segment <="0000000"; -- 8
-- when "1001"=> segment <="0000100"; -- 9
-- when others=> segment <="1111111"; -- -
-- end case;
-- case bcd(3 downto 0) is
-- when "0000"=> segment <="0000001"; -- 0
-- when "0001"=> segment <="1001111"; -- 1
-- when "0010"=> segment <="0010010"; -- 2
-- when "0011"=> segment <="0000110"; -- 3
-- when "0100"=> segment <="1001100"; -- 4
-- when "0101"=> segment <="0100100"; -- 5
-- when "0110"=> segment <="0100000"; -- 6
-- when "0111"=> segment <="0001111"; -- 7
-- when "1000"=> segment <="0000000"; -- 8
-- when "1001"=> segment <="0000100"; -- 9
-- when others=> segment <="1111111"; -- -
-- end case;
--
--return bcd;
--end seven.seg.display;
architecture Behavioral of main is
signal counter: std_logic_vector(7 downto 0);
signal prescaler: std_logic_vector(25 downto 0);
begin
CounterProcess: process(clock)
begin
if rising_edge(clock) then
if (reset = '1') then
prescaler <= (others => '0');
counter <= (others => '0');
else
if prescaler < "1011111010111100001000000" then
prescaler <= std_logic_vector(unsigned(prescaler) + 1);
else
prescaler <= (others => '0');
counter <= std_logic_vector(unsigned(counter) + 1);
end if;
end if;
end if;
end process;
LED <= counter;
end Behavioral;
答案 0 :(得分:0)
函数&#34; to.bcd&#34;的语法是错的,你必须写:
function to.bcd(bin: std_logic_vector(7 downto 0)) return std_logic_vector(11 downto 0) is
[...]
begin
[...]
end to.bcd;
另一件事。我不知道编译器如何用点(i-e&#39;。&#39;)来解释函数名。在名称中使用下划线(i-e&#39; _&#39;)更安全:to.bcd =&gt; to_bcd。
欢呼声
答案 1 :(得分:0)
您的功能不是主要单位。声明它的最简单的地方是在体系结构声明区域。
由于第一个答案指出函数没有返回类型声明或关键字是,并且标识符不能包含句点,因此句点是分隔符。
因为你没有包含另一个使用条款我转换了三个&#34; +&#34;添加到unsigned(来自numeric_std)。当您的第二个答案试图阐明时,您可以使用一个use子句来启用对包std_logic_unsigned的访问,但这需要您更改&#34; +&#34;在counterprocess
中,除非您将use子句添加为子程序(函数)声明项。
并且出现了错误:
bint(7 downto 0) := bint(6 downto 0);
应该是:
bint(7 downto 1) := bint(6 downto 0);
显然。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity main is
port (
reset: in std_logic;
clock: in std_logic;
led: out std_logic_vector(7 downto 0)
);
end entity;
architecture behavioral of main is
signal counter: std_logic_vector(7 downto 0);
signal prescaler: std_logic_vector(25 downto 0 );
function to_bcd (bin: std_logic_vector(7 downto 0)) return std_logic_vector is
variable i: integer:= 0;
variable bcd: std_logic_vector(11 downto 0):= (others => '0');
variable bint: std_logic_vector(7 downto 0):= bin;
begin
for i in 0 to 7 loop
bcd(11 downto 1) := bcd(10 downto 0);
bcd(0) := bint(7);
bint(7 downto 1) := bint(6 downto 0);
bint(0) := '0';
if i < 7 and bcd(3 downto 0) > "0100" then
bcd(3 downto 0) :=
std_logic_vector (unsigned(bcd(3 downto 0)) + "0011");
end if;
if i < 7 and bcd(7 downto 4) > "0100" then
bcd(7 downto 4) :=
std_logic_vector(unsigned(bcd(7 downto 4)) + "0011");
end if;
if i < 7 and bcd(11 downto 8) > "0100" then
bcd(11 downto 8) :=
std_logic_vector(unsigned(bcd(11 downto 8)) + "0011");
end if;
end loop;
return bcd;
end function;
begin
counterprocess:
process(clock)
begin
if rising_edge(clock) then
if (reset = '1') then
prescaler <= (others => '0');
counter <= (others => '0');
else
if prescaler < "1011111010111100001000000" then
prescaler <= std_logic_vector(unsigned(prescaler) + 1);
else
prescaler <= (others => '0');
counter <= std_logic_vector(unsigned(counter) + 1);
end if;
end if;
end if;
end process;
led <= counter;
end architecture;
这也不适用于已注释的&#39;功能&#39;。
您的VHDL规范现在进行分析和阐述。它尚未经过功能测试。 to_bcd double dabble函数看起来就像是来自VHDL Guru博客。