十进制加法器的VHDL程序及注释如下:
// 包含所需的库
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
// 定义所需的输入输出端口和
寄存器ENTITY BCD_counter IS
PORT(clr,clk: IN std_logic;
BCD_q:OUT std_logic_vector(3 DOWNTO 0));
END BCD_counter;
ARCHITECTURE behavioral OF BCD_counter IS
SIGNAL counter:std_logic_vector(3 DOWNTO 0);
BEGIN
process(CLR,CLK)
begin
IF clr='0' then // 清零标志有效,则
计数器清零
counter <= (OTHERS => '0');
ELSIF rising_edge(clk) THEN
IF counter < "1001" THEN // 计数器数值小于10,计数器加1
counter <= counter +'1';
ELSE counter <= (OTHERS => '0'); // 计数器数值大于等于10,计数器清零
END IF;
END IF;
end process;
BCD_q <= counter;
END behavioral;