使用spartan 3(vhdl)从键盘添加2个数字

使用spartan 3(vhdl)从键盘添加2个数字,vhdl,Vhdl,我的任务是从键盘上输入两个数字,从0到9,然后把它们相加。问题出在 存储这些数字。我想将第一次按(输入编号)保存到“a”中,第二次按(输入编号)保存到 “b”,但通过使用以下代码,首先按下a和b中的存储。第二次按压没有用。在这里 扫描代码=按下按钮的扫描代码(键盘接口代码输出) a=二进制数字(例如,如果我第一次按“1”,则代码检查扫描代码并将二进制值“1”分配给a)。 有谁能帮忙吗 process (clk, scan_code, cin) variable scancode1 : std

我的任务是从键盘上输入两个数字,从0到9,然后把它们相加。问题出在 存储这些数字。我想将第一次按(输入编号)保存到“a”中,第二次按(输入编号)保存到 “b”,但通过使用以下代码,首先按下a和b中的存储。第二次按压没有用。在这里 扫描代码=按下按钮的扫描代码(键盘接口代码输出) a=二进制数字(例如,如果我第一次按“1”,则代码检查扫描代码并将二进制值“1”分配给a)。 有谁能帮忙吗

process (clk, scan_code, cin)
  variable scancode1 : std_logic_vector (7 downto 0) := "00000000";
  variable cin2      : std_logic_vector(2 downto 0);
begin
  if(clk'event and clk = '1') then

    scancode1 := scan_code;
    a         <= "0000";
    b         <="0000";
    if (scancode1 = "00010110") then
      a <= "0001";
    elsif (scancode1 = "00011110") then
      a <="0010";
    elsif (scancode1 = "00100110") then
      a <="0011";
    elsif (scancode1 = "00100101") then
      a <="0100";
    elsif (scancode1 = "00101110") then
      a <="0101";
    elsif(scancode1 = "00110110") then
      a <="0110";
    elsif (scancode1 = "00111101") then
      a <="0111";
    elsif (scancode1 = "00111110") then
      a <="1000";
    elsif (scancode1 = "01000110") then
      a <="1001";
    elsif (scancode1 = "01000101") then
      a <="0000";
    end if;

    if (scancode1 = "01010101") then    --scancode for + sign
      a <=a;
    end if;

    if (scancode1 = "00010110") then
      b <="0001";
    elsif (scancode1 = "00011110") then
      b <="0010";
    elsif (scancode1 = "00100110") then
      b <="0011";
    elsif (scancode1 = "00100101") then
      b <="0100";
    elsif (scancode1 = "00101110") then
      b <="0101";
    elsif(scancode1 = "00110110") then
      b <="0110";
    elsif (scancode1 = "00111101") then
      b <="0111";
    elsif (scancode1 = "00111110") then
      b <="1000";
    elsif (scancode1 = "01000110") then
      b <="1001";
    elsif (scancode1 = "01000101") then
      b <="0000";
    end if;

    sum(0)  <= a(0) xor b(0) xor cin;
    cin2(0) := (a(0) and b(0)) or (cin and (a(0) xor b(0)));

    sum(1)  <= a(1) xor b(1) xor cin2(0);
    cin2(1) := (a(1) and b(1)) or (cin2(0) and (a(1) xor b(1)));

    sum(2)  <= a(2) xor b(2) xor cin2(1);
    cin2(2) := (a(2) and b(2)) or (cin2(1) and (a(2) xor b(2)));

    sum(3) <= a(3) xor b(3) xor cin2(2);
    cout   <= (a(3) and b(3)) or (cin2(2) and (a(3) xor b(3)));

  end if;
end process;
过程(时钟、扫描码、cin)
变量scancode1:std_逻辑_向量(7到0):=“00000000”;
变量cin2:std_逻辑_向量(2到0);
开始
如果(clk'事件和clk='1'),则
扫描代码1:=扫描代码;
a“a”和“b”在您这样编写的同时更新(在同一时钟边缘上检查“a”和“b”的相同“扫描码”)。考虑使用事件触发器,如以下示例所示:

...
if reset='1' then
   a<=(others => '0');
   b<=(others => '0');
   event_last<='0';
   event_nr<=0;

elsif rising_edge(clk) then 
   event_last<=event;

   -- trigger on "rising edge" of event
   if event='1' and event_last='0' then

        case event_nr is
        -- first event is "a"
        when 0 =>
            event_nr<=1;

            if (scancode1 = "00010110") then
                 a <= "0001";
            ...

        -- second event is "b"
        when others => 
            event_nr<=0;

            if (scancode1 = "00010110") then
                b <= "0001";
            ...
        end case;

   ...
   ...
。。。
如果reset='1',则
a“0”);
b‘0’;

事件\u您的最后一个问题可能是
a
b
仅在下次调用该进程时获取它们的新值。信号仅在进程完全运行后更新。进程运行时,它们保留调用时的值。您可能应该在开始时将
a
b
存储在临时变量中,并在底部分配它们的新值。您能告诉我什么是事件和事件吗?是我们选择的信号还是设置/重置按钮或时钟。我不明白这一点,“事件”是指按键事件。由于我不知道你的完整代码和硬件设置,我只能猜测。。。您可能会注意scancode1的更改(例如,如果scancode1/=scancode1\u last then事件