是否可以编写代码段并调用它,而不是多次编写该段? IE浏览器。我想重用一段代码,如下所示:
process (currentState)
begin
case currentState is
when requiredCoinsTensAnode => anodes <= "100000";--turn on the tens display
case tensCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
nextState <= requiredCoinsUnitsAnode;--just displayed the tens digit, next we need to display the units digit
when requiredCoinsUnitsAnode => anodes <= "010000";--turn on the units display
case unitsCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
nextState <= insertedCoinsTensAnode;
end case;
end process;
答案 0 :(得分:3)
是的,您可以在VHDL中使用函数。
检查http://www.csee.umbc.edu/portal/help/VHDL/design.html#funcd
http://www.pldworld.com/_hdl/1/www.ireste.fr/fdl/vcl/lesd/les_3.htm
答案 1 :(得分:2)
正如ravi指出的那样,功能是一种选择。
function f_segDisplay (
signal segCount : std_logic_vector(6 downto 0))
return std_logic_vector(3 downto 0) is
begin -- f_segDisplay
case segCount is
when "0000" => return "1111110"; --0
when "0001" => return "0110000"; --1
when "0010" => return "1101101"; --2
when "0011" => return "1111001"; --3
when "0100" => return "0110011"; --4
when "0101" => return "1011011"; --5
when "0110" => return "1011111"; --6
when "0111" => return "1110000"; --7
when "1000" => return "1111111"; --8
when others => return "1111011"; --9
end case;
end f_segDisplay;
process (currentState, tensCount, unitsCount)
begin
case currentState is
when requiredCoinsTensAnode =>
anodes <= "100000"; --turn on the tens display
segDisplay <= f_segDisplay(tensCount);
nextState <= requiredCoinsUnitsAnode;
when requiredCoinsUnitsAnode =>
anodes <= "010000"; --turn on the units display
segDisplay <= f_segDisplay(unitsCount);
nextState <= insertedCoinsTensAnode;
end case;
end process;
根据编译器和选项,它可能决定将功能代码置于行内。这将导致放置多个逻辑实例,就像您的原始代码一样。
另一种方法是将公共代码带入另一个进程:
p_segdisplay : process (segCount)
begin -- process p_segdisplay
case segCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
end process p_segdisplay;
process (currentState, tensCount, unitsCount)
begin
case currentState is
when requiredCoinsTensAnode =>
anodes <= "100000"; --turn on the tens display
segCount <= tensCount;
nextState <= requiredCoinsUnitsAnode;
when requiredCoinsUnitsAnode =>
anodes <= "010000"; --turn on the units display
segCount <= unitsCount;
nextState <= insertedCoinsTensAnode;
end case;
end process;
BTW:您的敏感度列表中需要tensCount和unitsCount。
在进行区域或功率冗余设计时,抽象这样的公共资源是一种有用的技术。
两者都应该以相同的方式工作,完美的工具会产生两者相同的逻辑,但我们很少有完美的工具。尝试不同的风格。有些工具会产生更好的效果,有些则会产生更好的效果。
答案 2 :(得分:1)
该代码最适合function
或procedure
。
entity
是另一种在VHDL中封装代码的方法。